Skip to content

feat(k8s): add wait commands for cluster, node and pool #994

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
May 4, 2020
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
@@ -1,7 +1,7 @@
Connect to the serial console of an instance

USAGE:
scw instance server console <server-id> [arg=value ...]
scw instance server console <server-id ...> [arg=value ...]

ARGS:
server-id Server ID to connect to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <cluster-id ...> [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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions cmd/scw/testdata/test-all-usage-k8s-node-wait-usage.stderr.golden
Original file line number Diff line number Diff line change
@@ -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 <node-id ...> [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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions cmd/scw/testdata/test-all-usage-k8s-pool-wait-usage.stderr.golden
Original file line number Diff line number Diff line change
@@ -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 <pool-id ...> [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
3 changes: 3 additions & 0 deletions internal/namespaces/k8s/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func GetCommands() *core.Commands {
k8sKubeconfigGetCommand(),
k8sKubeconfigInstallCommand(),
k8sKubeconfigUninstallCommand(),
k8sClusterWaitCommand(),
k8sNodeWaitCommand(),
k8sPoolWaitCommand(),
))

human.RegisterMarshalerFunc(k8s.ClusterStatus(0), human.EnumMarshalFunc(clusterStatusMarshalSpecs))
Expand Down
35 changes: 35 additions & 0 deletions internal/namespaces/k8s/v1/custom_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"reflect"
"time"

"github.com/fatih/color"
Expand Down Expand Up @@ -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"}`,
},
},
}
}
35 changes: 35 additions & 0 deletions internal/namespaces/k8s/v1/custom_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package k8s

import (
"context"
"reflect"
"time"

"github.com/fatih/color"
Expand Down Expand Up @@ -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"}`,
},
},
}
}
35 changes: 35 additions & 0 deletions internal/namespaces/k8s/v1/custom_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"reflect"
"time"

"github.com/fatih/color"
Expand Down Expand Up @@ -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"}`,
},
},
}
}