Skip to content

Commit

Permalink
feat(k8s): add support for deleting a node (#2426)
Browse files Browse the repository at this point in the history
Co-authored-by: Rémy Léone <rleone@scaleway.com>
  • Loading branch information
scaleway-bot and remyleone authored Jul 29, 2022
1 parent 4b31b4a commit c49c798
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 4 deletions.
23 changes: 23 additions & 0 deletions cmd/scw/testdata/test-all-usage-k8s-node-delete-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
This method allows to delete a specific node. Note that when there is not enough space to reschedule all the pods (in a one node cluster for instance), you may experience some disruption of your applications.

USAGE:
scw k8s node delete [arg=value ...]

EXAMPLES:
Delete a given node
scw k8s node delete 11111111-1111-1111-111111111111

ARGS:
node-id
[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 delete

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
2 changes: 1 addition & 1 deletion cmd/scw/testdata/test-all-usage-k8s-node-list-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ARGS:
[pool-id] The pool ID on which to filter the returned nodes
[order-by] The sort order of the returned nodes (created_at_asc | created_at_desc)
[name] The name on which to filter the returned nodes
[status] The status on which to filter the returned nodes (unknown | creating | not_ready | ready | deleting | deleted | locked | rebooting | creation_error | upgrading)
[status] The status on which to filter the returned nodes (unknown | creating | not_ready | ready | deleting | deleted | locked | rebooting | creation_error | upgrading | starting)
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)

FLAGS:
Expand Down
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-all-usage-k8s-node-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ USAGE:
scw k8s node <command>

AVAILABLE COMMANDS:
delete Delete a node in a cluster
get Get a node in a cluster
list List all the nodes in a cluster
reboot Reboot a node in a cluster
Expand Down
33 changes: 32 additions & 1 deletion docs/commands/k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Kapsule API
- [Install a kubeconfig](#install-a-kubeconfig)
- [Uninstall a kubeconfig](#uninstall-a-kubeconfig)
- [Kapsule node management commands](#kapsule-node-management-commands)
- [Delete a node in a cluster](#delete-a-node-in-a-cluster)
- [Get a node in a cluster](#get-a-node-in-a-cluster)
- [List all the nodes in a cluster](#list-all-the-nodes-in-a-cluster)
- [Reboot a node in a cluster](#reboot-a-node-in-a-cluster)
Expand Down Expand Up @@ -528,6 +529,36 @@ Please note that Kubernetes nodes cannot be accessed with ssh.



### Delete a node in a cluster

This method allows to delete a specific node. Note that when there is not enough space to reschedule all the pods (in a one node cluster for instance), you may experience some disruption of your applications.

**Usage:**

```
scw k8s node delete [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| node-id | Required | |
| 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:**


Delete a given node
```
scw k8s node delete 11111111-1111-1111-111111111111
```




### Get a node in a cluster

This method allows to get details about a specific Kubernetes node.
Expand Down Expand Up @@ -577,7 +608,7 @@ scw k8s node list [arg=value ...]
| pool-id | | The pool ID on which to filter the returned nodes |
| order-by | One of: `created_at_asc`, `created_at_desc` | The sort order of the returned nodes |
| name | | The name on which to filter the returned nodes |
| status | One of: `unknown`, `creating`, `not_ready`, `ready`, `deleting`, `deleted`, `locked`, `rebooting`, `creation_error`, `upgrading` | The status on which to filter the returned nodes |
| status | One of: `unknown`, `creating`, `not_ready`, `ready`, `deleting`, `deleted`, `locked`, `rebooting`, `creation_error`, `upgrading`, `starting` | The status on which to filter the returned nodes |
| 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 |


Expand Down
40 changes: 38 additions & 2 deletions internal/namespaces/k8s/v1/k8s_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func GetGeneratedCommands() *core.Commands {
k8sNodeGet(),
k8sNodeReplace(),
k8sNodeReboot(),
k8sNodeDelete(),
k8sVersionList(),
k8sVersionGet(),
)
Expand Down Expand Up @@ -1620,7 +1621,7 @@ func k8sNodeList() *core.Command {
Required: false,
Deprecated: false,
Positional: false,
EnumValues: []string{"unknown", "creating", "not_ready", "ready", "deleting", "deleted", "locked", "rebooting", "creation_error", "upgrading"},
EnumValues: []string{"unknown", "creating", "not_ready", "ready", "deleting", "deleted", "locked", "rebooting", "creation_error", "upgrading", "starting"},
},
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw),
},
Expand Down Expand Up @@ -1728,7 +1729,7 @@ func k8sNodeReplace() *core.Command {
Namespace: "k8s",
Resource: "node",
Verb: "replace",
// Deprecated: false,
// Deprecated: true,
ArgsType: reflect.TypeOf(k8s.ReplaceNodeRequest{}),
ArgSpecs: core.ArgSpecs{
{
Expand Down Expand Up @@ -1793,6 +1794,41 @@ func k8sNodeReboot() *core.Command {
}
}

func k8sNodeDelete() *core.Command {
return &core.Command{
Short: `Delete a node in a cluster`,
Long: `This method allows to delete a specific node. Note that when there is not enough space to reschedule all the pods (in a one node cluster for instance), you may experience some disruption of your applications.`,
Namespace: "k8s",
Resource: "node",
Verb: "delete",
// Deprecated: false,
ArgsType: reflect.TypeOf(k8s.DeleteNodeRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "node-id",
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.DeleteNodeRequest)

client := core.ExtractClient(ctx)
api := k8s.NewAPI(client)
return api.DeleteNode(request)

},
Examples: []*core.Example{
{
Short: "Delete a given node",
Raw: `scw k8s node delete 11111111-1111-1111-111111111111`,
},
},
}
}

func k8sVersionList() *core.Command {
return &core.Command{
Short: `List all available versions`,
Expand Down

0 comments on commit c49c798

Please sign in to comment.