Skip to content
Open
Show file tree
Hide file tree
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
26 changes: 7 additions & 19 deletions docs/stackit_ske_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,18 @@ Lists SKE provider options

### Synopsis

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

```
stackit ske options [flags]
```

### Examples

```
List SKE options for all categories
$ stackit ske options

List SKE options regarding Kubernetes versions only
$ stackit ske options --kubernetes-versions

List SKE options regarding Kubernetes versions and machine images
$ stackit ske options --kubernetes-versions --machine-images
```

### Options

```
--availability-zones Lists availability zones
-h, --help Help for "stackit ske options"
--kubernetes-versions Lists supported kubernetes versions
--machine-images Lists supported machine images
--machine-types Lists supported machine types
--volume-types Lists supported volume types
-h, --help Help for "stackit ske options"
```

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

* [stackit ske](./stackit_ske.md) - Provides functionality for SKE
* [stackit ske options availability-zones](./stackit_ske_options_availability-zones.md) - Lists SKE provider options for availability-zones
* [stackit ske options kubernetes-versions](./stackit_ske_options_kubernetes-versions.md) - Lists SKE provider options for kubernetes-versions
* [stackit ske options machine-images](./stackit_ske_options_machine-images.md) - Lists SKE provider options for machine-images
* [stackit ske options machine-types](./stackit_ske_options_machine-types.md) - Lists SKE provider options for machine-types
* [stackit ske options volume-types](./stackit_ske_options_volume-types.md) - Lists SKE provider options for volume-types

40 changes: 40 additions & 0 deletions docs/stackit_ske_options_availability-zones.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## stackit ske options availability-zones

Lists SKE provider options for availability-zones

### Synopsis

Lists STACKIT Kubernetes Engine (SKE) provider options for availability-zones.

```
stackit ske options availability-zones [flags]
```

### Examples

```
List SKE options for availability-zones
$ stackit ske options availability-zones
```

### Options

```
-h, --help Help for "stackit ske options availability-zones"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--region string Target region for region-specific requests
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options

44 changes: 44 additions & 0 deletions docs/stackit_ske_options_kubernetes-versions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## stackit ske options kubernetes-versions

Lists SKE provider options for kubernetes-versions

### Synopsis

Lists STACKIT Kubernetes Engine (SKE) provider options for kubernetes-versions.

```
stackit ske options kubernetes-versions [flags]
```

### Examples

```
List SKE options for kubernetes-versions
$ stackit ske options kubernetes-versions
List SKE options for supported kubernetes-versions
$ stackit ske options kubernetes-versions --supported
```

### Options

```
-h, --help Help for "stackit ske options kubernetes-versions"
--supported List supported versions only
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--region string Target region for region-specific requests
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options

40 changes: 40 additions & 0 deletions docs/stackit_ske_options_machine-images.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## stackit ske options machine-images

Lists SKE provider options for machine-images

### Synopsis

Lists STACKIT Kubernetes Engine (SKE) provider options for machine-images.

```
stackit ske options machine-images [flags]
```

### Examples

```
List SKE options for machine-images
$ stackit ske options machine-images
```

### Options

```
-h, --help Help for "stackit ske options machine-images"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--region string Target region for region-specific requests
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options

40 changes: 40 additions & 0 deletions docs/stackit_ske_options_machine-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## stackit ske options machine-types

Lists SKE provider options for machine-types

### Synopsis

Lists STACKIT Kubernetes Engine (SKE) provider options for machine-types.

```
stackit ske options machine-types [flags]
```

### Examples

```
List SKE options for machine-types
$ stackit ske options machine-types
```

### Options

```
-h, --help Help for "stackit ske options machine-types"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--region string Target region for region-specific requests
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options

40 changes: 40 additions & 0 deletions docs/stackit_ske_options_volume-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## stackit ske options volume-types

Lists SKE provider options for volume-types

### Synopsis

Lists STACKIT Kubernetes Engine (SKE) provider options for volume-types.

```
stackit ske options volume-types [flags]
```

### Examples

```
List SKE options for volume-types
$ stackit ske options volume-types
```

### Options

```
-h, --help Help for "stackit ske options volume-types"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--region string Target region for region-specific requests
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options

103 changes: 103 additions & 0 deletions internal/cmd/ske/options/availability_zones/availability_zones.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package availability_zones

import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/types"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
"github.com/stackitcloud/stackit-sdk-go/services/ske"
)

type inputModel struct {
globalflags.GlobalFlagModel
}

func NewCmd(params *types.CmdParams) *cobra.Command {
cmd := &cobra.Command{
Use: "availability-zones",
Short: "Lists SKE provider options for availability-zones",
Long: "Lists STACKIT Kubernetes Engine (SKE) provider options for availability-zones.",
Args: args.NoArgs,
Example: examples.Build(
examples.NewExample(
`List SKE options for availability-zones`,
"$ stackit ske options availability-zones"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
model, err := parseInput(params.Printer, cmd, args)
if err != nil {
return err
}

// Configure API client
apiClient, err := client.ConfigureClient(params.Printer, params.CliVersion)
if err != nil {
return err
}

// Call API
req := buildRequest(ctx, apiClient, model)
resp, err := req.Execute()
if err != nil {
return fmt.Errorf("get SKE provider options: %w", err)
}

return outputResult(params.Printer, model, resp)
},
}
return cmd
}

func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
globalFlags := globalflags.Parse(p, cmd)

model := inputModel{
GlobalFlagModel: utils.PtrValue(globalFlags),
}

p.DebugInputModel(model)
return &model, nil
}

func buildRequest(ctx context.Context, apiClient *ske.APIClient, model *inputModel) ske.ApiListProviderOptionsRequest {
req := apiClient.ListProviderOptions(ctx, model.Region)
return req
}

func outputResult(p *print.Printer, model *inputModel, options *ske.ProviderOptions) error {
if options == nil {
return fmt.Errorf("options is nil")
}

options.KubernetesVersions = nil
options.MachineImages = nil
options.MachineTypes = nil
options.VolumeTypes = nil

return p.OutputResult(model.OutputFormat, options, func() error {
zones := utils.PtrValue(options.AvailabilityZones)

table := tables.NewTable()
table.SetHeader("ZONE")
for i := range zones {
z := zones[i]
table.AddRow(utils.PtrValue(z.Name))
}

err := table.Display(p)
if err != nil {
return fmt.Errorf("display output: %w", err)
}
return nil
})
}
Loading
Loading