From 5b2e67319bbf24f4e0508d59384beb787acbad76 Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Thu, 10 Dec 2020 11:11:16 +0000 Subject: [PATCH 1/2] feat(k8s): add price expander in autoscaling options --- ...-all-usage-k8s-cluster-create-usage.golden | 2 +- ...-all-usage-k8s-cluster-update-usage.golden | 2 +- .../test-all-usage-rdb-snapshot-usage.golden | 15 ++ .../testdata/test-all-usage-rdb-usage.golden | 1 + internal/namespaces/k8s/v1/k8s_cli.go | 4 +- internal/namespaces/rdb/v1/rdb_cli.go | 227 +++++++++--------- 6 files changed, 139 insertions(+), 112 deletions(-) create mode 100644 cmd/scw/testdata/test-all-usage-rdb-snapshot-usage.golden diff --git a/cmd/scw/testdata/test-all-usage-k8s-cluster-create-usage.golden b/cmd/scw/testdata/test-all-usage-k8s-cluster-create-usage.golden index 4fca5bd9af..acf9bee9ff 100644 --- a/cmd/scw/testdata/test-all-usage-k8s-cluster-create-usage.golden +++ b/cmd/scw/testdata/test-all-usage-k8s-cluster-create-usage.golden @@ -35,7 +35,7 @@ ARGS: [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) - [autoscaler-config.expander] Type of node group expander to be used in scale up (unknown_expander | random | most_pods | least_waste | priority) + [autoscaler-config.expander] Type of node group expander to be used in scale up (unknown_expander | random | most_pods | least_waste | priority | price) [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 diff --git a/cmd/scw/testdata/test-all-usage-k8s-cluster-update-usage.golden b/cmd/scw/testdata/test-all-usage-k8s-cluster-update-usage.golden index e15c385529..7ccad6cdf6 100644 --- a/cmd/scw/testdata/test-all-usage-k8s-cluster-update-usage.golden +++ b/cmd/scw/testdata/test-all-usage-k8s-cluster-update-usage.golden @@ -20,7 +20,7 @@ ARGS: [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) - [autoscaler-config.expander] Type of node group expander to be used in scale up (unknown_expander | random | most_pods | least_waste | priority) + [autoscaler-config.expander] Type of node group expander to be used in scale up (unknown_expander | random | most_pods | least_waste | priority | price) [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 diff --git a/cmd/scw/testdata/test-all-usage-rdb-snapshot-usage.golden b/cmd/scw/testdata/test-all-usage-rdb-snapshot-usage.golden new file mode 100644 index 0000000000..81a8689871 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-rdb-snapshot-usage.golden @@ -0,0 +1,15 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Create, restore and manage block snapshot + +USAGE: + scw rdb snapshot + +FLAGS: + -h, --help help for snapshot + +GLOBAL FLAGS: + -c, --config string The path to the config file + -D, --debug Enable debug mode + -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") + -p, --profile string The config profile to use diff --git a/cmd/scw/testdata/test-all-usage-rdb-usage.golden b/cmd/scw/testdata/test-all-usage-rdb-usage.golden index 9719360f63..bbf10bae91 100644 --- a/cmd/scw/testdata/test-all-usage-rdb-usage.golden +++ b/cmd/scw/testdata/test-all-usage-rdb-usage.golden @@ -14,6 +14,7 @@ AVAILABLE COMMANDS: log Instance logs management commands node-type Node types management commands privilege User privileges management commands + snapshot Block snapshot management user User management commands FLAGS: diff --git a/internal/namespaces/k8s/v1/k8s_cli.go b/internal/namespaces/k8s/v1/k8s_cli.go index 67941572bd..cc5b72a45a 100644 --- a/internal/namespaces/k8s/v1/k8s_cli.go +++ b/internal/namespaces/k8s/v1/k8s_cli.go @@ -386,7 +386,7 @@ func k8sClusterCreate() *core.Command { Required: false, Deprecated: false, Positional: false, - EnumValues: []string{"unknown_expander", "random", "most_pods", "least_waste", "priority"}, + EnumValues: []string{"unknown_expander", "random", "most_pods", "least_waste", "priority", "price"}, }, { Name: "autoscaler-config.ignore-daemonsets-utilization", @@ -641,7 +641,7 @@ func k8sClusterUpdate() *core.Command { Required: false, Deprecated: false, Positional: false, - EnumValues: []string{"unknown_expander", "random", "most_pods", "least_waste", "priority"}, + EnumValues: []string{"unknown_expander", "random", "most_pods", "least_waste", "priority", "price"}, }, { Name: "autoscaler-config.ignore-daemonsets-utilization", diff --git a/internal/namespaces/rdb/v1/rdb_cli.go b/internal/namespaces/rdb/v1/rdb_cli.go index bed501247f..8d9addcd41 100644 --- a/internal/namespaces/rdb/v1/rdb_cli.go +++ b/internal/namespaces/rdb/v1/rdb_cli.go @@ -29,6 +29,9 @@ func GetGeneratedCommands() *core.Commands { rdbDatabase(), rdbNodeType(), rdbLog(), + rdbSnapshot(), + rdbEngineList(), + rdbNodeTypeList(), rdbBackupList(), rdbBackupCreate(), rdbBackupGet(), @@ -36,14 +39,13 @@ func GetGeneratedCommands() *core.Commands { rdbBackupDelete(), rdbBackupRestore(), rdbBackupExport(), - rdbInstanceClone(), - rdbEngineList(), rdbInstanceUpgrade(), rdbInstanceList(), rdbInstanceGet(), rdbInstanceCreate(), rdbInstanceUpdate(), rdbInstanceDelete(), + rdbInstanceClone(), rdbInstanceGetCertificate(), rdbLogPrepare(), rdbLogList(), @@ -60,7 +62,6 @@ func GetGeneratedCommands() *core.Commands { rdbDatabaseDelete(), rdbPrivilegeList(), rdbPrivilegeSet(), - rdbNodeTypeList(), ) } func rdbRoot() *core.Command { @@ -160,6 +161,77 @@ func rdbLog() *core.Command { } } +func rdbSnapshot() *core.Command { + return &core.Command{ + Short: `Block snapshot management`, + Long: `Create, restore and manage block snapshot +`, + Namespace: "rdb", + Resource: "snapshot", + } +} + +func rdbEngineList() *core.Command { + return &core.Command{ + Short: `List available database engines`, + Long: `List available database engines.`, + Namespace: "rdb", + Resource: "engine", + Verb: "list", + // Deprecated: false, + ArgsType: reflect.TypeOf(rdb.ListDatabaseEnginesRequest{}), + ArgSpecs: core.ArgSpecs{ + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*rdb.ListDatabaseEnginesRequest) + + client := core.ExtractClient(ctx) + api := rdb.NewAPI(client) + resp, err := api.ListDatabaseEngines(request, scw.WithAllPages()) + if err != nil { + return nil, err + } + return resp.Engines, nil + + }, + } +} + +func rdbNodeTypeList() *core.Command { + return &core.Command{ + Short: `List available node types`, + Long: `List available node types.`, + Namespace: "rdb", + Resource: "node-type", + Verb: "list", + // Deprecated: false, + ArgsType: reflect.TypeOf(rdb.ListNodeTypesRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "include-disabled-types", + Short: `Whether or not to include disabled types`, + Required: false, + Deprecated: false, + Positional: false, + }, + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*rdb.ListNodeTypesRequest) + + client := core.ExtractClient(ctx) + api := rdb.NewAPI(client) + resp, err := api.ListNodeTypes(request, scw.WithAllPages()) + if err != nil { + return nil, err + } + return resp.NodeTypes, nil + + }, + } +} + func rdbBackupList() *core.Command { return &core.Command{ Short: `List database backups`, @@ -453,77 +525,6 @@ func rdbBackupExport() *core.Command { } } -func rdbInstanceClone() *core.Command { - return &core.Command{ - Short: `Clone an instance`, - Long: `Clone an instance.`, - Namespace: "rdb", - Resource: "instance", - Verb: "clone", - // Deprecated: false, - ArgsType: reflect.TypeOf(rdb.CloneInstanceRequest{}), - ArgSpecs: core.ArgSpecs{ - { - Name: "instance-id", - Short: `UUID of the instance you want to clone`, - Required: true, - Deprecated: false, - Positional: true, - }, - { - Name: "name", - Short: `Name of the clone instance`, - Required: false, - Deprecated: false, - Positional: false, - }, - { - Name: "node-type", - Short: `Node type of the clone`, - Required: false, - Deprecated: false, - Positional: false, - }, - core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), - }, - Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { - request := args.(*rdb.CloneInstanceRequest) - - client := core.ExtractClient(ctx) - api := rdb.NewAPI(client) - return api.CloneInstance(request) - - }, - } -} - -func rdbEngineList() *core.Command { - return &core.Command{ - Short: `List available database engines`, - Long: `List available database engines.`, - Namespace: "rdb", - Resource: "engine", - Verb: "list", - // Deprecated: false, - ArgsType: reflect.TypeOf(rdb.ListDatabaseEnginesRequest{}), - ArgSpecs: core.ArgSpecs{ - core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), - }, - Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { - request := args.(*rdb.ListDatabaseEnginesRequest) - - client := core.ExtractClient(ctx) - api := rdb.NewAPI(client) - resp, err := api.ListDatabaseEngines(request, scw.WithAllPages()) - if err != nil { - return nil, err - } - return resp.Engines, nil - - }, - } -} - func rdbInstanceUpgrade() *core.Command { return &core.Command{ Short: `Upgrade an instance to an higher instance type`, @@ -897,6 +898,50 @@ func rdbInstanceDelete() *core.Command { } } +func rdbInstanceClone() *core.Command { + return &core.Command{ + Short: `Clone an instance`, + Long: `Clone an instance.`, + Namespace: "rdb", + Resource: "instance", + Verb: "clone", + // Deprecated: false, + ArgsType: reflect.TypeOf(rdb.CloneInstanceRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "instance-id", + Short: `UUID of the instance you want to clone`, + Required: true, + Deprecated: false, + Positional: true, + }, + { + Name: "name", + Short: `Name of the clone instance`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "node-type", + Short: `Node type of the clone`, + Required: false, + Deprecated: false, + Positional: false, + }, + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*rdb.CloneInstanceRequest) + + client := core.ExtractClient(ctx) + api := rdb.NewAPI(client) + return api.CloneInstance(request) + + }, + } +} + func rdbInstanceGetCertificate() *core.Command { return &core.Command{ Short: `Get the TLS certificate of an instance`, @@ -1596,37 +1641,3 @@ func rdbPrivilegeSet() *core.Command { }, } } - -func rdbNodeTypeList() *core.Command { - return &core.Command{ - Short: `List available node types`, - Long: `List available node types.`, - Namespace: "rdb", - Resource: "node-type", - Verb: "list", - // Deprecated: false, - ArgsType: reflect.TypeOf(rdb.ListNodeTypesRequest{}), - ArgSpecs: core.ArgSpecs{ - { - Name: "include-disabled-types", - Short: `Whether or not to include disabled types`, - Required: false, - Deprecated: false, - Positional: false, - }, - core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), - }, - Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { - request := args.(*rdb.ListNodeTypesRequest) - - client := core.ExtractClient(ctx) - api := rdb.NewAPI(client) - resp, err := api.ListNodeTypes(request, scw.WithAllPages()) - if err != nil { - return nil, err - } - return resp.NodeTypes, nil - - }, - } -} From 582e1c097b606627f8cf57f32836690f07afe01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Thu, 10 Dec 2020 14:21:07 +0100 Subject: [PATCH 2/2] Fix --- .../test-all-usage-rdb-snapshot-usage.golden | 15 -- .../testdata/test-all-usage-rdb-usage.golden | 1 - internal/namespaces/rdb/v1/rdb_cli.go | 227 +++++++++--------- 3 files changed, 108 insertions(+), 135 deletions(-) delete mode 100644 cmd/scw/testdata/test-all-usage-rdb-snapshot-usage.golden diff --git a/cmd/scw/testdata/test-all-usage-rdb-snapshot-usage.golden b/cmd/scw/testdata/test-all-usage-rdb-snapshot-usage.golden deleted file mode 100644 index 81a8689871..0000000000 --- a/cmd/scw/testdata/test-all-usage-rdb-snapshot-usage.golden +++ /dev/null @@ -1,15 +0,0 @@ -🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 -πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ -Create, restore and manage block snapshot - -USAGE: - scw rdb snapshot - -FLAGS: - -h, --help help for snapshot - -GLOBAL FLAGS: - -c, --config string The path to the config file - -D, --debug Enable debug mode - -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") - -p, --profile string The config profile to use diff --git a/cmd/scw/testdata/test-all-usage-rdb-usage.golden b/cmd/scw/testdata/test-all-usage-rdb-usage.golden index bbf10bae91..9719360f63 100644 --- a/cmd/scw/testdata/test-all-usage-rdb-usage.golden +++ b/cmd/scw/testdata/test-all-usage-rdb-usage.golden @@ -14,7 +14,6 @@ AVAILABLE COMMANDS: log Instance logs management commands node-type Node types management commands privilege User privileges management commands - snapshot Block snapshot management user User management commands FLAGS: diff --git a/internal/namespaces/rdb/v1/rdb_cli.go b/internal/namespaces/rdb/v1/rdb_cli.go index 8d9addcd41..bed501247f 100644 --- a/internal/namespaces/rdb/v1/rdb_cli.go +++ b/internal/namespaces/rdb/v1/rdb_cli.go @@ -29,9 +29,6 @@ func GetGeneratedCommands() *core.Commands { rdbDatabase(), rdbNodeType(), rdbLog(), - rdbSnapshot(), - rdbEngineList(), - rdbNodeTypeList(), rdbBackupList(), rdbBackupCreate(), rdbBackupGet(), @@ -39,13 +36,14 @@ func GetGeneratedCommands() *core.Commands { rdbBackupDelete(), rdbBackupRestore(), rdbBackupExport(), + rdbInstanceClone(), + rdbEngineList(), rdbInstanceUpgrade(), rdbInstanceList(), rdbInstanceGet(), rdbInstanceCreate(), rdbInstanceUpdate(), rdbInstanceDelete(), - rdbInstanceClone(), rdbInstanceGetCertificate(), rdbLogPrepare(), rdbLogList(), @@ -62,6 +60,7 @@ func GetGeneratedCommands() *core.Commands { rdbDatabaseDelete(), rdbPrivilegeList(), rdbPrivilegeSet(), + rdbNodeTypeList(), ) } func rdbRoot() *core.Command { @@ -161,77 +160,6 @@ func rdbLog() *core.Command { } } -func rdbSnapshot() *core.Command { - return &core.Command{ - Short: `Block snapshot management`, - Long: `Create, restore and manage block snapshot -`, - Namespace: "rdb", - Resource: "snapshot", - } -} - -func rdbEngineList() *core.Command { - return &core.Command{ - Short: `List available database engines`, - Long: `List available database engines.`, - Namespace: "rdb", - Resource: "engine", - Verb: "list", - // Deprecated: false, - ArgsType: reflect.TypeOf(rdb.ListDatabaseEnginesRequest{}), - ArgSpecs: core.ArgSpecs{ - core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), - }, - Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { - request := args.(*rdb.ListDatabaseEnginesRequest) - - client := core.ExtractClient(ctx) - api := rdb.NewAPI(client) - resp, err := api.ListDatabaseEngines(request, scw.WithAllPages()) - if err != nil { - return nil, err - } - return resp.Engines, nil - - }, - } -} - -func rdbNodeTypeList() *core.Command { - return &core.Command{ - Short: `List available node types`, - Long: `List available node types.`, - Namespace: "rdb", - Resource: "node-type", - Verb: "list", - // Deprecated: false, - ArgsType: reflect.TypeOf(rdb.ListNodeTypesRequest{}), - ArgSpecs: core.ArgSpecs{ - { - Name: "include-disabled-types", - Short: `Whether or not to include disabled types`, - Required: false, - Deprecated: false, - Positional: false, - }, - core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), - }, - Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { - request := args.(*rdb.ListNodeTypesRequest) - - client := core.ExtractClient(ctx) - api := rdb.NewAPI(client) - resp, err := api.ListNodeTypes(request, scw.WithAllPages()) - if err != nil { - return nil, err - } - return resp.NodeTypes, nil - - }, - } -} - func rdbBackupList() *core.Command { return &core.Command{ Short: `List database backups`, @@ -525,6 +453,77 @@ func rdbBackupExport() *core.Command { } } +func rdbInstanceClone() *core.Command { + return &core.Command{ + Short: `Clone an instance`, + Long: `Clone an instance.`, + Namespace: "rdb", + Resource: "instance", + Verb: "clone", + // Deprecated: false, + ArgsType: reflect.TypeOf(rdb.CloneInstanceRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "instance-id", + Short: `UUID of the instance you want to clone`, + Required: true, + Deprecated: false, + Positional: true, + }, + { + Name: "name", + Short: `Name of the clone instance`, + Required: false, + Deprecated: false, + Positional: false, + }, + { + Name: "node-type", + Short: `Node type of the clone`, + Required: false, + Deprecated: false, + Positional: false, + }, + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*rdb.CloneInstanceRequest) + + client := core.ExtractClient(ctx) + api := rdb.NewAPI(client) + return api.CloneInstance(request) + + }, + } +} + +func rdbEngineList() *core.Command { + return &core.Command{ + Short: `List available database engines`, + Long: `List available database engines.`, + Namespace: "rdb", + Resource: "engine", + Verb: "list", + // Deprecated: false, + ArgsType: reflect.TypeOf(rdb.ListDatabaseEnginesRequest{}), + ArgSpecs: core.ArgSpecs{ + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*rdb.ListDatabaseEnginesRequest) + + client := core.ExtractClient(ctx) + api := rdb.NewAPI(client) + resp, err := api.ListDatabaseEngines(request, scw.WithAllPages()) + if err != nil { + return nil, err + } + return resp.Engines, nil + + }, + } +} + func rdbInstanceUpgrade() *core.Command { return &core.Command{ Short: `Upgrade an instance to an higher instance type`, @@ -898,50 +897,6 @@ func rdbInstanceDelete() *core.Command { } } -func rdbInstanceClone() *core.Command { - return &core.Command{ - Short: `Clone an instance`, - Long: `Clone an instance.`, - Namespace: "rdb", - Resource: "instance", - Verb: "clone", - // Deprecated: false, - ArgsType: reflect.TypeOf(rdb.CloneInstanceRequest{}), - ArgSpecs: core.ArgSpecs{ - { - Name: "instance-id", - Short: `UUID of the instance you want to clone`, - Required: true, - Deprecated: false, - Positional: true, - }, - { - Name: "name", - Short: `Name of the clone instance`, - Required: false, - Deprecated: false, - Positional: false, - }, - { - Name: "node-type", - Short: `Node type of the clone`, - Required: false, - Deprecated: false, - Positional: false, - }, - core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), - }, - Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { - request := args.(*rdb.CloneInstanceRequest) - - client := core.ExtractClient(ctx) - api := rdb.NewAPI(client) - return api.CloneInstance(request) - - }, - } -} - func rdbInstanceGetCertificate() *core.Command { return &core.Command{ Short: `Get the TLS certificate of an instance`, @@ -1641,3 +1596,37 @@ func rdbPrivilegeSet() *core.Command { }, } } + +func rdbNodeTypeList() *core.Command { + return &core.Command{ + Short: `List available node types`, + Long: `List available node types.`, + Namespace: "rdb", + Resource: "node-type", + Verb: "list", + // Deprecated: false, + ArgsType: reflect.TypeOf(rdb.ListNodeTypesRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "include-disabled-types", + Short: `Whether or not to include disabled types`, + Required: false, + Deprecated: false, + Positional: false, + }, + core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*rdb.ListNodeTypesRequest) + + client := core.ExtractClient(ctx) + api := rdb.NewAPI(client) + resp, err := api.ListNodeTypes(request, scw.WithAllPages()) + if err != nil { + return nil, err + } + return resp.NodeTypes, nil + + }, + } +}