Skip to content

feat(k8s): add version commands #775

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 8 commits into from
Mar 17, 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
@@ -0,0 +1,16 @@
Get all the details about a specific Kubernetes version.

USAGE:
scw k8s version get <version> [arg=value ...]

ARGS:
version Version from which to get details
[region] Region to target. If none is passed will use default region from the config

FLAGS:
-h, --help help for get

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 @@ -9,6 +9,7 @@ USAGE:

AVAILABLE COMMANDS:
list List all available versions
get Get a Kubernetes version

FLAGS:
-h, --help help for version
Expand Down
5 changes: 5 additions & 0 deletions internal/namespaces/k8s/v1beta4/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
// - Apply handwritten overrides (of Command.Run)
func GetCommands() *core.Commands {
cmds := GetGeneratedCommands()
cmds.Merge(core.NewCommands(
k8sVersionGetCommand(),
))

human.RegisterMarshalerFunc(k8s.ClusterStatus(0), human.BindAttributesMarshalFunc(clusterStatusAttributes))
human.RegisterMarshalerFunc(k8s.PoolStatus(0), human.BindAttributesMarshalFunc(poolStatusAttributes))
Expand All @@ -32,5 +35,7 @@ func GetCommands() *core.Commands {

cmds.MustFind("k8s", "node", "reboot").Override(nodeRebootBuilder)

cmds.MustFind("k8s", "version", "list").Override(versionListBuilder)

return cmds
}
24 changes: 24 additions & 0 deletions internal/namespaces/k8s/v1beta4/custom_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package k8s

import (
"context"

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

func versionListBuilder(c *core.Command) *core.Command {
originalRun := c.Run

c.Run = func(ctx context.Context, argsI interface{}) (interface{}, error) {
originalRes, err := originalRun(ctx, argsI)
if err != nil {
return nil, err
}

versionsResponse := originalRes.(*k8s.ListVersionsResponse)
return versionsResponse.Versions, nil
}

return c
}
59 changes: 59 additions & 0 deletions internal/namespaces/k8s/v1beta4/custom_version_get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package k8s

import (
"context"
"fmt"
"reflect"

"github.com/scaleway/scaleway-cli/internal/core"
k8s "github.com/scaleway/scaleway-sdk-go/api/k8s/v1beta4"
"github.com/scaleway/scaleway-sdk-go/scw"
)

type k8sVersionGetRequest struct {
Version string
Region scw.Region
}

func k8sVersionGetCommand() *core.Command {
return &core.Command{
Short: `Get a Kubernetes version`,
Long: `Get all the details about a specific Kubernetes version.`,
Namespace: "k8s",
Verb: "get",
Resource: "version",
ArgsType: reflect.TypeOf(k8sVersionGetRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "version",
Short: "Version from which to get details",
Required: true,
Positional: true,
},
core.RegionArgSpec(),
},
Run: k8sVersionGetRun,
}
}

func k8sVersionGetRun(ctx context.Context, argsI interface{}) (i interface{}, e error) {
request := argsI.(*k8sVersionGetRequest)

client := core.ExtractClient(ctx)
apiK8s := k8s.NewAPI(client)

versions, err := apiK8s.ListVersions(&k8s.ListVersionsRequest{
Region: request.Region,
})

if err != nil {
return nil, err
}

for _, version := range versions.Versions {
if version.Name == request.Version {
return version, nil
}
}
return nil, fmt.Errorf("version '%s' not found", request.Version)
}
31 changes: 31 additions & 0 deletions internal/namespaces/k8s/v1beta4/custom_version_get_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package k8s

import (
"fmt"
"testing"

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

////
// Simple use cases
////
func Test_GetVersion(t *testing.T) {
t.Run("simple", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw k8s version get 1.17.4",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(0),
),
}))

