Skip to content

Commit d936977

Browse files
authored
feat(k8s): fix version list and add a golden test (#1769)
1 parent 6de8d9e commit d936977

File tree

7 files changed

+279
-46
lines changed

7 files changed

+279
-46
lines changed

internal/namespaces/k8s/v1/custom.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ func GetCommands() *core.Commands {
2626

2727
human.RegisterMarshalerFunc(k8s.Version{}, versionMarshalerFunc)
2828
human.RegisterMarshalerFunc(k8s.Cluster{}, clusterMarshalerFunc)
29-
human.RegisterMarshalerFunc([]k8s.CNI{}, cniSliceMarshalerFunc)
30-
human.RegisterMarshalerFunc([]k8s.Ingress{}, ingressSliceMarshalerFunc)
31-
human.RegisterMarshalerFunc([]k8s.Runtime{}, runtimeSliceMarshalerFunc)
3229
human.RegisterMarshalerFunc(k8s.ClusterStatus(""), human.EnumMarshalFunc(clusterStatusMarshalSpecs))
3330
human.RegisterMarshalerFunc(k8s.PoolStatus(""), human.EnumMarshalFunc(poolStatusMarshalSpecs))
3431
human.RegisterMarshalerFunc(k8s.NodeStatus(""), human.EnumMarshalFunc(nodeStatusMarshalSpecs))

internal/namespaces/k8s/v1/custom_version.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package k8s
22

33
import (
44
"context"
5-
"fmt"
6-
"strings"
75

86
"github.com/scaleway/scaleway-cli/internal/core"
97
"github.com/scaleway/scaleway-cli/internal/human"
@@ -24,33 +22,6 @@ func versionListBuilder(c *core.Command) *core.Command {
2422
return c
2523
}
2624

27-
func runtimeSliceMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
28-
runtimeSlice := i.([]k8s.Runtime)
29-
var res []string
30-
for _, value := range runtimeSlice {
31-
res = append(res, fmt.Sprintf("- %s", value.String()))
32-
}
33-
return strings.Join(res, "\n"), nil
34-
}
35-
36-
func ingressSliceMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
37-
runtimeSlice := i.([]k8s.Ingress)
38-
var res []string
39-
for _, value := range runtimeSlice {
40-
res = append(res, fmt.Sprintf("- %s", value.String()))
41-
}
42-
return strings.Join(res, "\n"), nil
43-
}
44-
45-
func cniSliceMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
46-
runtimeSlice := i.([]k8s.CNI)
47-
var res []string
48-
for _, value := range runtimeSlice {
49-
res = append(res, fmt.Sprintf("- %s", value.String()))
50-
}
51-
return strings.Join(res, "\n"), nil
52-
}
53-
5425
func versionMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
5526
type tmp k8s.Version
5627
version := tmp(i.(k8s.Version))

internal/namespaces/k8s/v1/custom_version_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@ func Test_GetVersion(t *testing.T) {
1919
),
2020
}))
2121
}
22+
23+
func Test_ListVersion_Basic(t *testing.T) {
24+
t.Run("simple", core.Test(&core.TestConfig{
25+
Commands: GetCommands(),
26+
Cmd: "scw k8s version list",
27+
Check: core.TestCheckCombine(
28+
core.TestCheckGolden(),
29+
),
30+
}))
31+
}

internal/namespaces/k8s/v1/testdata/test-get-version-simple.cassette.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interactions:
66
form: {}
77
headers:
88
User-Agent:
9-
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test
9+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.8; darwin; amd64) cli-e2e-test
1010
url: https://api.scaleway.com/k8s/v1/regions/fr-par/versions/1.20.2
1111
method: GET
1212
response:
@@ -19,7 +19,7 @@ interactions:
1919
Content-Type:
2020
- application/json
2121
Date:
22-
- Wed, 10 Feb 2021 15:25:17 GMT
22+
- Thu, 18 Feb 2021 14:28:56 GMT
2323
Server:
2424
- Scaleway API-Gateway
2525
Strict-Transport-Security:
@@ -29,7 +29,7 @@ interactions:
2929
X-Frame-Options:
3030
- DENY
3131
X-Request-Id:
32-
- 6b5b146e-bdd6-485f-b38c-a8782f4eba52
32+
- 29f9a8d1-4bc1-4df9-86a8-5e74f70d2e8c
3333
status: 200 OK
3434
code: 200
3535
duration: ""

internal/namespaces/k8s/v1/testdata/test-get-version-simple.golden

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,13 @@ Available Kubelet Arguments:
88
map[cpuCFSQuota:bool cpuCFSQuotaPeriod:duration cpuManagerPolicy:enum:none|static maxPods:uint16]
99

1010
Available CNIs:
11-
- cilium
12-
- calico
13-
- weave
14-
- flannel
11+
[cilium calico weave flannel]
1512

1613
Available Ingresses:
17-
- none
18-
- nginx
19-
- traefik
20-
- traefik2
14+
[none nginx traefik traefik2]
2115

2216
Available Container Runtimes:
23-
- containerd
24-
- crio
25-
- docker
17+
[containerd crio docker]
2618

2719
Available Feature Gates:
2820
[TTLAfterFinished HPAScaleToZero ServiceTopology EphemeralContainers KubeletCredentialProviders GenericEphemeralVolume]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
User-Agent:
9+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.8; darwin; amd64) cli-e2e-test
10+
url: https://api.scaleway.com/k8s/v1/regions/fr-par/versions
11+
method: GET
12+
response:
13+
body: '{"versions":[{"region":"fr-par","name":"1.20.3","label":"Kubernetes 1.20.3","available_cnis":["cilium","calico","weave","flannel"],"available_ingresses":["none","nginx","traefik","traefik2"],"available_container_runtimes":["containerd","crio","docker"],"available_feature_gates":["TTLAfterFinished","HPAScaleToZero","ServiceTopology","EphemeralContainers","KubeletCredentialProviders","GenericEphemeralVolume"],"available_admission_plugins":["PodSecurityPolicy","PodNodeSelector","AlwaysPullImages","PodPreset","PodTolerationRestriction"],"available_kubelet_args":{"cpuCFSQuota":"bool","cpuCFSQuotaPeriod":"duration","cpuManagerPolicy":"enum:none|static","maxPods":"uint16"}},{"region":"fr-par","name":"1.19.8","label":"Kubernetes 1.19.8","available_cnis":["cilium","calico","weave","flannel"],"available_ingresses":["none","nginx","traefik","traefik2"],"available_container_runtimes":["containerd","crio","docker"],"available_feature_gates":["TTLAfterFinished","ServiceNodeExclusion","EndpointSlice","EndpointSliceProxying","HPAScaleToZero","ServiceTopology","EphemeralContainers","GenericEphemeralVolume"],"available_admission_plugins":["PodSecurityPolicy","PodNodeSelector","AlwaysPullImages","PodPreset","PodTolerationRestriction"],"available_kubelet_args":{"cpuCFSQuota":"bool","cpuCFSQuotaPeriod":"duration","cpuManagerPolicy":"enum:none|static","maxPods":"uint16"}},{"region":"fr-par","name":"1.18.16","label":"Kubernetes 1.18.16","available_cnis":["cilium","calico","weave","flannel"],"available_ingresses":["none","nginx","traefik","traefik2"],"available_container_runtimes":["containerd","crio","docker"],"available_feature_gates":["TTLAfterFinished","ServiceNodeExclusion","EndpointSlice","EndpointSliceProxying","HPAScaleToZero","ServiceTopology","EphemeralContainers"],"available_admission_plugins":["PodSecurityPolicy","PodNodeSelector","AlwaysPullImages","PodPreset","PodTolerationRestriction"],"available_kubelet_args":{"cpuCFSQuota":"bool","cpuCFSQuotaPeriod":"duration","cpuManagerPolicy":"enum:none|static","maxPods":"uint16"}},{"region":"fr-par","name":"1.17.17","label":"Kubernetes 1.17.17","available_cnis":["cilium","calico","weave","flannel"],"available_ingresses":["none","nginx","traefik","traefik2"],"available_container_runtimes":["containerd","crio","docker"],"available_feature_gates":["TTLAfterFinished","ServiceNodeExclusion","EndpointSlice","HPAScaleToZero","ServiceTopology","EphemeralContainers"],"available_admission_plugins":["PodSecurityPolicy","PodNodeSelector","AlwaysPullImages","PodPreset","PodTolerationRestriction"],"available_kubelet_args":{"cpuCFSQuota":"bool","cpuCFSQuotaPeriod":"duration","cpuManagerPolicy":"enum:none|static","maxPods":"uint16"}},{"region":"fr-par","name":"1.16.15","label":"Kubernetes 1.16.15","available_cnis":["cilium","calico","weave","flannel"],"available_ingresses":["none","nginx","traefik","traefik2"],"available_container_runtimes":["containerd","crio","docker"],"available_feature_gates":["TTLAfterFinished","ServiceNodeExclusion","EndpointSlice","HPAScaleToZero","EphemeralContainers"],"available_admission_plugins":["PodSecurityPolicy","PodNodeSelector","AlwaysPullImages","PodPreset","PodTolerationRestriction"],"available_kubelet_args":{"cpuCFSQuota":"bool","cpuCFSQuotaPeriod":"duration","cpuManagerPolicy":"enum:none|static","maxPods":"uint16"}}]}'
14+
headers:
15+
Content-Length:
16+
- "3330"
17+
Content-Security-Policy:
18+
- default-src 'none'; frame-ancestors 'none'
19+
Content-Type:
20+
- application/json
21+
Date:
22+
- Thu, 18 Feb 2021 14:29:13 GMT
23+
Server:
24+
- Scaleway API-Gateway
25+
Strict-Transport-Security:
26+
- max-age=63072000
27+
X-Content-Type-Options:
28+
- nosniff
29+
X-Frame-Options:
30+
- DENY
31+
X-Request-Id:
32+
- 29d7cfc4-5c09-4110-85a8-55d27500f3e1
33+
status: 200 OK
34+
code: 200
35+
duration: ""
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
3+
NAME AVAILABLE CNIS AVAILABLE INGRESSES AVAILABLE CONTAINER RUNTIMES AVAILABLE FEATURE GATES AVAILABLE ADMISSION PLUGINS AVAILABLE KUBELET ARGS
4+
1.20.3 [cilium calico weave flannel] [none nginx traefik traefik2] [containerd crio docker] [TTLAfterFinished HPAScaleToZero ServiceTopology EphemeralContainers KubeletCredentialProviders GenericEphemeralVolume] [PodSecurityPolicy PodNodeSelector AlwaysPullImages PodPreset PodTolerationRestriction] map[cpuCFSQuota:bool cpuCFSQuotaPeriod:duration cpuManagerPolicy:enum:none|static maxPods:uint16]
5+
1.19.8 [cilium calico weave flannel] [none nginx traefik traefik2] [containerd crio docker] [TTLAfterFinished ServiceNodeExclusion EndpointSlice EndpointSliceProxying HPAScaleToZero ServiceTopology EphemeralContainers GenericEphemeralVolume] [PodSecurityPolicy PodNodeSelector AlwaysPullImages PodPreset PodTolerationRestriction] map[cpuCFSQuota:bool cpuCFSQuotaPeriod:duration cpuManagerPolicy:enum:none|static maxPods:uint16]
6+
1.18.16 [cilium calico weave flannel] [none nginx traefik traefik2] [containerd crio docker] [TTLAfterFinished ServiceNodeExclusion EndpointSlice EndpointSliceProxying HPAScaleToZero ServiceTopology EphemeralContainers] [PodSecurityPolicy PodNodeSelector AlwaysPullImages PodPreset PodTolerationRestriction] map[cpuCFSQuota:bool cpuCFSQuotaPeriod:duration cpuManagerPolicy:enum:none|static maxPods:uint16]
7+
1.17.17 [cilium calico weave flannel] [none nginx traefik traefik2] [containerd crio docker] [TTLAfterFinished ServiceNodeExclusion EndpointSlice HPAScaleToZero ServiceTopology EphemeralContainers] [PodSecurityPolicy PodNodeSelector AlwaysPullImages PodPreset PodTolerationRestriction] map[cpuCFSQuota:bool cpuCFSQuotaPeriod:duration cpuManagerPolicy:enum:none|static maxPods:uint16]
8+
1.16.15 [cilium calico weave flannel] [none nginx traefik traefik2] [containerd crio docker] [TTLAfterFinished ServiceNodeExclusion EndpointSlice HPAScaleToZero EphemeralContainers] [PodSecurityPolicy PodNodeSelector AlwaysPullImages PodPreset PodTolerationRestriction] map[cpuCFSQuota:bool cpuCFSQuotaPeriod:duration cpuManagerPolicy:enum:none|static maxPods:uint16]
9+
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
10+
[
11+
{
12+
"name": "1.20.3",
13+
"label": "Kubernetes 1.20.3",
14+
"region": "fr-par",
15+
"available_cnis": [
16+
"cilium",
17+
"calico",
18+
"weave",
19+
"flannel"
20+
],
21+
"available_ingresses": [
22+
"none",
23+
"nginx",
24+
"traefik",
25+
"traefik2"
26+
],
27+
"available_container_runtimes": [
28+
"containerd",
29+
"crio",
30+
"docker"
31+
],
32+
"available_feature_gates": [
33+
"TTLAfterFinished",
34+
"HPAScaleToZero",
35+
"ServiceTopology",
36+
"EphemeralContainers",
37+
"KubeletCredentialProviders",
38+
"GenericEphemeralVolume"
39+
],
40+
"available_admission_plugins": [
41+
"PodSecurityPolicy",
42+
"PodNodeSelector",
43+
"AlwaysPullImages",
44+
"PodPreset",
45+
"PodTolerationRestriction"
46+
],
47+
"available_kubelet_args": {
48+
"cpuCFSQuota": "bool",
49+
"cpuCFSQuotaPeriod": "duration",
50+
"cpuManagerPolicy": "enum:none|static",
51+
"maxPods": "uint16"
52+
}
53+
},
54+
{
55+
"name": "1.19.8",
56+
"label": "Kubernetes 1.19.8",
57+
"region": "fr-par",
58+
"available_cnis": [
59+
"cilium",
60+
"calico",
61+
"weave",
62+
"flannel"
63+
],
64+
"available_ingresses": [
65+
"none",
66+
"nginx",
67+
"traefik",
68+
"traefik2"
69+
],
70+
"available_container_runtimes": [
71+
"containerd",
72+
"crio",
73+
"docker"
74+
],
75+
"available_feature_gates": [
76+
"TTLAfterFinished",
77+
"ServiceNodeExclusion",
78+
"EndpointSlice",
79+
"EndpointSliceProxying",
80+
"HPAScaleToZero",
81+
"ServiceTopology",
82+
"EphemeralContainers",
83+
"GenericEphemeralVolume"
84+
],
85+
"available_admission_plugins": [
86+
"PodSecurityPolicy",
87+
"PodNodeSelector",
88+
"AlwaysPullImages",
89+
"PodPreset",
90+
"PodTolerationRestriction"
91+
],
92+
"available_kubelet_args": {
93+
"cpuCFSQuota": "bool",
94+
"cpuCFSQuotaPeriod": "duration",
95+
"cpuManagerPolicy": "enum:none|static",
96+
"maxPods": "uint16"
97+
}
98+
},
99+
{
100+
"name": "1.18.16",
101+
"label": "Kubernetes 1.18.16",
102+
"region": "fr-par",
103+
"available_cnis": [
104+
"cilium",
105+
"calico",
106+
"weave",
107+
"flannel"
108+
],
109+
"available_ingresses": [
110+
"none",
111+
"nginx",
112+
"traefik",
113+
"traefik2"
114+
],
115+
"available_container_runtimes": [
116+
"containerd",
117+
"crio",
118+
"docker"
119+
],
120+
"available_feature_gates": [
121+
"TTLAfterFinished",
122+
"ServiceNodeExclusion",
123+
"EndpointSlice",
124+
"EndpointSliceProxying",
125+
"HPAScaleToZero",
126+
"ServiceTopology",
127+
"EphemeralContainers"
128+
],
129+
"available_admission_plugins": [
130+
"PodSecurityPolicy",
131+
"PodNodeSelector",
132+
"AlwaysPullImages",
133+
"PodPreset",
134+
"PodTolerationRestriction"
135+
],
136+
"available_kubelet_args": {
137+
"cpuCFSQuota": "bool",
138+
"cpuCFSQuotaPeriod": "duration",
139+
"cpuManagerPolicy": "enum:none|static",
140+
"maxPods": "uint16"
141+
}
142+
},
143+
{
144+
"name": "1.17.17",
145+
"label": "Kubernetes 1.17.17",
146+
"region": "fr-par",
147+
"available_cnis": [
148+
"cilium",
149+
"calico",
150+
"weave",
151+
"flannel"
152+
],
153+
"available_ingresses": [
154+
"none",
155+
"nginx",
156+
"traefik",
157+
"traefik2"
158+
],
159+
"available_container_runtimes": [
160+
"containerd",
161+
"crio",
162+
"docker"
163+
],
164+
"available_feature_gates": [
165+
"TTLAfterFinished",
166+
"ServiceNodeExclusion",
167+
"EndpointSlice",
168+
"HPAScaleToZero",
169+
"ServiceTopology",
170+
"EphemeralContainers"
171+
],
172+
"available_admission_plugins": [
173+
"PodSecurityPolicy",
174+
"PodNodeSelector",
175+
"AlwaysPullImages",
176+
"PodPreset",
177+
"PodTolerationRestriction"
178+
],
179+
"available_kubelet_args": {
180+
"cpuCFSQuota": "bool",
181+
"cpuCFSQuotaPeriod": "duration",
182+
"cpuManagerPolicy": "enum:none|static",
183+
"maxPods": "uint16"
184+
}
185+
},
186+
{
187+
"name": "1.16.15",
188+
"label": "Kubernetes 1.16.15",
189+
"region": "fr-par",
190+
"available_cnis": [
191+
"cilium",
192+
"calico",
193+
"weave",
194+
"flannel"
195+
],
196+
"available_ingresses": [
197+
"none",
198+
"nginx",
199+
"traefik",
200+
"traefik2"
201+
],
202+
"available_container_runtimes": [
203+
"containerd",
204+
"crio",
205+
"docker"
206+
],
207+
"available_feature_gates": [
208+
"TTLAfterFinished",
209+
"ServiceNodeExclusion",
210+
"EndpointSlice",
211+
"HPAScaleToZero",
212+
"EphemeralContainers"
213+
],
214+
"available_admission_plugins": [
215+
"PodSecurityPolicy",
216+
"PodNodeSelector",
217+
"AlwaysPullImages",
218+
"PodPreset",
219+
"PodTolerationRestriction"
220+
],
221+
"available_kubelet_args": {
222+
"cpuCFSQuota": "bool",
223+
"cpuCFSQuotaPeriod": "duration",
224+
"cpuManagerPolicy": "enum:none|static",
225+
"maxPods": "uint16"
226+
}
227+
}
228+
]

0 commit comments

Comments
 (0)