Skip to content

Commit 92c48cb

Browse files
authored
feat(ske): split options to own subcommands (#1313)
also add filter to show only supported k8s versions relates to STACKITCLI-312
1 parent 1657b71 commit 92c48cb

18 files changed

+1883
-41
lines changed

docs/stackit_ske_options.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,18 @@ Lists SKE provider options
44

55
### Synopsis
66

7+
Command "options" is deprecated, use the subcommands instead.
78
Lists STACKIT Kubernetes Engine (SKE) provider options (availability zones, Kubernetes versions, machine images and types, volume types).
89
Pass one or more flags to filter what categories are shown.
910

1011
```
1112
stackit ske options [flags]
1213
```
1314

14-
### Examples
15-
16-
```
17-
List SKE options for all categories
18-
$ stackit ske options
19-
20-
List SKE options regarding Kubernetes versions only
21-
$ stackit ske options --kubernetes-versions
22-
23-
List SKE options regarding Kubernetes versions and machine images
24-
$ stackit ske options --kubernetes-versions --machine-images
25-
```
26-
2715
### Options
2816

2917
```
30-
--availability-zones Lists availability zones
31-
-h, --help Help for "stackit ske options"
32-
--kubernetes-versions Lists supported kubernetes versions
33-
--machine-images Lists supported machine images
34-
--machine-types Lists supported machine types
35-
--volume-types Lists supported volume types
18+
-h, --help Help for "stackit ske options"
3619
```
3720

3821
### Options inherited from parent commands
@@ -49,4 +32,9 @@ stackit ske options [flags]
4932
### SEE ALSO
5033

5134
* [stackit ske](./stackit_ske.md) - Provides functionality for SKE
35+
* [stackit ske options availability-zones](./stackit_ske_options_availability-zones.md) - Lists SKE provider options for availability-zones
36+
* [stackit ske options kubernetes-versions](./stackit_ske_options_kubernetes-versions.md) - Lists SKE provider options for kubernetes-versions
37+
* [stackit ske options machine-images](./stackit_ske_options_machine-images.md) - Lists SKE provider options for machine-images
38+
* [stackit ske options machine-types](./stackit_ske_options_machine-types.md) - Lists SKE provider options for machine-types
39+
* [stackit ske options volume-types](./stackit_ske_options_volume-types.md) - Lists SKE provider options for volume-types
5240

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske options availability-zones
2+
3+
Lists SKE provider options for availability-zones
4+
5+
### Synopsis
6+
7+
Lists STACKIT Kubernetes Engine (SKE) provider options for availability-zones.
8+
9+
```
10+
stackit ske options availability-zones [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List SKE options for availability-zones
17+
$ stackit ske options availability-zones
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske options availability-zones"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
40+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## stackit ske options kubernetes-versions
2+
3+
Lists SKE provider options for kubernetes-versions
4+
5+
### Synopsis
6+
7+
Lists STACKIT Kubernetes Engine (SKE) provider options for kubernetes-versions.
8+
9+
```
10+
stackit ske options kubernetes-versions [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List SKE options for kubernetes-versions
17+
$ stackit ske options kubernetes-versions
18+
19+
List SKE options for supported kubernetes-versions
20+
$ stackit ske options kubernetes-versions --supported
21+
```
22+
23+
### Options
24+
25+
```
26+
-h, --help Help for "stackit ske options kubernetes-versions"
27+
--supported List supported versions only
28+
```
29+
30+
### Options inherited from parent commands
31+
32+
```
33+
-y, --assume-yes If set, skips all confirmation prompts
34+
--async If set, runs the command asynchronously
35+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
36+
-p, --project-id string Project ID
37+
--region string Target region for region-specific requests
38+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
39+
```
40+
41+
### SEE ALSO
42+
43+
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
44+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske options machine-images
2+
3+
Lists SKE provider options for machine-images
4+
5+
### Synopsis
6+
7+
Lists STACKIT Kubernetes Engine (SKE) provider options for machine-images.
8+
9+
```
10+
stackit ske options machine-images [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List SKE options for machine-images
17+
$ stackit ske options machine-images
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske options machine-images"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
40+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske options machine-types
2+
3+
Lists SKE provider options for machine-types
4+
5+
### Synopsis
6+
7+
Lists STACKIT Kubernetes Engine (SKE) provider options for machine-types.
8+
9+
```
10+
stackit ske options machine-types [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List SKE options for machine-types
17+
$ stackit ske options machine-types
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske options machine-types"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
40+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske options volume-types
2+
3+
Lists SKE provider options for volume-types
4+
5+
### Synopsis
6+
7+
Lists STACKIT Kubernetes Engine (SKE) provider options for volume-types.
8+
9+
```
10+
stackit ske options volume-types [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List SKE options for volume-types
17+
$ stackit ske options volume-types
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske options volume-types"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
40+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package availability_zones
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
8+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
9+
10+
"github.com/spf13/cobra"
11+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
17+
"github.com/stackitcloud/stackit-sdk-go/services/ske"
18+
)
19+
20+
type inputModel struct {
21+
globalflags.GlobalFlagModel
22+
}
23+
24+
func NewCmd(params *types.CmdParams) *cobra.Command {
25+
cmd := &cobra.Command{
26+
Use: "availability-zones",
27+
Short: "Lists SKE provider options for availability-zones",
28+
Long: "Lists STACKIT Kubernetes Engine (SKE) provider options for availability-zones.",
29+
Args: args.NoArgs,
30+
Example: examples.Build(
31+
examples.NewExample(
32+
`List SKE options for availability-zones`,
33+
"$ stackit ske options availability-zones"),
34+
),
35+
RunE: func(cmd *cobra.Command, args []string) error {
36+
ctx := context.Background()
37+
model, err := parseInput(params.Printer, cmd, args)
38+
if err != nil {
39+
return err
40+
}
41+
42+
// Configure API client
43+
apiClient, err := client.ConfigureClient(params.Printer, params.CliVersion)
44+
if err != nil {
45+
return err
46+
}
47+
48+
// Call API
49+
req := buildRequest(ctx, apiClient, model)
50+
resp, err := req.Execute()
51+
if err != nil {
52+
return fmt.Errorf("get SKE provider options: %w", err)
53+
}
54+
55+
return outputResult(params.Printer, model, resp)
56+
},
57+
}
58+
return cmd
59+
}
60+
61+
func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
62+
globalFlags := globalflags.Parse(p, cmd)
63+
64+
model := inputModel{
65+
GlobalFlagModel: utils.PtrValue(globalFlags),
66+
}
67+
68+
p.DebugInputModel(model)
69+
return &model, nil
70+
}
71+
72+
func buildRequest(ctx context.Context, apiClient *ske.APIClient, model *inputModel) ske.ApiListProviderOptionsRequest {
73+
req := apiClient.ListProviderOptions(ctx, model.Region)
74+
return req
75+
}
76+
77+
func outputResult(p *print.Printer, model *inputModel, options *ske.ProviderOptions) error {
78+
if options == nil {
79+
return fmt.Errorf("options is nil")
80+
}
81+
82+
options.KubernetesVersions = nil
83+
options.MachineImages = nil
84+
options.MachineTypes = nil
85+
options.VolumeTypes = nil
86+
87+
return p.OutputResult(model.OutputFormat, options, func() error {
88+
zones := utils.PtrValue(options.AvailabilityZones)
89+
90+
table := tables.NewTable()
91+
table.SetHeader("ZONE")
92+
for i := range zones {
93+
z := zones[i]
94+
table.AddRow(utils.PtrValue(z.Name))
95+
}
96+
97+
err := table.Display(p)
98+
if err != nil {
99+
return fmt.Errorf("display output: %w", err)
100+
}
101+
return nil
102+
})
103+
}

0 commit comments

Comments
 (0)