diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index 8a2e3ba1f0..8eeb7c723f 100644 --- a/cli/cmd/cluster.go +++ b/cli/cmd/cluster.go @@ -346,15 +346,15 @@ var _clusterScaleCmd = &cobra.Command{ } clusterConfig := refreshCachedClusterConfig(*awsClient, accessConfig, true) - clusterConfig, err = updateNodeGroupScale(clusterConfig, _flagClusterScaleNodeGroup, scaleMinIntances, scaleMaxInstances, _flagClusterDisallowPrompt) + clusterConfig, ngIndex, err := updateNodeGroupScale(clusterConfig, _flagClusterScaleNodeGroup, scaleMinIntances, scaleMaxInstances, _flagClusterDisallowPrompt) if err != nil { exit.Error(err) } out, exitCode, err := runManagerWithClusterConfig("/root/install.sh --update", &clusterConfig, awsClient, nil, nil, []string{ "CORTEX_SCALING_NODEGROUP=" + _flagClusterScaleNodeGroup, - "CORTEX_SCALING_MIN_INSTANCES=" + s.Int64(_flagClusterScaleMinInstances), - "CORTEX_SCALING_MAX_INSTANCES=" + s.Int64(_flagClusterScaleMaxInstances), + "CORTEX_SCALING_MIN_INSTANCES=" + s.Int64(clusterConfig.NodeGroups[ngIndex].MinInstances), + "CORTEX_SCALING_MAX_INSTANCES=" + s.Int64(clusterConfig.NodeGroups[ngIndex].MaxInstances), }) if err != nil { exit.Error(err) @@ -1023,11 +1023,10 @@ func refreshCachedClusterConfig(awsClient aws.Client, accessConfig *clusterconfi return *refreshedClusterConfig } -func updateNodeGroupScale(clusterConfig clusterconfig.Config, targetNg string, desiredMinReplicas, desiredMaxReplicas *int64, disallowPrompt bool) (clusterconfig.Config, error) { +func updateNodeGroupScale(clusterConfig clusterconfig.Config, targetNg string, desiredMinReplicas, desiredMaxReplicas *int64, disallowPrompt bool) (clusterconfig.Config, int, error) { clusterName := clusterConfig.ClusterName region := clusterConfig.Region - ngFound := false availableNodeGroups := []string{} for idx, ng := range clusterConfig.NodeGroups { if ng == nil { @@ -1048,13 +1047,13 @@ func updateNodeGroupScale(clusterConfig clusterconfig.Config, targetNg string, d } if minReplicas < 0 { - return clusterconfig.Config{}, ErrorMinInstancesLowerThan(0) + return clusterconfig.Config{}, 0, ErrorMinInstancesLowerThan(0) } if maxReplicas < 0 { - return clusterconfig.Config{}, ErrorMaxInstancesLowerThan(0) + return clusterconfig.Config{}, 0, ErrorMaxInstancesLowerThan(0) } if minReplicas > maxReplicas { - return clusterconfig.Config{}, ErrorMinInstancesGreaterThanMaxInstances(minReplicas, maxReplicas) + return clusterconfig.Config{}, 0, ErrorMinInstancesGreaterThanMaxInstances(minReplicas, maxReplicas) } if ng.MinInstances == minReplicas && ng.MaxInstances == maxReplicas { @@ -1080,16 +1079,11 @@ func updateNodeGroupScale(clusterConfig clusterconfig.Config, targetNg string, d clusterConfig.NodeGroups[idx].MinInstances = minReplicas clusterConfig.NodeGroups[idx].MaxInstances = maxReplicas - ngFound = true - break + return clusterConfig, idx, nil } } - if !ngFound { - return clusterconfig.Config{}, ErrorNodeGroupNotFound(targetNg, clusterName, region, availableNodeGroups) - } - - return clusterConfig, nil + return clusterconfig.Config{}, 0, ErrorNodeGroupNotFound(targetNg, clusterName, region, availableNodeGroups) } func createS3BucketIfNotFound(awsClient *aws.Client, bucket string, tags map[string]string) error { diff --git a/cli/cmd/errors.go b/cli/cmd/errors.go index e52995e2e9..4bc9d1a374 100644 --- a/cli/cmd/errors.go +++ b/cli/cmd/errors.go @@ -220,7 +220,7 @@ func ErrorMaxInstancesLowerThan(minValue int64) error { func ErrorMinInstancesGreaterThanMaxInstances(minInstances, maxInstances int64) error { return errors.WithStack(&errors.Error{ Kind: ErrMinInstancesGreaterThanMaxInstances, - Message: "min instances (%d) cannot be set to a value higher than max instances (%d)", + Message: fmt.Sprintf("min instances (%d) cannot be set to a value higher than max instances (%d)", minInstances, maxInstances), }) }