Skip to content

feat(k8s): add support for set-type for cluster #2906

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

Merged
merged 3 commits into from
Mar 22, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Change type of a specific Kubernetes cluster.

USAGE:
scw k8s cluster set-type <cluster-id ...> [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
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-all-usage-k8s-cluster-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions docs/commands/k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 <cluster-id ...> [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`<br />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.
Expand Down
44 changes: 44 additions & 0 deletions internal/namespaces/k8s/v1/k8s_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func GetGeneratedCommands() *core.Commands {
k8sClusterUpdate(),
k8sClusterDelete(),
k8sClusterUpgrade(),
k8sClusterSetType(),
k8sClusterListAvailableVersions(),
k8sClusterResetAdminToken(),
k8sPoolList(),
Expand Down Expand Up @@ -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`,
Expand Down