Skip to content
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

feat(k8s): add marshallers for get versions #1560

Merged
merged 9 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions internal/namespaces/k8s/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func GetCommands() *core.Commands {
k8sPoolWaitCommand(),
))

human.RegisterMarshalerFunc(k8s.Version{}, versionMarshalerFunc)
human.RegisterMarshalerFunc(k8s.Cluster{}, clusterMarshalerFunc)
human.RegisterMarshalerFunc(k8s.ClusterStatus(""), human.EnumMarshalFunc(clusterStatusMarshalSpecs))
human.RegisterMarshalerFunc(k8s.PoolStatus(""), human.EnumMarshalFunc(poolStatusMarshalSpecs))
Expand Down
37 changes: 37 additions & 0 deletions internal/namespaces/k8s/v1/custom_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/scaleway/scaleway-cli/internal/core"
"github.com/scaleway/scaleway-cli/internal/human"
k8s "github.com/scaleway/scaleway-sdk-go/api/k8s/v1"
)

Expand All @@ -20,3 +21,39 @@ func versionListBuilder(c *core.Command) *core.Command {

return c
}

func versionMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
type tmp k8s.Version
version := tmp(i.(k8s.Version))

// Sections
opt.Sections = []*human.MarshalSection{
{
FieldName: "AvailableCnis",
Title: "Available CNIs",
},
{
FieldName: "AvailableIngresses",
Title: "Available Ingresses",
},
{
FieldName: "AvailableContainerRuntimes",
Title: "Available Container Runtimes",
},
{
FieldName: "AvailableFeatureGates",
Title: "Available Feature Gates",
},
{
FieldName: "AvailableAdmissionPlugins",
Title: "Available Admission Plugins",
},
}

str, err := human.Marshal(version, opt)
if err != nil {
return "", err
}

return str, nil
}
21 changes: 21 additions & 0 deletions internal/namespaces/k8s/v1/custom_version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package k8s

import (
"testing"

"github.com/scaleway/scaleway-cli/internal/core"
)

func Test_GetVersion(t *testing.T) {
////
// Simple use cases
////
t.Run("simple", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw k8s version get 1.20.2",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(0),
),
}))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.15.7; darwin; amd64) cli-e2e-test
url: https://api.scaleway.com/k8s/v1/regions/fr-par/versions/1.20.2
method: GET
response:
body: '{"region":"fr-par","name":"1.20.2","label":"Kubernetes 1.20.2","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"}}'
headers:
Content-Length:
- "662"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 09 Feb 2021 15:18:51 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- 0445af44-3011-45d3-a2d9-8d31286bc013
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
Name 1.20.2
Label Kubernetes 1.20.2
Region fr-par
AvailableKubeletArgs.cpuCFSQuota bool
AvailableKubeletArgs.cpuCFSQuotaPeriod duration
AvailableKubeletArgs.cpuManagerPolicy enum:none|static
AvailableKubeletArgs.maxPods uint16

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]
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{
"name": "1.20.2",
"label": "Kubernetes 1.20.2",
"region": "fr-par",
"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"
}
}