From cd111e2af444dae673cbf925967ee1dedc346043 Mon Sep 17 00:00:00 2001 From: Scaleway Bot Date: Fri, 13 Sep 2024 10:37:33 +0200 Subject: [PATCH] feat(k8s): enable MigrateClusterToSBSCSI in CLI (#4120) --- ...8s-cluster-migrate-to-sbs-csi-usage.golden | 23 ++++++++++++ .../test-all-usage-k8s-cluster-usage.golden | 1 + docs/commands/k8s.md | 31 ++++++++++++++++ internal/namespaces/k8s/v1/k8s_cli.go | 37 +++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 cmd/scw/testdata/test-all-usage-k8s-cluster-migrate-to-sbs-csi-usage.golden diff --git a/cmd/scw/testdata/test-all-usage-k8s-cluster-migrate-to-sbs-csi-usage.golden b/cmd/scw/testdata/test-all-usage-k8s-cluster-migrate-to-sbs-csi-usage.golden new file mode 100644 index 000000000..34959b07b --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-k8s-cluster-migrate-to-sbs-csi-usage.golden @@ -0,0 +1,23 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Enable the latest CSI compatible with Scaleway Block Storage (SBS) and migrate all existing PersistentVolumes/VolumeSnapshotContents to SBS. + +USAGE: + scw k8s cluster migrate-to-sbs-csi [arg=value ...] + +EXAMPLES: + Migrate a cluster to SBS CSI + scw k8s cluster migrate-to-sbs-csi 11111111-1111-1111-111111111111 + +ARGS: + cluster-id Cluster ID for which the latest CSI compatible with Scaleway Block Storage will be enabled + [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 migrate-to-sbs-csi + +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 2923e65d7..69cb5e0cd 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-available-types List available cluster types for a cluster list-available-versions List available versions for a Cluster migrate-to-routed-ips Migrate a cluster to Routed IPs + migrate-to-sbs-csi Migrate a cluster to SBS CSI reset-admin-token Reset the admin token of a Cluster set-type Change the Cluster type update Update a Cluster diff --git a/docs/commands/k8s.md b/docs/commands/k8s.md index 342a59962..2efe66c4a 100644 --- a/docs/commands/k8s.md +++ b/docs/commands/k8s.md @@ -11,6 +11,7 @@ This API allows you to manage Kubernetes Kapsule and Kosmos clusters. - [List available cluster types for a cluster](#list-available-cluster-types-for-a-cluster) - [List available versions for a Cluster](#list-available-versions-for-a-cluster) - [Migrate a cluster to Routed IPs](#migrate-a-cluster-to-routed-ips) + - [Migrate a cluster to SBS CSI](#migrate-a-cluster-to-sbs-csi) - [Reset the admin token of a Cluster](#reset-the-admin-token-of-a-cluster) - [Change the Cluster type](#change-the-cluster-type) - [Update a Cluster](#update-a-cluster) @@ -347,6 +348,36 @@ scw k8s cluster migrate-to-routed-ips 11111111-1111-1111-111111111111 +### Migrate a cluster to SBS CSI + +Enable the latest CSI compatible with Scaleway Block Storage (SBS) and migrate all existing PersistentVolumes/VolumeSnapshotContents to SBS. + +**Usage:** + +``` +scw k8s cluster migrate-to-sbs-csi [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| cluster-id | Required | Cluster ID for which the latest CSI compatible with Scaleway Block Storage will be enabled | +| 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:** + + +Migrate a cluster to SBS CSI +``` +scw k8s cluster migrate-to-sbs-csi 11111111-1111-1111-111111111111 +``` + + + + ### Reset the admin token of a Cluster Reset the admin token for a specific Kubernetes cluster. This will revoke the old admin token (which will not be usable afterwards) and create a new one. Note that you will need to download kubeconfig again to keep interacting with the cluster. diff --git a/internal/namespaces/k8s/v1/k8s_cli.go b/internal/namespaces/k8s/v1/k8s_cli.go index 1a2c17157..91047663f 100644 --- a/internal/namespaces/k8s/v1/k8s_cli.go +++ b/internal/namespaces/k8s/v1/k8s_cli.go @@ -37,6 +37,7 @@ func GetGeneratedCommands() *core.Commands { k8sClusterListAvailableTypes(), k8sClusterResetAdminToken(), k8sClusterMigrateToRoutedIPs(), + k8sClusterMigrateToSbsCsi(), k8sPoolList(), k8sPoolCreate(), k8sPoolGet(), @@ -1196,6 +1197,42 @@ func k8sClusterMigrateToRoutedIPs() *core.Command { } } +func k8sClusterMigrateToSbsCsi() *core.Command { + return &core.Command{ + Short: `Migrate a cluster to SBS CSI`, + Long: `Enable the latest CSI compatible with Scaleway Block Storage (SBS) and migrate all existing PersistentVolumes/VolumeSnapshotContents to SBS.`, + Namespace: "k8s", + Resource: "cluster", + Verb: "migrate-to-sbs-csi", + // Deprecated: false, + ArgsType: reflect.TypeOf(k8s.MigrateClusterToSBSCSIRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "cluster-id", + Short: `Cluster ID for which the latest CSI compatible with Scaleway Block Storage will be enabled`, + Required: true, + Deprecated: false, + Positional: true, + }, + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*k8s.MigrateClusterToSBSCSIRequest) + + client := core.ExtractClient(ctx) + api := k8s.NewAPI(client) + return api.MigrateClusterToSBSCSI(request) + + }, + Examples: []*core.Example{ + { + Short: "Migrate a cluster to SBS CSI", + Raw: `scw k8s cluster migrate-to-sbs-csi 11111111-1111-1111-111111111111`, + }, + }, + } +} + func k8sPoolList() *core.Command { return &core.Command{ Short: `List Pools in a Cluster`,