Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gsk versions ls #178

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading