diff --git a/cmd/scw/testdata/test-all-usage-k8s-cluster-set-type-usage.golden b/cmd/scw/testdata/test-all-usage-k8s-cluster-set-type-usage.golden new file mode 100644 index 0000000000..6cc19347b7 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-k8s-cluster-set-type-usage.golden @@ -0,0 +1,24 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Change type of a specific Kubernetes cluster. + +USAGE: + scw k8s cluster set-type [arg=value ...] + +EXAMPLES: + Convert a kapsule cluster to a kapsule-dedicated-16 cluster + scw k8s cluster set-type 11111111-1111-1111-111111111111 type=kapsule-dedicated-16 + +ARGS: + cluster-id ID of the cluster to migrate from one type to another + type Type of the cluster + [region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw) + +FLAGS: + -h, --help help for set-type + +GLOBAL FLAGS: + -c, --config string The path to the config file + -D, --debug Enable debug mode + -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") + -p, --profile string The config profile to use diff --git a/cmd/scw/testdata/test-all-usage-k8s-cluster-usage.golden b/cmd/scw/testdata/test-all-usage-k8s-cluster-usage.golden index c6111560d3..30ef173076 100644 --- a/cmd/scw/testdata/test-all-usage-k8s-cluster-usage.golden +++ b/cmd/scw/testdata/test-all-usage-k8s-cluster-usage.golden @@ -14,6 +14,7 @@ AVAILABLE COMMANDS: list List all clusters list-available-versions List available versions for a cluster reset-admin-token Reset the admin token of a cluster + set-type Change type of a cluster update Update a cluster upgrade Upgrade a cluster diff --git a/docs/commands/k8s.md b/docs/commands/k8s.md index e22b8b045b..9d8525fd74 100644 --- a/docs/commands/k8s.md +++ b/docs/commands/k8s.md @@ -9,6 +9,7 @@ Kapsule API. - [List all clusters](#list-all-clusters) - [List available versions for a cluster](#list-available-versions-for-a-cluster) - [Reset the admin token of a cluster](#reset-the-admin-token-of-a-cluster) + - [Change type of a cluster](#change-type-of-a-cluster) - [Update a cluster](#update-a-cluster) - [Upgrade a cluster](#upgrade-a-cluster) - [Wait for a cluster to reach a stable state](#wait-for-a-cluster-to-reach-a-stable-state) @@ -294,6 +295,37 @@ scw k8s cluster reset-admin-token 11111111-1111-1111-111111111111 +### Change type of a cluster + +Change type of a specific Kubernetes cluster. + +**Usage:** + +``` +scw k8s cluster set-type [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| cluster-id | Required | ID of the cluster to migrate from one type to another | +| type | Required | Type of the cluster | +| region | Default: `fr-par`
One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config | + + +**Examples:** + + +Convert a kapsule cluster to a kapsule-dedicated-16 cluster +``` +scw k8s cluster set-type 11111111-1111-1111-111111111111 type=kapsule-dedicated-16 +``` + + + + ### Update a cluster Update a specific Kubernetes cluster. Note that this method is designed to update details such as name, description, tags and configuration. However, you cannot upgrade a cluster with this method. To do so, use the dedicated endpoint. diff --git a/internal/namespaces/k8s/v1/k8s_cli.go b/internal/namespaces/k8s/v1/k8s_cli.go index cc1a4d1598..dcb476cbcf 100644 --- a/internal/namespaces/k8s/v1/k8s_cli.go +++ b/internal/namespaces/k8s/v1/k8s_cli.go @@ -30,6 +30,7 @@ func GetGeneratedCommands() *core.Commands { k8sClusterUpdate(), k8sClusterDelete(), k8sClusterUpgrade(), + k8sClusterSetType(), k8sClusterListAvailableVersions(), k8sClusterResetAdminToken(), k8sPoolList(), @@ -980,6 +981,49 @@ func k8sClusterUpgrade() *core.Command { } } +func k8sClusterSetType() *core.Command { + return &core.Command{ + Short: `Change type of a cluster`, + Long: `Change type of a specific Kubernetes cluster.`, + Namespace: "k8s", + Resource: "cluster", + Verb: "set-type", + // Deprecated: false, + ArgsType: reflect.TypeOf(k8s.SetClusterTypeRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "cluster-id", + Short: `ID of the cluster to migrate from one type to another`, + Required: true, + Deprecated: false, + Positional: true, + }, + { + Name: "type", + Short: `Type of the cluster`, + Required: true, + Deprecated: false, + Positional: false, + }, + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*k8s.SetClusterTypeRequest) + + client := core.ExtractClient(ctx) + api := k8s.NewAPI(client) + return api.SetClusterType(request) + + }, + Examples: []*core.Example{ + { + Short: "Convert a kapsule cluster to a kapsule-dedicated-16 cluster", + Raw: `scw k8s cluster set-type 11111111-1111-1111-111111111111 type=kapsule-dedicated-16`, + }, + }, + } +} + func k8sClusterListAvailableVersions() *core.Command { return &core.Command{ Short: `List available versions for a cluster`,