Skip to content

Commit

Permalink
feat(k8s): add k8s in available namespace (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh4d1 authored Mar 6, 2020
1 parent 012978d commit 080706d
Show file tree
Hide file tree
Showing 14 changed files with 310 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/scw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
configNamespace "github.com/scaleway/scaleway-cli/internal/namespaces/config"
initNamespace "github.com/scaleway/scaleway-cli/internal/namespaces/init"
"github.com/scaleway/scaleway-cli/internal/namespaces/instance/v1"
k8s "github.com/scaleway/scaleway-cli/internal/namespaces/k8s/v1beta4"
"github.com/scaleway/scaleway-cli/internal/namespaces/marketplace/v1"
versionNamespace "github.com/scaleway/scaleway-cli/internal/namespaces/version"
"github.com/scaleway/scaleway-cli/internal/sentry"
Expand Down Expand Up @@ -38,6 +39,7 @@ func getCommands() *core.Commands {
// NB: Merge order impacts scw usage sort.
commands := core.NewCommands()
commands.Merge(instance.GetCommands())
commands.Merge(k8s.GetCommands())
commands.Merge(marketplace.GetCommands())
commands.Merge(initNamespace.GetCommands())
commands.Merge(configNamespace.GetCommands())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
This method allows to create a new Kubernetes cluster on an account.

USAGE:
scw [global-flags] k8s cluster create [flags] [arg=value ...]

ARGS:
name The name of the cluster
[description] The description of the cluster
[tags.{index}] The tags associated with the cluster
version The Kubernetes version of the cluster
cni The Container Network Interface (CNI) plugin that will run in the cluster (unknown_cni | cilium | calico | weave | flannel)
[enable-dashboard] The enablement of the Kubernetes Dashboard in the cluster
[ingress] The Ingress Controller that will run in the cluster (unknown_ingress | none | nginx | traefik)
default-pool-config.node-type The node type is the type of Scaleway Instance wanted for the pool
[default-pool-config.placement-group-id] The placement group ID in which all the nodes of the pool will be created
[default-pool-config.autoscaling] The enablement of the autoscaling feature for the pool
default-pool-config.size The size (number of nodes) of the pool
[default-pool-config.min-size] The minimun size of the pool
[default-pool-config.max-size] The maximum size of the pool
[default-pool-config.container-runtime] The container runtime for the nodes of the pool (unknown_runtime | docker | containerd | crio)
[default-pool-config.autohealing] The enablement of the autohealing feature for the pool
[default-pool-config.tags.{index}] The tags associated with the pool
[autoscaler-config.scale-down-disabled] Disable the cluster autoscaler
[autoscaler-config.scale-down-delay-after-add] How long after scale up that scale down evaluation resumes
[autoscaler-config.estimator] Type of resource estimator to be used in scale up (unknown_estimator | binpacking | oldbinpacking)
[autoscaler-config.expander] Type of node group expander to be used in scale up (unknown_expander | random | most_pods | least_waste | priority)
[autoscaler-config.ignore-daemonsets-utilization] Ignore DaemonSet pods when calculating resource utilization for scaling down
[autoscaler-config.balance-similar-node-groups] Detect similar node groups and balance the number of nodes between them
[autoscaler-config.expendable-pods-priority-cutoff] Pods with priority below cutoff will be expendable
[auto-upgrade.enable] Whether or not auto upgrade is enabled for the cluster
[auto-upgrade.maintenance-window.start-hour] The start hour of the 2-hour maintenance window
[auto-upgrade.maintenance-window.day] The day of the week for the maintenance window (any | monday | tuesday | wednesday | thursday | friday | saturday | sunday)
[feature-gates.{index}] List of feature gates to enable
[admission-plugins.{index}] List of admission plugins to enable
[organization-id] Organization ID to use. If none is passed will use default organization ID from the config
[region] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for create

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
@@ -0,0 +1,16 @@
This method allows to delete a specific cluster and all its associated pools and nodes. Note that this method will not delete any Load Balancers or Block Volumes that are associated with the cluster.

USAGE:
scw [global-flags] k8s cluster delete [flags] [arg=value ...]

ARGS:
cluster-id The ID of the cluster to delete
[region] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for delete

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
@@ -0,0 +1,20 @@
This method allows to get details about a specific Kubernetes cluster.

USAGE:
scw [global-flags] k8s cluster get [flags] [arg=value ...]

EXAMPLES:
Get the cluster with id 11111111-1111-1111-111111111111
scw k8s cluster get

ARGS:
cluster-id The ID of the requested cluster
[region] Region to target. If none is passed will use default region from the config (fr-par)

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
@@ -0,0 +1,16 @@
This method allows to list the versions that a specific Kubernetes cluster is allowed to upgrade to. Note that it will be every patch version greater than the actual one as well a one minor version ahead of the actual one. Upgrades skipping a minor version will not work.

USAGE:
scw [global-flags] k8s cluster list-available-versions [flags] [arg=value ...]

ARGS:
cluster-id The ID of the cluster which the available Kuberentes versions will be listed from
[region] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for list-available-versions

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
@@ -0,0 +1,29 @@
This method allows to list all the existing Kubernetes clusters in an account.

USAGE:
scw [global-flags] k8s cluster list [flags] [arg=value ...]

EXAMPLES:
List all the clusters on your default region
scw k8s cluster list

List the ready clusters on your default region
scw k8s cluster list status=ready

List the clusters that match the given name on fr-par ('cluster1' will return 'cluster100' and 'cluster1' but not 'foo')
scw k8s cluster list region=fr-par name=cluster1

ARGS:
[order-by] The sort order of the returned clusters (created_at_asc | created_at_desc | updated_at_asc | updated_at_desc | name_asc | name_desc | status_asc | status_desc | version_asc | version_desc)
[name] The name on which to filter the returned clusters
[status] The status on which to filter the returned clusters (unknown | creating | ready | deleting | deleted | updating | warning | error | locked)
[organization-id] The organization ID on which to filter the returned clusters
[region] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for list

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
@@ -0,0 +1,16 @@
This method allows to reset the admin token for a specific Kubernetes cluster. This will invalidate the old admin token (which will not be usable after) and create a new one. Note that the redownload of the kubeconfig will be necessary to keep interacting with the cluster (if the old admin token was used).

USAGE:
scw [global-flags] k8s cluster reset-admin-token [flags] [arg=value ...]

ARGS:
cluster-id The ID of the cluster of which the admin token will be renewed
[region] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for reset-admin-token

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
@@ -0,0 +1,40 @@
This method allows to update a specific Kubernetes cluster. Note that this method is not made to upgrade a Kubernetes cluster.

USAGE:
scw [global-flags] k8s cluster update [flags] [arg=value ...]

EXAMPLES:
Enable dashboard on cluster 11111111-1111-1111-111111111111
scw k8s cluster update

Add TTLAfterFinished Feature gates on cluster 11111111-1111-1111-111111111111
scw k8s cluster update

ARGS:
cluster-id The ID of the cluster to update
[name] The new name of the cluster
[description] The new description of the cluster
[tags] The new tags associated with the cluster
[autoscaler-config.scale-down-disabled] Disable the cluster autoscaler
[autoscaler-config.scale-down-delay-after-add] How long after scale up that scale down evaluation resumes
[autoscaler-config.estimator] Type of resource estimator to be used in scale up (unknown_estimator | binpacking | oldbinpacking)
[autoscaler-config.expander] Type of node group expander to be used in scale up (unknown_expander | random | most_pods | least_waste | priority)
[autoscaler-config.ignore-daemonsets-utilization] Ignore DaemonSet pods when calculating resource utilization for scaling down
[autoscaler-config.balance-similar-node-groups] Detect similar node groups and balance the number of nodes between them
[autoscaler-config.expendable-pods-priority-cutoff] Pods with priority below cutoff will be expendable
[enable-dashboard] The new value of the Kubernetes Dashboard enablement
[ingress] The new Ingress Controller for the cluster (unknown_ingress | none | nginx | traefik)
[auto-upgrade.enable] Whether or not auto upgrade is enabled for the cluster
[auto-upgrade.maintenance-window.start-hour] The start hour of the 2-hour maintenance window
[auto-upgrade.maintenance-window.day] The day of the week for the maintenance window (any | monday | tuesday | wednesday | thursday | friday | saturday | sunday)
[feature-gates] List of feature gates to enable
[admission-plugins] List of admission plugins to enable
[region] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for update

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
@@ -0,0 +1,18 @@
This method allows to upgrade a specific Kubernetes cluster and/or its associated pools to a specific and supported Kubernetes version.

USAGE:
scw [global-flags] k8s cluster upgrade [flags] [arg=value ...]

ARGS:
cluster-id The ID of the cluster to upgrade
[version] The new Kubernetes version of the cluster
[upgrade-pools] The enablement of the pools upgrade
[region] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for upgrade

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use
26 changes: 26 additions & 0 deletions cmd/scw/testdata/test-all-usage-k8s-cluster-usage.stderr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
A cluster is a fully managed Kubernetes cluster.

It is composed of different pools, each pool containing the same kind of nodes.

USAGE:
scw [global-flags] k8s cluster <command> [flags]

AVAILABLE COMMANDS:
list List all the clusters
create Create a new cluster
get Get a cluster
update Update a cluster
delete Delete a cluster
upgrade Upgrade a cluster
list-available-versions List available versions for a cluster
reset-admin-token Reset the admin token of a cluster

FLAGS:
-h, --help help for cluster

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use

Use "scw k8s cluster [command] --help" for more information about a command.
17 changes: 17 additions & 0 deletions cmd/scw/testdata/test-all-usage-k8s-usage.stderr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
This API allows you to manage your Kapsule clusters

USAGE:
scw [global-flags] k8s <command> [flags]

AVAILABLE COMMANDS:
cluster A cluster is a Kubernetes Kapsule cluster

FLAGS:
-h, --help help for k8s

GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human
-p, --profile string The config profile to use

Use "scw k8s [command] --help" for more information about a command.
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-main-usage-usage.stderr.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ USAGE:

AVAILABLE COMMANDS:
instance Instance API
k8s This API allows you to manage your Kapsule clusters
marketplace Marketplace API
init Initialize the config
config Config file management
Expand Down
23 changes: 23 additions & 0 deletions internal/namespaces/k8s/v1beta4/custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package k8s

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

// GetCommands returns cluster commands.
//
// This function:
// - Gets the generated commands
// - Register handwritten marshalers
// - Apply handwritten overrides (of Command.Run)
func GetCommands() *core.Commands {
cmds := GetGeneratedCommands()

human.RegisterMarshalerFunc(k8s.ClusterStatus(0), human.BindAttributesMarshalFunc(clusterStatusAttributes))

cmds.MustFind("k8s", "cluster", "list-available-versions").Override(clusterAvailableVersionsListBuilder)

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

import (
"context"

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

//
// Marshalers
//

// clusterStatusMarshalerFunc marshals a k8s.ClusterStatus.
var (
clusterStatusAttributes = human.Attributes{
k8s.ClusterStatusCreating: color.FgBlue,
k8s.ClusterStatusReady: color.FgGreen,
k8s.ClusterStatusError: color.FgRed,
k8s.ClusterStatusLocked: color.FgRed,
k8s.ClusterStatusUpdating: color.FgBlue,
k8s.ClusterStatusWarning: color.FgHiYellow,
}
)

func clusterAvailableVersionsListBuilder(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
}

listClusterAvailableVersionsResponse := originalRes.(*k8s.ListClusterAvailableVersionsResponse)
return listClusterAvailableVersionsResponse.Versions, nil
}

return c
}

0 comments on commit 080706d

Please sign in to comment.