From 3da879261539ee126e1c09960868839719d569b1 Mon Sep 17 00:00:00 2001 From: Quentin Brosse Date: Thu, 2 Apr 2020 16:03:57 +0200 Subject: [PATCH] feat(instance): add stocks in server-type list --- internal/human/marshal_func.go | 27 ++++++--- internal/namespaces/instance/v1/custom.go | 10 ++-- .../instance/v1/custom_security_group.go | 12 ++-- .../instance/v1/custom_security_group_rule.go | 23 -------- .../namespaces/instance/v1/custom_server.go | 19 ++++--- .../instance/v1/custom_server_type.go | 57 ++++++++++++++----- .../instance/v1/custom_server_type_test.go | 2 +- .../namespaces/instance/v1/custom_volume.go | 6 +- ...-type-list-server-type-list.cassette.yaml} | 0 ...-type-list-server-type-list.stdout.golden} | 44 +++++++------- internal/namespaces/k8s/v1/custom.go | 6 +- internal/namespaces/k8s/v1/custom_cluster.go | 12 ++-- internal/namespaces/k8s/v1/custom_node.go | 16 +++--- internal/namespaces/k8s/v1/custom_pool.go | 14 ++--- 14 files changed, 134 insertions(+), 114 deletions(-) delete mode 100644 internal/namespaces/instance/v1/custom_security_group_rule.go rename internal/namespaces/instance/v1/testdata/{test-server-type-list-builder-server-type-list.cassette.yaml => test-server-type-list-server-type-list.cassette.yaml} (100%) rename internal/namespaces/instance/v1/testdata/{test-server-type-list-builder-server-type-list.stdout.golden => test-server-type-list-server-type-list.stdout.golden} (62%) diff --git a/internal/human/marshal_func.go b/internal/human/marshal_func.go index 035156515e..e8822db93c 100644 --- a/internal/human/marshal_func.go +++ b/internal/human/marshal_func.go @@ -102,17 +102,26 @@ func isMarshalable(t reflect.Type) bool { (t.Kind() == reflect.Ptr && isMarshalable(t.Elem())) } -// BindAttributesMarshalFunc will apply the Attributes bindings to the value i -func BindAttributesMarshalFunc(attributes Attributes) MarshalerFunc { +type EnumMarshalSpec struct { + // Attribute (mainly colors) to use. + Attribute color.Attribute + + // Value is the value that will be printed for the given value. + Value string +} + +type EnumMarshalSpecs map[interface{}]*EnumMarshalSpec + +func EnumMarshalFunc(specs EnumMarshalSpecs) MarshalerFunc { return func(i interface{}, opt *MarshalOpt) (s string, e error) { - s, _ = defaultMarshalerFunc(i, opt) - attribute, exist := attributes[i] + value, _ := defaultMarshalerFunc(i, opt) + spec, exist := specs[i] if exist { - s = terminal.Style(s, attribute) + if spec.Value != "" { + value = spec.Value + } + value = terminal.Style(value, spec.Attribute) } - return s, nil + return value, nil } } - -// Attributes makes the binding between a value and a color.Attribute -type Attributes map[interface{}]color.Attribute diff --git a/internal/namespaces/instance/v1/custom.go b/internal/namespaces/instance/v1/custom.go index 73710d8fd8..d98728aa02 100644 --- a/internal/namespaces/instance/v1/custom.go +++ b/internal/namespaces/instance/v1/custom.go @@ -23,7 +23,7 @@ func GetCommands() *core.Commands { // Server // human.RegisterMarshalerFunc(instance.CreateServerResponse{}, marshallNestedField("Server")) - human.RegisterMarshalerFunc(instance.ServerState(0), serverStateMarshalerFunc) + human.RegisterMarshalerFunc(instance.ServerState(0), human.EnumMarshalFunc(serverStateMarshalSpecs)) human.RegisterMarshalerFunc(instance.ServerLocation{}, serverLocationMarshalerFunc) human.RegisterMarshalerFunc([]*instance.Server{}, serversMarshalerFunc) human.RegisterMarshalerFunc(instance.GetServerResponse{}, getServerResponseMarshalerFunc) @@ -46,6 +46,8 @@ func GetCommands() *core.Commands { // // Server-Type // + human.RegisterMarshalerFunc(instance.ServerTypesAvailability(""), human.EnumMarshalFunc(serverTypesAvailabilityMarshalSpecs)) + cmds.MustFind("instance", "server-type", "list").Override(serverTypeListBuilder) // @@ -70,7 +72,7 @@ func GetCommands() *core.Commands { // Volume // human.RegisterMarshalerFunc(instance.CreateVolumeResponse{}, marshallNestedField("Volume")) - human.RegisterMarshalerFunc(instance.VolumeState(0), human.BindAttributesMarshalFunc(volumeStateAttributes)) + human.RegisterMarshalerFunc(instance.VolumeState(0), human.EnumMarshalFunc(volumeStateMarshalSpecs)) human.RegisterMarshalerFunc(instance.VolumeSummary{}, volumeSummaryMarshalerFunc) human.RegisterMarshalerFunc(map[string]*instance.Volume{}, volumeMapMarshalerFunc) @@ -78,7 +80,7 @@ func GetCommands() *core.Commands { // Security Group // human.RegisterMarshalerFunc(instance.CreateSecurityGroupResponse{}, marshallNestedField("SecurityGroup")) - human.RegisterMarshalerFunc(instance.SecurityGroupPolicy(0), human.BindAttributesMarshalFunc(securityGroupPolicyAttribute)) + human.RegisterMarshalerFunc(instance.SecurityGroupPolicy(0), human.EnumMarshalFunc(securityGroupPolicyMarshalSpecs)) cmds.MustFind("instance", "security-group", "get").Override(securityGroupGetBuilder) cmds.MustFind("instance", "security-group", "delete").Override(securityGroupDeleteBuilder) @@ -92,7 +94,7 @@ func GetCommands() *core.Commands { // Security Group Rule // human.RegisterMarshalerFunc(instance.CreateSecurityGroupRuleResponse{}, marshallNestedField("Rule")) - human.RegisterMarshalerFunc(instance.SecurityGroupRuleAction(0), human.BindAttributesMarshalFunc(securityGroupRuleActionAttribute)) + human.RegisterMarshalerFunc(instance.SecurityGroupRuleAction(0), human.EnumMarshalFunc(securityGroupRuleActionMarshalSpecs)) // // Placement Group diff --git a/internal/namespaces/instance/v1/custom_security_group.go b/internal/namespaces/instance/v1/custom_security_group.go index bd80e2eceb..445a502bdc 100644 --- a/internal/namespaces/instance/v1/custom_security_group.go +++ b/internal/namespaces/instance/v1/custom_security_group.go @@ -24,14 +24,14 @@ import ( // var ( - securityGroupPolicyAttribute = human.Attributes{ - instance.SecurityGroupPolicyDrop: color.FgRed, - instance.SecurityGroupPolicyAccept: color.FgGreen, + securityGroupPolicyMarshalSpecs = human.EnumMarshalSpecs{ + instance.SecurityGroupPolicyDrop: &human.EnumMarshalSpec{Attribute: color.FgRed}, + instance.SecurityGroupPolicyAccept: &human.EnumMarshalSpec{Attribute: color.FgGreen}, } - securityGroupRuleActionAttribute = human.Attributes{ - instance.SecurityGroupRuleActionDrop: color.FgRed, - instance.SecurityGroupRuleActionAccept: color.FgGreen, + securityGroupRuleActionMarshalSpecs = human.EnumMarshalSpecs{ + instance.SecurityGroupRuleActionDrop: &human.EnumMarshalSpec{Attribute: color.FgRed}, + instance.SecurityGroupRuleActionAccept: &human.EnumMarshalSpec{Attribute: color.FgGreen}, } ) diff --git a/internal/namespaces/instance/v1/custom_security_group_rule.go b/internal/namespaces/instance/v1/custom_security_group_rule.go deleted file mode 100644 index f3b5bd8cdc..0000000000 --- a/internal/namespaces/instance/v1/custom_security_group_rule.go +++ /dev/null @@ -1,23 +0,0 @@ -package instance - -import ( - "github.com/fatih/color" - "github.com/scaleway/scaleway-cli/internal/human" - "github.com/scaleway/scaleway-sdk-go/api/instance/v1" -) - -// -// Marshalers -// - -// serverStateMarshalerFunc marshals a instance.ServerState. -var ( - serverStateAttributes = human.Attributes{ - instance.ServerStateRunning: color.FgGreen, - instance.ServerStateStopped: color.Faint, - instance.ServerStateStoppedInPlace: color.Faint, - instance.ServerStateStarting: color.FgBlue, - instance.ServerStateStopping: color.FgBlue, - instance.ServerStateLocked: color.FgRed, - } -) diff --git a/internal/namespaces/instance/v1/custom_server.go b/internal/namespaces/instance/v1/custom_server.go index f5b464e25c..3a6387f2aa 100644 --- a/internal/namespaces/instance/v1/custom_server.go +++ b/internal/namespaces/instance/v1/custom_server.go @@ -10,11 +10,11 @@ import ( "time" "github.com/fatih/color" + "github.com/hashicorp/go-multierror" "github.com/scaleway/scaleway-cli/internal/core" "github.com/scaleway/scaleway-cli/internal/human" "github.com/scaleway/scaleway-cli/internal/interactive" - "github.com/scaleway/scaleway-cli/internal/terminal" "github.com/scaleway/scaleway-sdk-go/api/instance/v1" "github.com/scaleway/scaleway-sdk-go/logger" "github.com/scaleway/scaleway-sdk-go/scw" @@ -28,14 +28,17 @@ const ( // Marshalers // -// serverStateMarshalerFunc marshals a instance.ServerState. -func serverStateMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) { - // The Scaleway console shows "archived" for a stopped server. - if i.(instance.ServerState) == instance.ServerStateStopped { - return terminal.Style("archived", color.Faint), nil +// serverStateMarshalSpecs allows to override the displayed instance.ServerState. +var ( + serverStateMarshalSpecs = human.EnumMarshalSpecs{ + instance.ServerStateRunning: &human.EnumMarshalSpec{Attribute: color.FgGreen}, + instance.ServerStateStopped: &human.EnumMarshalSpec{Attribute: color.Faint, Value: "archived"}, + instance.ServerStateStoppedInPlace: &human.EnumMarshalSpec{Attribute: color.Faint}, + instance.ServerStateStarting: &human.EnumMarshalSpec{Attribute: color.FgBlue}, + instance.ServerStateStopping: &human.EnumMarshalSpec{Attribute: color.FgBlue}, + instance.ServerStateLocked: &human.EnumMarshalSpec{Attribute: color.FgRed}, } - return human.BindAttributesMarshalFunc(serverStateAttributes)(i, opt) -} +) // serverLocationMarshalerFunc marshals a instance.ServerLocation. func serverLocationMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) { diff --git a/internal/namespaces/instance/v1/custom_server_type.go b/internal/namespaces/instance/v1/custom_server_type.go index 25244eac69..4851234e64 100644 --- a/internal/namespaces/instance/v1/custom_server_type.go +++ b/internal/namespaces/instance/v1/custom_server_type.go @@ -5,11 +5,25 @@ import ( "sort" "strings" + "github.com/fatih/color" "github.com/scaleway/scaleway-cli/internal/core" + "github.com/scaleway/scaleway-cli/internal/human" "github.com/scaleway/scaleway-sdk-go/api/instance/v1" "github.com/scaleway/scaleway-sdk-go/scw" ) +// +// Marshalers +// + +var ( + serverTypesAvailabilityMarshalSpecs = human.EnumMarshalSpecs{ + instance.ServerTypesAvailabilityAvailable: &human.EnumMarshalSpec{Attribute: color.FgGreen}, + instance.ServerTypesAvailabilityScarce: &human.EnumMarshalSpec{Attribute: color.Faint, Value: "low stock"}, + instance.ServerTypesAvailabilityShortage: &human.EnumMarshalSpec{Attribute: color.FgRed, Value: "out of stock"}, + } +) + // // Builders // @@ -33,30 +47,44 @@ func serverTypeListBuilder(c *core.Command) *core.Command { "X64-60GB": {}, } - originalRun := c.Run - c.Run = func(ctx context.Context, argsI interface{}) (interface{}, error) { type customServerType struct { - Name string `json:"name"` - MonthlyPrice *scw.Money `json:"monthly_price"` - HourlyPrice *scw.Money `json:"hourly_price"` - LocalVolumeSize scw.Size `json:"local_volume_size"` - CPU uint32 `json:"cpu"` - GPU *uint64 `json:"gpu"` - RAM scw.Size `json:"ram"` - Arch instance.Arch `json:"arch"` + Name string `json:"name"` + MonthlyPrice *scw.Money `json:"monthly_price"` + HourlyPrice *scw.Money `json:"hourly_price"` + LocalVolumeSize scw.Size `json:"local_volume_size"` + CPU uint32 `json:"cpu"` + GPU *uint64 `json:"gpu"` + RAM scw.Size `json:"ram"` + Arch instance.Arch `json:"arch"` + Availability instance.ServerTypesAvailability `json:"availability"` } - originalRes, err := originalRun(ctx, argsI) + api := instance.NewAPI(core.ExtractClient(ctx)) + + // Get server types. + request := argsI.(*instance.ListServersTypesRequest) + listServersTypesResponse, err := api.ListServersTypes(request) if err != nil { return nil, err } - - listServersTypesResponse := originalRes.(*instance.ListServersTypesResponse) serverTypes := []*customServerType(nil) - for name, serverType := range listServersTypesResponse.Servers { + // Get server availabilities. + serverAvailabilities := make(map[string]instance.ServerTypesAvailability) + availabilitiesResponse, err := api.GetServerTypesAvailability(&instance.GetServerTypesAvailabilityRequest{}) + if err != nil { + // Do nothing and show degraded results. + } else { + serverAvailabilities = availabilitiesResponse.Servers + } + + // Remove me + serverAvailabilities["ARM64-2GB"] = instance.ServerTypesAvailabilityAvailable // available green + serverAvailabilities["ARM64-4GB"] = instance.ServerTypesAvailabilityScarce // low Stock orange + serverAvailabilities["ARM64-8GB"] = instance.ServerTypesAvailabilityShortage // temporarily out of stock red + for name, serverType := range listServersTypesResponse.Servers { _, isDeprecated := deprecatedNames[name] if isDeprecated { continue @@ -71,6 +99,7 @@ func serverTypeListBuilder(c *core.Command) *core.Command { GPU: serverType.Gpu, RAM: scw.Size(serverType.RAM), Arch: serverType.Arch, + Availability: serverAvailabilities[name], }) } diff --git a/internal/namespaces/instance/v1/custom_server_type_test.go b/internal/namespaces/instance/v1/custom_server_type_test.go index 80c5630d1e..5a036c61d5 100644 --- a/internal/namespaces/instance/v1/custom_server_type_test.go +++ b/internal/namespaces/instance/v1/custom_server_type_test.go @@ -6,7 +6,7 @@ import ( "github.com/scaleway/scaleway-cli/internal/core" ) -func Test_serverTypeListBuilder(t *testing.T) { +func Test_ServerTypeList(t *testing.T) { t.Run("server-type list", core.Test(&core.TestConfig{ Commands: GetCommands(), Cmd: "scw instance server-type list", diff --git a/internal/namespaces/instance/v1/custom_volume.go b/internal/namespaces/instance/v1/custom_volume.go index 162dcb3f22..a55f63c3cf 100644 --- a/internal/namespaces/instance/v1/custom_volume.go +++ b/internal/namespaces/instance/v1/custom_volume.go @@ -13,9 +13,9 @@ import ( // var ( - volumeStateAttributes = human.Attributes{ - instance.VolumeStateError: color.FgRed, - instance.VolumeStateAvailable: color.FgGreen, + volumeStateMarshalSpecs = human.EnumMarshalSpecs{ + instance.VolumeStateError: &human.EnumMarshalSpec{Attribute: color.FgRed}, + instance.VolumeStateAvailable: &human.EnumMarshalSpec{Attribute: color.FgGreen}, } ) diff --git a/internal/namespaces/instance/v1/testdata/test-server-type-list-builder-server-type-list.cassette.yaml b/internal/namespaces/instance/v1/testdata/test-server-type-list-server-type-list.cassette.yaml similarity index 100% rename from internal/namespaces/instance/v1/testdata/test-server-type-list-builder-server-type-list.cassette.yaml rename to internal/namespaces/instance/v1/testdata/test-server-type-list-server-type-list.cassette.yaml diff --git a/internal/namespaces/instance/v1/testdata/test-server-type-list-builder-server-type-list.stdout.golden b/internal/namespaces/instance/v1/testdata/test-server-type-list-server-type-list.stdout.golden similarity index 62% rename from internal/namespaces/instance/v1/testdata/test-server-type-list-builder-server-type-list.stdout.golden rename to internal/namespaces/instance/v1/testdata/test-server-type-list-server-type-list.stdout.golden index 14627af16f..4c7a281627 100644 --- a/internal/namespaces/instance/v1/testdata/test-server-type-list-builder-server-type-list.stdout.golden +++ b/internal/namespaces/instance/v1/testdata/test-server-type-list-server-type-list.stdout.golden @@ -1,22 +1,22 @@ -NAME MONTHLY PRICE HOURLY PRICE LOCAL VOLUME SIZE CPU GPU RAM ARCH -ARM64-2GB € 2.99 € 0.006 50 GB 4 2.0 GiB arm64 -ARM64-4GB € 5.99 € 0.012 100 GB 6 4.0 GiB arm64 -ARM64-8GB € 11.99 € 0.024 200 GB 8 8.0 GiB arm64 -ARM64-16GB € 34.99 € 0.07 200 GB 16 16 GiB arm64 -ARM64-32GB € 69.99 € 0.14 300 GB 32 32 GiB arm64 -ARM64-64GB € 139.99 € 0.28 400 GB 48 64 GiB arm64 -ARM64-128GB € 279.99 € 0.56 500 GB 64 128 GiB arm64 -C1 € 2.99 € 0.006 50 GB 4 2.0 GiB arm -C2L € 23.99 € 0.048 50 GB 8 32 GiB x86_64 -C2M € 17.99 € 0.036 50 GB 8 16 GiB x86_64 -C2S € 11.99 € 0.024 50 GB 4 8.0 GiB x86_64 -DEV1-S € 2.99 € 0.006 20 GB 2 2.0 GiB x86_64 -DEV1-M € 7.99 € 0.016 40 GB 3 4.0 GiB x86_64 -DEV1-L € 15.99 € 0.032 80 GB 4 8.0 GiB x86_64 -DEV1-XL € 23.99 € 0.048 120 GB 4 12 GiB x86_64 -GP1-XS € 39.00 € 0.078 150 GB 4 16 GiB x86_64 -GP1-S € 79.00 € 0.158 300 GB 8 32 GiB x86_64 -GP1-M € 159.00 € 0.318 600 GB 16 64 GiB x86_64 -GP1-L € 299.00 € 0.598 600 GB 32 128 GiB x86_64 -GP1-XL € 569.00 € 1.138 600 GB 48 256 GiB x86_64 -RENDER-S € 499.99 € 1.00 400 GB 10 1 45 GiB x86_64 +NAME MONTHLY PRICE HOURLY PRICE LOCAL VOLUME SIZE CPU GPU RAM ARCH AVAILABILITY +ARM64-2GB € 2.99 € 0.006 50 GB 4 2.0 GiB arm64 available +ARM64-4GB € 5.99 € 0.012 100 GB 6 4.0 GiB arm64 low stock +ARM64-8GB € 11.99 € 0.024 200 GB 8 8.0 GiB arm64 out of stock +ARM64-16GB € 34.99 € 0.07 200 GB 16 16 GiB arm64 available +ARM64-32GB € 69.99 € 0.14 300 GB 32 32 GiB arm64 available +ARM64-64GB € 139.99 € 0.28 400 GB 48 64 GiB arm64 available +ARM64-128GB € 279.99 € 0.56 500 GB 64 128 GiB arm64 available +C1 € 2.99 € 0.006 50 GB 4 2.0 GiB arm available +C2L € 23.99 € 0.048 50 GB 8 32 GiB x86_64 available +C2M € 17.99 € 0.036 50 GB 8 16 GiB x86_64 available +C2S € 11.99 € 0.024 50 GB 4 8.0 GiB x86_64 available +DEV1-S € 2.99 € 0.006 20 GB 2 2.0 GiB x86_64 available +DEV1-M € 7.99 € 0.016 40 GB 3 4.0 GiB x86_64 available +DEV1-L € 15.99 € 0.032 80 GB 4 8.0 GiB x86_64 available +DEV1-XL € 23.99 € 0.048 120 GB 4 12 GiB x86_64 available +GP1-XS € 39.00 € 0.078 150 GB 4 16 GiB x86_64 available +GP1-S € 79.00 € 0.158 300 GB 8 32 GiB x86_64 available +GP1-M € 159.00 € 0.318 600 GB 16 64 GiB x86_64 available +GP1-L € 299.00 € 0.598 600 GB 32 128 GiB x86_64 available +GP1-XL € 569.00 € 1.138 600 GB 48 256 GiB x86_64 available +RENDER-S € 499.99 € 1.00 400 GB 10 1 45 GiB x86_64 available diff --git a/internal/namespaces/k8s/v1/custom.go b/internal/namespaces/k8s/v1/custom.go index 368376cd95..7e6de4bd4a 100644 --- a/internal/namespaces/k8s/v1/custom.go +++ b/internal/namespaces/k8s/v1/custom.go @@ -21,9 +21,9 @@ func GetCommands() *core.Commands { k8sKubeconfigUninstallCommand(), )) - human.RegisterMarshalerFunc(k8s.ClusterStatus(0), human.BindAttributesMarshalFunc(clusterStatusAttributes)) - human.RegisterMarshalerFunc(k8s.PoolStatus(0), human.BindAttributesMarshalFunc(poolStatusAttributes)) - human.RegisterMarshalerFunc(k8s.NodeStatus(0), human.BindAttributesMarshalFunc(nodeStatusAttributes)) + human.RegisterMarshalerFunc(k8s.ClusterStatus(0), human.EnumMarshalFunc(clusterStatusMarshalSpecs)) + human.RegisterMarshalerFunc(k8s.PoolStatus(0), human.EnumMarshalFunc(poolStatusMarshalSpecs)) + human.RegisterMarshalerFunc(k8s.NodeStatus(0), human.EnumMarshalFunc(nodeStatusMarshalSpecs)) cmds.MustFind("k8s", "cluster", "list-available-versions").Override(clusterAvailableVersionsListBuilder) cmds.MustFind("k8s", "cluster", "create").Override(clusterCreateBuilder) diff --git a/internal/namespaces/k8s/v1/custom_cluster.go b/internal/namespaces/k8s/v1/custom_cluster.go index 5e52198c86..e807f50290 100644 --- a/internal/namespaces/k8s/v1/custom_cluster.go +++ b/internal/namespaces/k8s/v1/custom_cluster.go @@ -24,12 +24,12 @@ const ( // clusterStatusMarshalerFunc marshals a k8s.ClusterStatus. var ( - clusterStatusAttributes = human.Attributes{ - k8s.ClusterStatusCreating: color.FgBlue, - k8s.ClusterStatusReady: color.FgGreen, - k8s.ClusterStatusPoolRequired: color.FgRed, - k8s.ClusterStatusLocked: color.FgRed, - k8s.ClusterStatusUpdating: color.FgBlue, + clusterStatusMarshalSpecs = human.EnumMarshalSpecs{ + k8s.ClusterStatusCreating: &human.EnumMarshalSpec{Attribute: color.FgBlue}, + k8s.ClusterStatusReady: &human.EnumMarshalSpec{Attribute: color.FgGreen}, + k8s.ClusterStatusPoolRequired: &human.EnumMarshalSpec{Attribute: color.FgRed}, + k8s.ClusterStatusLocked: &human.EnumMarshalSpec{Attribute: color.FgRed}, + k8s.ClusterStatusUpdating: &human.EnumMarshalSpec{Attribute: color.FgBlue}, } ) diff --git a/internal/namespaces/k8s/v1/custom_node.go b/internal/namespaces/k8s/v1/custom_node.go index 5c78429ec4..fd91d1ae24 100644 --- a/internal/namespaces/k8s/v1/custom_node.go +++ b/internal/namespaces/k8s/v1/custom_node.go @@ -16,14 +16,14 @@ const ( ) var ( - // nodeStatusAttributes allows to override the displayed status color - nodeStatusAttributes = human.Attributes{ - k8s.NodeStatusCreating: color.FgBlue, - k8s.NodeStatusRebooting: color.FgBlue, - k8s.NodeStatusReady: color.FgGreen, - k8s.NodeStatusNotReady: color.FgYellow, - k8s.NodeStatusCreationError: color.FgRed, - k8s.NodeStatusLocked: color.FgRed, + // nodeStatusMarshalSpecs allows to override the displayed status color + nodeStatusMarshalSpecs = human.EnumMarshalSpecs{ + k8s.NodeStatusCreating: &human.EnumMarshalSpec{Attribute: color.FgBlue}, + k8s.NodeStatusRebooting: &human.EnumMarshalSpec{Attribute: color.FgBlue}, + k8s.NodeStatusReady: &human.EnumMarshalSpec{Attribute: color.FgGreen}, + k8s.NodeStatusNotReady: &human.EnumMarshalSpec{Attribute: color.FgYellow}, + k8s.NodeStatusCreationError: &human.EnumMarshalSpec{Attribute: color.FgRed}, + k8s.NodeStatusLocked: &human.EnumMarshalSpec{Attribute: color.FgRed}, } ) diff --git a/internal/namespaces/k8s/v1/custom_pool.go b/internal/namespaces/k8s/v1/custom_pool.go index 2f4c42f4b0..e029ea0dcb 100644 --- a/internal/namespaces/k8s/v1/custom_pool.go +++ b/internal/namespaces/k8s/v1/custom_pool.go @@ -22,14 +22,14 @@ const ( // Marshalers // -// poolStatusMarshalerFunc marshals a k8s.PoolStatus. +// poolStatusMarshalSpecs marshals a k8s.PoolStatus. var ( - poolStatusAttributes = human.Attributes{ - k8s.PoolStatusScaling: color.FgBlue, - k8s.PoolStatusReady: color.FgGreen, - k8s.PoolStatusLocked: color.FgRed, - k8s.PoolStatusUpgrading: color.FgBlue, - k8s.PoolStatusWarning: color.FgHiYellow, + poolStatusMarshalSpecs = human.EnumMarshalSpecs{ + k8s.PoolStatusScaling: &human.EnumMarshalSpec{Attribute: color.FgBlue}, + k8s.PoolStatusReady: &human.EnumMarshalSpec{Attribute: color.FgGreen}, + k8s.PoolStatusLocked: &human.EnumMarshalSpec{Attribute: color.FgRed}, + k8s.PoolStatusUpgrading: &human.EnumMarshalSpec{Attribute: color.FgBlue}, + k8s.PoolStatusWarning: &human.EnumMarshalSpec{Attribute: color.FgHiYellow}, } )