Skip to content

Commit af1e398

Browse files
committed
feat(ske): add commands to trigger hibernate, wakeup maintenance, and reconcile
1 parent 2f1d07a commit af1e398

17 files changed

+1302
-8
lines changed

docs/stackit_ske.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ stackit ske [flags]
3535
* [stackit ske describe](./stackit_ske_describe.md) - Shows overall details regarding SKE
3636
* [stackit ske disable](./stackit_ske_disable.md) - Disables SKE for a project
3737
* [stackit ske enable](./stackit_ske_enable.md) - Enables SKE for a project
38+
* [stackit ske hibernate](./stackit_ske_hibernate.md) - Trigger hibernate for a SKE cluster
3839
* [stackit ske kubeconfig](./stackit_ske_kubeconfig.md) - Provides functionality for SKE kubeconfig
40+
* [stackit ske maintenance](./stackit_ske_maintenance.md) - Trigger maintenance for a SKE cluster
3941
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
42+
* [stackit ske reconcile](./stackit_ske_reconcile.md) - Trigger reconcile for a SKE cluster
43+
* [stackit ske wakeup](./stackit_ske_wakeup.md) - Trigger wakeup from hibernation for a SKE cluster
4044

docs/stackit_ske_cluster.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ stackit ske cluster [flags]
3232
* [stackit ske](./stackit_ske.md) - Provides functionality for SKE
3333
* [stackit ske cluster create](./stackit_ske_cluster_create.md) - Creates an SKE cluster
3434
* [stackit ske cluster delete](./stackit_ske_cluster_delete.md) - Deletes a SKE cluster
35-
* [stackit ske cluster describe](./stackit_ske_cluster_describe.md) - Shows details of a SKE cluster
35+
* [stackit ske cluster describe](./stackit_ske_cluster_describe.md) - Shows details of a SKE cluster
3636
* [stackit ske cluster generate-payload](./stackit_ske_cluster_generate-payload.md) - Generates a payload to create/update SKE clusters
3737
* [stackit ske cluster list](./stackit_ske_cluster_list.md) - Lists all SKE clusters
3838
* [stackit ske cluster update](./stackit_ske_cluster_update.md) - Updates an SKE cluster

docs/stackit_ske_cluster_describe.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## stackit ske cluster describe
22

3-
Shows details of a SKE cluster
3+
Shows details of a SKE cluster
44

55
### Synopsis
66

7-
Shows details of a STACKIT Kubernetes Engine (SKE) cluster.
7+
Shows details of a STACKIT Kubernetes Engine (SKE) cluster.
88

99
```
1010
stackit ske cluster describe CLUSTER_NAME [flags]

docs/stackit_ske_hibernate.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske hibernate
2+
3+
Trigger hibernate for a SKE cluster
4+
5+
### Synopsis
6+
7+
Trigger hibernate for a STACKIT Kubernetes Engine (SKE) cluster.
8+
9+
```
10+
stackit ske hibernate CLUSTER_NAME [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Trigger hibernate for a SKE cluster with name "my-cluster"
17+
$ stackit ske cluster hibernate my-cluster
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske hibernate"
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](./stackit_ske.md) - Provides functionality for SKE
40+

docs/stackit_ske_maintenance.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske maintenance
2+
3+
Trigger maintenance for a SKE cluster
4+
5+
### Synopsis
6+
7+
Trigger maintenance for a STACKIT Kubernetes Engine (SKE) cluster.
8+
9+
```
10+
stackit ske maintenance CLUSTER_NAME [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Trigger maintenance for a SKE cluster with name "my-cluster"
17+
$ stackit ske cluster maintenance my-cluster
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske maintenance"
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](./stackit_ske.md) - Provides functionality for SKE
40+

docs/stackit_ske_reconcile.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske reconcile
2+
3+
Trigger reconcile for a SKE cluster
4+
5+
### Synopsis
6+
7+
Trigger reconcile for a STACKIT Kubernetes Engine (SKE) cluster.
8+
9+
```
10+
stackit ske reconcile CLUSTER_NAME [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Trigger reconcile for a SKE cluster with name "my-cluster"
17+
$ stackit ske cluster reconcile my-cluster
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske reconcile"
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](./stackit_ske.md) - Provides functionality for SKE
40+

docs/stackit_ske_wakeup.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske wakeup
2+
3+
Trigger wakeup from hibernation for a SKE cluster
4+
5+
### Synopsis
6+
7+
Trigger wakeup from hibernation for a STACKIT Kubernetes Engine (SKE) cluster.
8+
9+
```
10+
stackit ske wakeup CLUSTER_NAME [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Trigger wakeup from hibernation for a SKE cluster with name "my-cluster"
17+
$ stackit ske cluster wakeup my-cluster
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske wakeup"
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](./stackit_ske.md) - Provides functionality for SKE
40+

internal/cmd/ske/cluster/describe/describe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type inputModel struct {
3131
func NewCmd(params *params.CmdParams) *cobra.Command {
3232
cmd := &cobra.Command{
3333
Use: fmt.Sprintf("describe %s", clusterNameArg),
34-
Short: "Shows details of a SKE cluster",
35-
Long: "Shows details of a STACKIT Kubernetes Engine (SKE) cluster.",
34+
Short: "Shows details of a SKE cluster",
35+
Long: "Shows details of a STACKIT Kubernetes Engine (SKE) cluster.",
3636
Args: args.SingleArg(clusterNameArg, nil),
3737
Example: examples.Build(
3838
examples.NewExample(
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package hibernate
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/spf13/cobra"
8+
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
9+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
10+
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
11+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client"
15+
"github.com/stackitcloud/stackit-sdk-go/services/ske"
16+
)
17+
18+
const (
19+
clusterNameArg = "CLUSTER_NAME"
20+
)
21+
22+
type inputModel struct {
23+
*globalflags.GlobalFlagModel
24+
ClusterName string
25+
}
26+
27+
func NewCmd(params *params.CmdParams) *cobra.Command {
28+
cmd := &cobra.Command{
29+
Use: fmt.Sprintf("hibernate %s", clusterNameArg),
30+
Short: "Trigger hibernate for a SKE cluster",
31+
Long: "Trigger hibernate for a STACKIT Kubernetes Engine (SKE) cluster.",
32+
Args: args.SingleArg(clusterNameArg, nil),
33+
Example: examples.Build(
34+
examples.NewExample(
35+
`Trigger hibernate for a SKE cluster with name "my-cluster"`,
36+
"$ stackit ske cluster hibernate my-cluster"),
37+
),
38+
RunE: func(cmd *cobra.Command, args []string) error {
39+
ctx := context.Background()
40+
model, err := parseInput(params.Printer, cmd, args)
41+
if err != nil {
42+
return err
43+
}
44+
// Configure API client
45+
apiClient, err := client.ConfigureClient(params.Printer, params.CliVersion)
46+
if err != nil {
47+
return err
48+
}
49+
50+
if !model.AssumeYes {
51+
prompt := fmt.Sprintf("Are you sure you want to trigger hibernate for %q in project %q?", model.ClusterName, model.ProjectId)
52+
err = params.Printer.PromptForConfirmation(prompt)
53+
if err != nil {
54+
return err
55+
}
56+
}
57+
58+
// Call API
59+
req := buildRequest(ctx, model, apiClient)
60+
_, err = req.Execute()
61+
if err != nil {
62+
return fmt.Errorf("hibernate SKE cluster: %w", err)
63+
}
64+
65+
params.Printer.Info("Hibernate got triggered for %q\n", model.ClusterName)
66+
return nil
67+
},
68+
}
69+
return cmd
70+
}
71+
72+
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
73+
clusterName := inputArgs[0]
74+
75+
globalFlags := globalflags.Parse(p, cmd)
76+
if globalFlags.ProjectId == "" {
77+
return nil, &errors.ProjectIdError{}
78+
}
79+
80+
model := inputModel{
81+
GlobalFlagModel: globalFlags,
82+
ClusterName: clusterName,
83+
}
84+
85+
if p.IsVerbosityDebug() {
86+
modelStr, err := print.BuildDebugStrFromInputModel(model)
87+
if err != nil {
88+
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
89+
} else {
90+
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
91+
}
92+
}
93+
94+
return &model, nil
95+
}
96+
97+
func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClient) ske.ApiTriggerHibernateRequest {
98+
req := apiClient.TriggerHibernate(ctx, model.ProjectId, model.Region, model.ClusterName)
99+
return req
100+
}

0 commit comments

Comments
 (0)