Skip to content

Commit 87ce689

Browse files
feat(k8s): enable list cluster types (#3229)
Co-authored-by: Rémy Léone <rleone@scaleway.com>
1 parent 42cdb22 commit 87ce689

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
List available cluster types and their technical details.
4+
5+
USAGE:
6+
scw k8s cluster-type list [arg=value ...]
7+
8+
ARGS:
9+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw | all)
10+
11+
FLAGS:
12+
-h, --help help for list
13+
14+
GLOBAL FLAGS:
15+
-c, --config string The path to the config file
16+
-D, --debug Enable debug mode
17+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
18+
-p, --profile string The config profile to use

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ All cluster types available in a specified region
44
A cluster type represents the different commercial types of clusters offered by Scaleway.
55

66
USAGE:
7-
scw k8s cluster-type
7+
scw k8s cluster-type <command>
8+
9+
AVAILABLE COMMANDS:
10+
list List cluster types
811

912
FLAGS:
1013
-h, --help help for cluster-type
@@ -14,3 +17,5 @@ GLOBAL FLAGS:
1417
-D, --debug Enable debug mode
1518
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
1619
-p, --profile string The config profile to use
20+
21+
Use "scw k8s cluster-type [command] --help" for more information about a command.

docs/commands/k8s.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Kubernetes API.
1515
- [Upgrade a Cluster](#upgrade-a-cluster)
1616
- [Wait for a cluster to reach a stable state](#wait-for-a-cluster-to-reach-a-stable-state)
1717
- [Cluster type management commands](#cluster-type-management-commands)
18+
- [List cluster types](#list-cluster-types)
1819
- [Manage your Kubernetes Kapsule cluster's kubeconfig files](#manage-your-kubernetes-kapsule-cluster's-kubeconfig-files)
1920
- [Retrieve a kubeconfig](#retrieve-a-kubeconfig)
2021
- [Install a kubeconfig](#install-a-kubeconfig)
@@ -501,17 +502,25 @@ All cluster types available in a specified region
501502
A cluster type represents the different commercial types of clusters offered by Scaleway.
502503

503504

504-
All cluster types available in a specified region
505-
A cluster type represents the different commercial types of clusters offered by Scaleway.
506505

506+
### List cluster types
507+
508+
List available cluster types and their technical details.
507509

508510
**Usage:**
509511

510512
```
511-
scw k8s cluster-type
513+
scw k8s cluster-type list [arg=value ...]
512514
```
513515

514516

517+
**Args:**
518+
519+
| Name | | Description |
520+
|------|---|-------------|
521+
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw`, `all` | Region to target. If none is passed will use default region from the config |
522+
523+
515524

516525
## Manage your Kubernetes Kapsule cluster's kubeconfig files
517526

internal/namespaces/k8s/v1/k8s_cli.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func GetGeneratedCommands() *core.Commands {
4848
k8sNodeDelete(),
4949
k8sVersionList(),
5050
k8sVersionGet(),
51+
k8sClusterTypeList(),
5152
)
5253
}
5354
func k8sRoot() *core.Command {
@@ -2062,3 +2063,35 @@ func k8sVersionGet() *core.Command {
20622063
},
20632064
}
20642065
}
2066+
2067+
func k8sClusterTypeList() *core.Command {
2068+
return &core.Command{
2069+
Short: `List cluster types`,
2070+
Long: `List available cluster types and their technical details.`,
2071+
Namespace: "k8s",
2072+
Resource: "cluster-type",
2073+
Verb: "list",
2074+
// Deprecated: false,
2075+
ArgsType: reflect.TypeOf(k8s.ListClusterTypesRequest{}),
2076+
ArgSpecs: core.ArgSpecs{
2077+
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw, scw.Region(core.AllLocalities)),
2078+
},
2079+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
2080+
request := args.(*k8s.ListClusterTypesRequest)
2081+
2082+
client := core.ExtractClient(ctx)
2083+
api := k8s.NewAPI(client)
2084+
opts := []scw.RequestOption{scw.WithAllPages()}
2085+
if request.Region == scw.Region(core.AllLocalities) {
2086+
opts = append(opts, scw.WithRegions(api.Regions()...))
2087+
request.Region = ""
2088+
}
2089+
resp, err := api.ListClusterTypes(request, opts...)
2090+
if err != nil {
2091+
return nil, err
2092+
}
2093+
return resp.ClusterTypes, nil
2094+
2095+
},
2096+
}
2097+
}

0 commit comments

Comments
 (0)