From a3126c6370c17086763a34b83aa71461b467baf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Mon, 4 May 2020 11:53:45 +0200 Subject: [PATCH 1/3] feat(k8s): add wait commands for cluster, node and pool --- internal/namespaces/k8s/v1/custom.go | 3 ++ internal/namespaces/k8s/v1/custom_cluster.go | 35 ++++++++++++++++++++ internal/namespaces/k8s/v1/custom_node.go | 35 ++++++++++++++++++++ internal/namespaces/k8s/v1/custom_pool.go | 35 ++++++++++++++++++++ 4 files changed, 108 insertions(+) diff --git a/internal/namespaces/k8s/v1/custom.go b/internal/namespaces/k8s/v1/custom.go index 7e6de4bd4a..6edbda6a5a 100644 --- a/internal/namespaces/k8s/v1/custom.go +++ b/internal/namespaces/k8s/v1/custom.go @@ -19,6 +19,9 @@ func GetCommands() *core.Commands { k8sKubeconfigGetCommand(), k8sKubeconfigInstallCommand(), k8sKubeconfigUninstallCommand(), + k8sClusterWaitCommand(), + k8sNodeWaitCommand(), + k8sPoolWaitCommand(), )) human.RegisterMarshalerFunc(k8s.ClusterStatus(0), human.EnumMarshalFunc(clusterStatusMarshalSpecs)) diff --git a/internal/namespaces/k8s/v1/custom_cluster.go b/internal/namespaces/k8s/v1/custom_cluster.go index 4efff8d2e6..36efb66a34 100644 --- a/internal/namespaces/k8s/v1/custom_cluster.go +++ b/internal/namespaces/k8s/v1/custom_cluster.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "reflect" "time" "github.com/fatih/color" @@ -101,3 +102,37 @@ func waitForClusterFunc(action int) core.WaitFunc { return nil, err } } + +func k8sClusterWaitCommand() *core.Command { + return &core.Command{ + Short: `Wait for a cluster to reach a stable state`, + Long: `Wait for server to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the server.`, + Namespace: "k8s", + Resource: "cluster", + Verb: "wait", + ArgsType: reflect.TypeOf(k8s.WaitForClusterRequest{}), + Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) { + api := k8s.NewAPI(core.ExtractClient(ctx)) + return api.WaitForCluster(&k8s.WaitForClusterRequest{ + Region: argsI.(*k8s.WaitForClusterRequest).Region, + ClusterID: argsI.(*k8s.WaitForClusterRequest).ClusterID, + Timeout: scw.TimeDurationPtr(clusterActionTimeout), + }) + }, + ArgSpecs: core.ArgSpecs{ + { + Name: "cluster-id", + Short: `ID of the cluster.`, + Required: true, + Positional: true, + }, + core.RegionArgSpec(), + }, + Examples: []*core.Example{ + { + Short: "Wait for a cluster to reach a stable state", + Request: `{"cluster_id": "11111111-1111-1111-1111-111111111111"}`, + }, + }, + } +} diff --git a/internal/namespaces/k8s/v1/custom_node.go b/internal/namespaces/k8s/v1/custom_node.go index fd91d1ae24..11eb2f9fa0 100644 --- a/internal/namespaces/k8s/v1/custom_node.go +++ b/internal/namespaces/k8s/v1/custom_node.go @@ -2,6 +2,7 @@ package k8s import ( "context" + "reflect" "time" "github.com/fatih/color" @@ -50,3 +51,37 @@ func waitForNodeFunc(action int) core.WaitFunc { return nil, err } } + +func k8sNodeWaitCommand() *core.Command { + return &core.Command{ + Short: `Wait for a node to reach a stable state`, + Long: `Wait for a node to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the node.`, + Namespace: "k8s", + Resource: "node", + Verb: "wait", + ArgsType: reflect.TypeOf(k8s.WaitForNodeRequest{}), + Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) { + api := k8s.NewAPI(core.ExtractClient(ctx)) + return api.WaitForNode(&k8s.WaitForNodeRequest{ + Region: argsI.(*k8s.WaitForNodeRequest).Region, + NodeID: argsI.(*k8s.WaitForNodeRequest).NodeID, + Timeout: scw.TimeDurationPtr(nodeActionTimeout), + }) + }, + ArgSpecs: core.ArgSpecs{ + { + Name: "node-id", + Short: `ID of the node.`, + Required: true, + Positional: true, + }, + core.RegionArgSpec(), + }, + Examples: []*core.Example{ + { + Short: "Wait for a node to reach a stable state", + Request: `{"node_id": "11111111-1111-1111-1111-111111111111"}`, + }, + }, + } +} diff --git a/internal/namespaces/k8s/v1/custom_pool.go b/internal/namespaces/k8s/v1/custom_pool.go index e029ea0dcb..1eb9161e17 100644 --- a/internal/namespaces/k8s/v1/custom_pool.go +++ b/internal/namespaces/k8s/v1/custom_pool.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "reflect" "time" "github.com/fatih/color" @@ -87,3 +88,37 @@ func waitForPoolFunc(action int) core.WaitFunc { return nil, err } } + +func k8sPoolWaitCommand() *core.Command { + return &core.Command{ + Short: `Wait for a pool to reach a stable state`, + Long: `Wait for a pool to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the node.`, + Namespace: "k8s", + Resource: "pool", + Verb: "wait", + ArgsType: reflect.TypeOf(k8s.WaitForPoolRequest{}), + Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) { + api := k8s.NewAPI(core.ExtractClient(ctx)) + return api.WaitForPool(&k8s.WaitForPoolRequest{ + Region: argsI.(*k8s.WaitForPoolRequest).Region, + PoolID: argsI.(*k8s.WaitForPoolRequest).PoolID, + Timeout: scw.TimeDurationPtr(poolActionTimeout), + }) + }, + ArgSpecs: core.ArgSpecs{ + { + Name: "pool-id", + Short: `ID of the pool.`, + Required: true, + Positional: true, + }, + core.RegionArgSpec(), + }, + Examples: []*core.Example{ + { + Short: "Wait for a pool to reach a stable state", + Request: `{"pool_id": "11111111-1111-1111-1111-111111111111"}`, + }, + }, + } +} From 84a22b7ffe18fb5209a5cf3531c97e3220b66f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Mon, 4 May 2020 11:55:52 +0200 Subject: [PATCH 2/3] Fix --- ...-all-usage-k8s-cluster-usage.stderr.golden | 1 + ...usage-k8s-cluster-wait-usage.stderr.golden | 20 +++++++++++++++++++ ...est-all-usage-k8s-node-usage.stderr.golden | 1 + ...ll-usage-k8s-node-wait-usage.stderr.golden | 20 +++++++++++++++++++ ...est-all-usage-k8s-pool-usage.stderr.golden | 1 + ...ll-usage-k8s-pool-wait-usage.stderr.golden | 20 +++++++++++++++++++ 6 files changed, 63 insertions(+) create mode 100644 cmd/scw/testdata/test-all-usage-k8s-cluster-wait-usage.stderr.golden create mode 100644 cmd/scw/testdata/test-all-usage-k8s-node-wait-usage.stderr.golden create mode 100644 cmd/scw/testdata/test-all-usage-k8s-pool-wait-usage.stderr.golden diff --git a/cmd/scw/testdata/test-all-usage-k8s-cluster-usage.stderr.golden b/cmd/scw/testdata/test-all-usage-k8s-cluster-usage.stderr.golden index 542ce73899..07583870c0 100644 --- a/cmd/scw/testdata/test-all-usage-k8s-cluster-usage.stderr.golden +++ b/cmd/scw/testdata/test-all-usage-k8s-cluster-usage.stderr.golden @@ -14,6 +14,7 @@ AVAILABLE COMMANDS: upgrade Upgrade a cluster list-available-versions List available versions for a cluster reset-admin-token Reset the admin token of a cluster + wait Wait for a cluster to reach a stable state FLAGS: -h, --help help for cluster diff --git a/cmd/scw/testdata/test-all-usage-k8s-cluster-wait-usage.stderr.golden b/cmd/scw/testdata/test-all-usage-k8s-cluster-wait-usage.stderr.golden new file mode 100644 index 0000000000..b27b293527 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-k8s-cluster-wait-usage.stderr.golden @@ -0,0 +1,20 @@ +Wait for server to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the server. + +USAGE: + scw k8s cluster wait [arg=value ...] + +EXAMPLES: + Wait for a cluster to reach a stable state + scw k8s cluster wait 11111111-1111-1111-1111-111111111111 + +ARGS: + cluster-id ID of the cluster. + [region] Region to target. If none is passed will use default region from the config + +FLAGS: + -h, --help help for wait + +GLOBAL FLAGS: + -D, --debug Enable debug mode + -o, --output string Output format: json or human + -p, --profile string The config profile to use diff --git a/cmd/scw/testdata/test-all-usage-k8s-node-usage.stderr.golden b/cmd/scw/testdata/test-all-usage-k8s-node-usage.stderr.golden index a1d84eb53c..91a7ce70fa 100644 --- a/cmd/scw/testdata/test-all-usage-k8s-node-usage.stderr.golden +++ b/cmd/scw/testdata/test-all-usage-k8s-node-usage.stderr.golden @@ -10,6 +10,7 @@ AVAILABLE COMMANDS: get Get a node in a cluster replace Replace a node in a cluster reboot Reboot a node in a cluster + wait Wait for a node to reach a stable state FLAGS: -h, --help help for node diff --git a/cmd/scw/testdata/test-all-usage-k8s-node-wait-usage.stderr.golden b/cmd/scw/testdata/test-all-usage-k8s-node-wait-usage.stderr.golden new file mode 100644 index 0000000000..029ee54fdb --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-k8s-node-wait-usage.stderr.golden @@ -0,0 +1,20 @@ +Wait for a node to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the node. + +USAGE: + scw k8s node wait [arg=value ...] + +EXAMPLES: + Wait for a node to reach a stable state + scw k8s node wait 11111111-1111-1111-1111-111111111111 + +ARGS: + node-id ID of the node. + [region] Region to target. If none is passed will use default region from the config + +FLAGS: + -h, --help help for wait + +GLOBAL FLAGS: + -D, --debug Enable debug mode + -o, --output string Output format: json or human + -p, --profile string The config profile to use diff --git a/cmd/scw/testdata/test-all-usage-k8s-pool-usage.stderr.golden b/cmd/scw/testdata/test-all-usage-k8s-pool-usage.stderr.golden index 54148c17c2..41f40ba85f 100644 --- a/cmd/scw/testdata/test-all-usage-k8s-pool-usage.stderr.golden +++ b/cmd/scw/testdata/test-all-usage-k8s-pool-usage.stderr.golden @@ -12,6 +12,7 @@ AVAILABLE COMMANDS: upgrade Upgrade a pool in a cluster update Update a pool in a cluster delete Delete a pool in a cluster + wait Wait for a pool to reach a stable state FLAGS: -h, --help help for pool diff --git a/cmd/scw/testdata/test-all-usage-k8s-pool-wait-usage.stderr.golden b/cmd/scw/testdata/test-all-usage-k8s-pool-wait-usage.stderr.golden new file mode 100644 index 0000000000..9c6cfbc0eb --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-k8s-pool-wait-usage.stderr.golden @@ -0,0 +1,20 @@ +Wait for a pool to reach a stable state. This is similar to using --wait flag on other action commands, but without requiring a new action on the node. + +USAGE: + scw k8s pool wait [arg=value ...] + +EXAMPLES: + Wait for a pool to reach a stable state + scw k8s pool wait 11111111-1111-1111-1111-111111111111 + +ARGS: + pool-id ID of the pool. + [region] Region to target. If none is passed will use default region from the config + +FLAGS: + -h, --help help for wait + +GLOBAL FLAGS: + -D, --debug Enable debug mode + -o, --output string Output format: json or human + -p, --profile string The config profile to use From 0db3d32413752704a3f251191d6f11c1e4a282e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Mon, 4 May 2020 11:57:58 +0200 Subject: [PATCH 3/3] Fix --- .../test-all-usage-instance-server-console-usage.stderr.golden | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/scw/testdata/test-all-usage-instance-server-console-usage.stderr.golden b/cmd/scw/testdata/test-all-usage-instance-server-console-usage.stderr.golden index 1716cc1cf1..55a317daeb 100644 --- a/cmd/scw/testdata/test-all-usage-instance-server-console-usage.stderr.golden +++ b/cmd/scw/testdata/test-all-usage-instance-server-console-usage.stderr.golden @@ -1,7 +1,7 @@ Connect to the serial console of an instance USAGE: - scw instance server console [arg=value ...] + scw instance server console [arg=value ...] ARGS: server-id Server ID to connect to