t.Run("error", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw k8s version get test",
Check: core.TestCheckCombine(
core.TestCheckError(fmt.Errorf("version 'test' not found")),
core.TestCheckExitCode(1),
),
}))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14; linux; amd64) cli-e2e-test
url: https://api.scaleway.com/k8s/v1beta4/regions/fr-par/versions
method: GET
response:
body: '{"versions":[{"region":"fr-par","name":"1.17.4","label":"Kubernetes 1.17.4","available_cnis":["cilium","calico","weave","flannel"],"available_ingresses":["none","nginx","traefik"],"available_container_runtimes":["docker","containerd","crio"],"available_feature_gates":["TTLAfterFinished","ServiceTopology","EndpointSlice","HPAScaleToZero","ServiceNodeExclusion"],"available_admission_plugins":["PodSecurityPolicy","MutatingAdmissionWebhook","PodNodeSelector","AlwaysPullImages"]},{"region":"fr-par","name":"1.16.8","label":"Kubernetes
1.16.8","available_cnis":["cilium","calico","weave","flannel"],"available_ingresses":["none","nginx","traefik"],"available_container_runtimes":["docker","containerd","crio"],"available_feature_gates":["TTLAfterFinished","EndpointSlice","HPAScaleToZero","ServiceNodeExclusion"],"available_admission_plugins":["PodSecurityPolicy","MutatingAdmissionWebhook","PodNodeSelector","AlwaysPullImages"]},{"region":"fr-par","name":"1.15.11","label":"Kubernetes
1.15.11","available_cnis":["cilium","calico","weave","flannel"],"available_ingresses":["none","nginx","traefik"],"available_container_runtimes":["docker","containerd","crio"],"available_feature_gates":["TTLAfterFinished","ServiceNodeExclusion"],"available_admission_plugins":["PodSecurityPolicy","MutatingAdmissionWebhook","PodNodeSelector","AlwaysPullImages"]}]}'
headers:
Content-Length:
- "1348"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 17 Mar 2020 11:38:15 GMT
Server:
- scaleway_api
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- d3f5d4f9-44bb-4c0c-8c4a-a82d2251db18
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14; linux; amd64) cli-e2e-test
url: https://api.scaleway.com/k8s/v1beta4/regions/fr-par/versions
method: GET
response:
body: '{"versions":[{"region":"fr-par","name":"1.17.4","label":"Kubernetes 1.17.4","available_cnis":["cilium","calico","weave","flannel"],"available_ingresses":["none","nginx","traefik"],"available_container_runtimes":["docker","containerd","crio"],"available_feature_gates":["TTLAfterFinished","ServiceTopology","EndpointSlice","HPAScaleToZero","ServiceNodeExclusion"],"available_admission_plugins":["PodSecurityPolicy","MutatingAdmissionWebhook","PodNodeSelector","AlwaysPullImages"]},{"region":"fr-par","name":"1.16.8","label":"Kubernetes
1.16.8","available_cnis":["cilium","calico","weave","flannel"],"available_ingresses":["none","nginx","traefik"],"available_container_runtimes":["docker","containerd","crio"],"available_feature_gates":["TTLAfterFinished","EndpointSlice","HPAScaleToZero","ServiceNodeExclusion"],"available_admission_plugins":["PodSecurityPolicy","MutatingAdmissionWebhook","PodNodeSelector","AlwaysPullImages"]},{"region":"fr-par","name":"1.15.11","label":"Kubernetes
1.15.11","available_cnis":["cilium","calico","weave","flannel"],"available_ingresses":["none","nginx","traefik"],"available_container_runtimes":["docker","containerd","crio"],"available_feature_gates":["TTLAfterFinished","ServiceNodeExclusion"],"available_admission_plugins":["PodSecurityPolicy","MutatingAdmissionWebhook","PodNodeSelector","AlwaysPullImages"]}]}'
headers:
Content-Length:
- "1348"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 17 Mar 2020 11:38:15 GMT
Server:
- scaleway_api
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- 7d321500-a3fd-4a89-ab8c-12caab3b8f4c
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name 1.17.4
label Kubernetes 1.17.4
region fr-par
available-cnis.0 cilium
available-cnis.1 calico
available-cnis.2 weave
available-cnis.3 flannel
available-ingresses.0 none
available-ingresses.1 nginx
available-ingresses.2 traefik
available-container-runtimes.0 docker
available-container-runtimes.1 containerd
available-container-runtimes.2 crio
available-feature-gates.0 TTLAfterFinished
available-feature-gates.1 ServiceTopology
available-feature-gates.2 EndpointSlice
available-feature-gates.3 HPAScaleToZero
available-feature-gates.4 ServiceNodeExclusion
available-admission-plugins.0 PodSecurityPolicy
available-admission-plugins.1 MutatingAdmissionWebhook
available-admission-plugins.2 PodNodeSelector
available-admission-plugins.3 AlwaysPullImages