Skip to content

Commit 04f9e18

Browse files
feat(k8s): add migrate-to-private-network command (#3144)
Co-authored-by: Jules Castéran <[email protected]>
1 parent 12d813c commit 04f9e18

File tree

4 files changed

+111
-10
lines changed

4 files changed

+111
-10
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Migrate a cluster that was created before the release of Private Network clusters to a new one with a Private Network.
4+
5+
USAGE:
6+
scw k8s cluster migrate-to-private-network <cluster-id ...> [arg=value ...]
7+
8+
EXAMPLES:
9+
Migrate a cluster to a Private Network cluster
10+
scw k8s cluster migrate-to-private-network 11111111-1111-1111-111111111111 private-network-id=11111111-1111-1111-111111111111
11+
12+
ARGS:
13+
cluster-id ID of the cluster to migrate
14+
private-network-id ID of the Private Network to link to the cluster
15+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)
16+
17+
FLAGS:
18+
-h, --help help for migrate-to-private-network
19+
20+
GLOBAL FLAGS:
21+
-c, --config string The path to the config file
22+
-D, --debug Enable debug mode
23+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
24+
-p, --profile string The config profile to use

cmd/scw/testdata/test-all-usage-k8s-cluster-usage.golden

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ USAGE:
77
scw k8s cluster <command>
88

99
AVAILABLE COMMANDS:
10-
create Create a new Cluster
11-
delete Delete a Cluster
12-
get Get a Cluster
13-
list List Clusters
14-
list-available-versions List available versions for a Cluster
15-
reset-admin-token Reset the admin token of a Cluster
16-
set-type Change the Cluster type
17-
update Update a Cluster
18-
upgrade Upgrade a Cluster
10+
create Create a new Cluster
11+
delete Delete a Cluster
12+
get Get a Cluster
13+
list List Clusters
14+
list-available-versions List available versions for a Cluster
15+
migrate-to-private-network Migrate an existing cluster to a Private Network cluster
16+
reset-admin-token Reset the admin token of a Cluster
17+
set-type Change the Cluster type
18+
update Update a Cluster
19+
upgrade Upgrade a Cluster
1920

2021
WORKFLOW COMMANDS:
21-
wait Wait for a cluster to reach a stable state
22+
wait Wait for a cluster to reach a stable state
2223

2324
FLAGS:
2425
-h, --help help for cluster

docs/commands/k8s.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Kubernetes API.
88
- [Get a Cluster](#get-a-cluster)
99
- [List Clusters](#list-clusters)
1010
- [List available versions for a Cluster](#list-available-versions-for-a-cluster)
11+
- [Migrate an existing cluster to a Private Network cluster](#migrate-an-existing-cluster-to-a-private-network-cluster)
1112
- [Reset the admin token of a Cluster](#reset-the-admin-token-of-a-cluster)
1213
- [Change the Cluster type](#change-the-cluster-type)
1314
- [Update a Cluster](#update-a-cluster)
@@ -269,6 +270,37 @@ scw k8s cluster list-available-versions 11111111-1111-1111-111111111111
269270

270271

271272

273+
### Migrate an existing cluster to a Private Network cluster
274+
275+
Migrate a cluster that was created before the release of Private Network clusters to a new one with a Private Network.
276+
277+
**Usage:**
278+
279+
```
280+
scw k8s cluster migrate-to-private-network <cluster-id ...> [arg=value ...]
281+
```
282+
283+
284+
**Args:**
285+
286+
| Name | | Description |
287+
|------|---|-------------|
288+
| cluster-id | Required | ID of the cluster to migrate |
289+
| private-network-id | Required | ID of the Private Network to link to the cluster |
290+
| 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 |
291+
292+
293+
**Examples:**
294+
295+
296+
Migrate a cluster to a Private Network cluster
297+
```
298+
scw k8s cluster migrate-to-private-network 11111111-1111-1111-111111111111 private-network-id=11111111-1111-1111-111111111111
299+
```
300+
301+
302+
303+
272304
### Reset the admin token of a Cluster
273305

274306
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.

internal/namespaces/k8s/v1/k8s_cli.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func GetGeneratedCommands() *core.Commands {
3333
k8sClusterSetType(),
3434
k8sClusterListAvailableVersions(),
3535
k8sClusterResetAdminToken(),
36+
k8sClusterMigrateToPrivateNetwork(),
3637
k8sPoolList(),
3738
k8sPoolCreate(),
3839
k8sPoolGet(),
@@ -1122,6 +1123,49 @@ func k8sClusterResetAdminToken() *core.Command {
11221123
}
11231124
}
11241125

1126+
func k8sClusterMigrateToPrivateNetwork() *core.Command {
1127+
return &core.Command{
1128+
Short: `Migrate an existing cluster to a Private Network cluster`,
1129+
Long: `Migrate a cluster that was created before the release of Private Network clusters to a new one with a Private Network.`,
1130+
Namespace: "k8s",
1131+
Resource: "cluster",
1132+
Verb: "migrate-to-private-network",
1133+
// Deprecated: false,
1134+
ArgsType: reflect.TypeOf(k8s.MigrateToPrivateNetworkClusterRequest{}),
1135+
ArgSpecs: core.ArgSpecs{
1136+
{
1137+
Name: "cluster-id",
1138+
Short: `ID of the cluster to migrate`,
1139+
Required: true,
1140+
Deprecated: false,
1141+
Positional: true,
1142+
},
1143+
{
1144+
Name: "private-network-id",
1145+
Short: `ID of the Private Network to link to the cluster`,
1146+
Required: true,
1147+
Deprecated: false,
1148+
Positional: false,
1149+
},
1150+
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw),
1151+
},
1152+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
1153+
request := args.(*k8s.MigrateToPrivateNetworkClusterRequest)
1154+
1155+
client := core.ExtractClient(ctx)
1156+
api := k8s.NewAPI(client)
1157+
return api.MigrateToPrivateNetworkCluster(request)
1158+
1159+
},
1160+
Examples: []*core.Example{
1161+
{
1162+
Short: "Migrate a cluster to a Private Network cluster",
1163+
Raw: `scw k8s cluster migrate-to-private-network 11111111-1111-1111-111111111111 private-network-id=11111111-1111-1111-111111111111`,
1164+
},
1165+
},
1166+
}
1167+
}
1168+
11251169
func k8sPoolList() *core.Command {
11261170
return &core.Command{
11271171
Short: `List Pools in a Cluster`,

0 commit comments

Comments
 (0)