Skip to content

Commit

Permalink
Merge pull request #178 from gridscale/feature/add-k8s-version-ls
Browse files Browse the repository at this point in the history
Add gsk versions ls
  • Loading branch information
nvthongswansea authored Sep 16, 2024
2 parents 54ac6ba + 7857301 commit d66b2dd
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion cmd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,48 @@ var getKubernetesReleasesCmd = &cobra.Command{
},
}

var getKubernetesVersionsCmd = &cobra.Command{
Use: "versions",
Short: "Get available GS Kubernetes versions",
Long: "Prints all available GS Kubernetes versions.",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
out := new(bytes.Buffer)
op := rt.PaaSOperator()
paasTemplates, err := op.GetPaaSTemplateList(ctx)
if err != nil {
return NewError(cmd, "Could not get get list of Kubernetes versions", err)
}

var versions []string
for _, template := range paasTemplates {
if template.Properties.Flavour == "kubernetes" {
versions = append(versions, template.Properties.Version)
}
}
sort.Sort(sort.Reverse(utils.StringSorter(versions)))
if !rootFlags.json {
heading := []string{"versions"}
var rows [][]string
for _, ver := range versions {
rows = append(rows, []string{ver})
}
render.AsTable(out, heading, rows, renderOpts)
if rootFlags.quiet {
for _, ver := range versions {
fmt.Println(ver)
}
return nil
}

} else {
render.AsJSON(out, versions)
}
fmt.Print(out)
return nil
},
}

func clusterLsCmdRun(cmd *cobra.Command, args []string) error {
paasOp := rt.PaaSOperator()
ctx := context.Background()
Expand Down Expand Up @@ -338,7 +380,7 @@ func init() {
execCredentialCmd.MarkFlagRequired("cluster")
clusterCmd.AddCommand(execCredentialCmd, clusterLsCmd)

kubernetesCmd.AddCommand(clusterCmd, getKubernetesReleasesCmd)
kubernetesCmd.AddCommand(clusterCmd, getKubernetesReleasesCmd, getKubernetesVersionsCmd)
rootCmd.AddCommand(kubernetesCmd)
}

Expand Down

0 comments on commit d66b2dd

Please sign in to comment.