Skip to content

feat(ske): add commands to trigger operations #873

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions docs/stackit_ske.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ stackit ske [flags]
* [stackit ske describe](./stackit_ske_describe.md) - Shows overall details regarding SKE
* [stackit ske disable](./stackit_ske_disable.md) - Disables SKE for a project
* [stackit ske enable](./stackit_ske_enable.md) - Enables SKE for a project
* [stackit ske hibernate](./stackit_ske_hibernate.md) - Trigger hibernate for a SKE cluster
* [stackit ske kubeconfig](./stackit_ske_kubeconfig.md) - Provides functionality for SKE kubeconfig
* [stackit ske maintenance](./stackit_ske_maintenance.md) - Trigger maintenance for a SKE cluster
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
* [stackit ske reconcile](./stackit_ske_reconcile.md) - Trigger reconcile for a SKE cluster
* [stackit ske wakeup](./stackit_ske_wakeup.md) - Trigger wakeup from hibernation for a SKE cluster

2 changes: 1 addition & 1 deletion docs/stackit_ske_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ stackit ske cluster [flags]
* [stackit ske](./stackit_ske.md) - Provides functionality for SKE
* [stackit ske cluster create](./stackit_ske_cluster_create.md) - Creates an SKE cluster
* [stackit ske cluster delete](./stackit_ske_cluster_delete.md) - Deletes a SKE cluster
* [stackit ske cluster describe](./stackit_ske_cluster_describe.md) - Shows details of a SKE cluster
* [stackit ske cluster describe](./stackit_ske_cluster_describe.md) - Shows details of a SKE cluster
* [stackit ske cluster generate-payload](./stackit_ske_cluster_generate-payload.md) - Generates a payload to create/update SKE clusters
* [stackit ske cluster list](./stackit_ske_cluster_list.md) - Lists all SKE clusters
* [stackit ske cluster update](./stackit_ske_cluster_update.md) - Updates an SKE cluster
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_ske_cluster_describe.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## stackit ske cluster describe

Shows details of a SKE cluster
Shows details of a SKE cluster

### Synopsis

Shows details of a STACKIT Kubernetes Engine (SKE) cluster.
Shows details of a STACKIT Kubernetes Engine (SKE) cluster.

```
stackit ske cluster describe CLUSTER_NAME [flags]
Expand Down
40 changes: 40 additions & 0 deletions docs/stackit_ske_hibernate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## stackit ske hibernate

Trigger hibernate for a SKE cluster

### Synopsis

Trigger hibernate for a STACKIT Kubernetes Engine (SKE) cluster.

```
stackit ske hibernate CLUSTER_NAME [flags]
```

### Examples

```
Trigger hibernate for a SKE cluster with name "my-cluster"
$ stackit ske cluster hibernate my-cluster
```

### Options

```
-h, --help Help for "stackit ske hibernate"
```

### 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](./stackit_ske.md) - Provides functionality for SKE

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

Trigger maintenance for a SKE cluster

### Synopsis

Trigger maintenance for a STACKIT Kubernetes Engine (SKE) cluster.

```
stackit ske maintenance CLUSTER_NAME [flags]
```

### Examples

```
Trigger maintenance for a SKE cluster with name "my-cluster"
$ stackit ske cluster maintenance my-cluster
```

### Options

```
-h, --help Help for "stackit ske maintenance"
```

### 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](./stackit_ske.md) - Provides functionality for SKE

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

Trigger reconcile for a SKE cluster

### Synopsis

Trigger reconcile for a STACKIT Kubernetes Engine (SKE) cluster.

```
stackit ske reconcile CLUSTER_NAME [flags]
```

### Examples

```
Trigger reconcile for a SKE cluster with name "my-cluster"
$ stackit ske cluster reconcile my-cluster
```

### Options

```
-h, --help Help for "stackit ske reconcile"
```

### 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](./stackit_ske.md) - Provides functionality for SKE

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

Trigger wakeup from hibernation for a SKE cluster

### Synopsis

Trigger wakeup from hibernation for a STACKIT Kubernetes Engine (SKE) cluster.

```
stackit ske wakeup CLUSTER_NAME [flags]
```

### Examples

```
Trigger wakeup from hibernation for a SKE cluster with name "my-cluster"
$ stackit ske cluster wakeup my-cluster
```

### Options

```
-h, --help Help for "stackit ske wakeup"
```

### 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](./stackit_ske.md) - Provides functionality for SKE

4 changes: 2 additions & 2 deletions internal/cmd/ske/cluster/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type inputModel struct {
func NewCmd(params *params.CmdParams) *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("describe %s", clusterNameArg),
Short: "Shows details of a SKE cluster",
Long: "Shows details of a STACKIT Kubernetes Engine (SKE) cluster.",
Short: "Shows details of a SKE cluster",
Long: "Shows details of a STACKIT Kubernetes Engine (SKE) cluster.",
Args: args.SingleArg(clusterNameArg, nil),
Example: examples.Build(
examples.NewExample(
Expand Down
100 changes: 100 additions & 0 deletions internal/cmd/ske/cluster/hibernate/hibernate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package hibernate

import (
"context"
"fmt"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"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-sdk-go/services/ske"
)

const (
clusterNameArg = "CLUSTER_NAME"
)

type inputModel struct {
*globalflags.GlobalFlagModel
ClusterName string
}

func NewCmd(params *params.CmdParams) *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("hibernate %s", clusterNameArg),
Short: "Trigger hibernate for a SKE cluster",
Long: "Trigger hibernate for a STACKIT Kubernetes Engine (SKE) cluster.",
Args: args.SingleArg(clusterNameArg, nil),
Example: examples.Build(
examples.NewExample(
`Trigger hibernate for a SKE cluster with name "my-cluster"`,
"$ stackit ske cluster hibernate my-cluster"),
),
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
}

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to trigger hibernate for %q in project %q?", model.ClusterName, model.ProjectId)
err = params.Printer.PromptForConfirmation(prompt)
if err != nil {
return err
}
}

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

params.Printer.Info("Hibernate got triggered for %q\n", model.ClusterName)
return nil
},
}
return cmd
}

func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
clusterName := inputArgs[0]

globalFlags := globalflags.Parse(p, cmd)
if globalFlags.ProjectId == "" {
return nil, &errors.ProjectIdError{}
}

model := inputModel{
GlobalFlagModel: globalFlags,
ClusterName: clusterName,
}

if p.IsVerbosityDebug() {
modelStr, err := print.BuildDebugStrFromInputModel(model)
if err != nil {
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
} else {
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
}
}

return &model, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiTriggerHibernateRequest {
req := apiClient.TriggerHibernate(ctx, model.ProjectId, model.Region, model.ClusterName)
return req
}
Loading
Loading