Skip to content

Commit 2f62aeb

Browse files
authored
Fix cortex cluster scale cmd (#2149)
1 parent 7ac0548 commit 2f62aeb

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

cli/cmd/cluster.go

+9-15
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,15 @@ var _clusterScaleCmd = &cobra.Command{
346346
}
347347

348348
clusterConfig := refreshCachedClusterConfig(*awsClient, accessConfig, true)
349-
clusterConfig, err = updateNodeGroupScale(clusterConfig, _flagClusterScaleNodeGroup, scaleMinIntances, scaleMaxInstances, _flagClusterDisallowPrompt)
349+
clusterConfig, ngIndex, err := updateNodeGroupScale(clusterConfig, _flagClusterScaleNodeGroup, scaleMinIntances, scaleMaxInstances, _flagClusterDisallowPrompt)
350350
if err != nil {
351351
exit.Error(err)
352352
}
353353

354354
out, exitCode, err := runManagerWithClusterConfig("/root/install.sh --update", &clusterConfig, awsClient, nil, nil, []string{
355355
"CORTEX_SCALING_NODEGROUP=" + _flagClusterScaleNodeGroup,
356-
"CORTEX_SCALING_MIN_INSTANCES=" + s.Int64(_flagClusterScaleMinInstances),
357-
"CORTEX_SCALING_MAX_INSTANCES=" + s.Int64(_flagClusterScaleMaxInstances),
356+
"CORTEX_SCALING_MIN_INSTANCES=" + s.Int64(clusterConfig.NodeGroups[ngIndex].MinInstances),
357+
"CORTEX_SCALING_MAX_INSTANCES=" + s.Int64(clusterConfig.NodeGroups[ngIndex].MaxInstances),
358358
})
359359
if err != nil {
360360
exit.Error(err)
@@ -1023,11 +1023,10 @@ func refreshCachedClusterConfig(awsClient aws.Client, accessConfig *clusterconfi
10231023
return *refreshedClusterConfig
10241024
}
10251025

1026-
func updateNodeGroupScale(clusterConfig clusterconfig.Config, targetNg string, desiredMinReplicas, desiredMaxReplicas *int64, disallowPrompt bool) (clusterconfig.Config, error) {
1026+
func updateNodeGroupScale(clusterConfig clusterconfig.Config, targetNg string, desiredMinReplicas, desiredMaxReplicas *int64, disallowPrompt bool) (clusterconfig.Config, int, error) {
10271027
clusterName := clusterConfig.ClusterName
10281028
region := clusterConfig.Region
10291029

1030-
ngFound := false
10311030
availableNodeGroups := []string{}
10321031
for idx, ng := range clusterConfig.NodeGroups {
10331032
if ng == nil {
@@ -1048,13 +1047,13 @@ func updateNodeGroupScale(clusterConfig clusterconfig.Config, targetNg string, d
10481047
}
10491048

10501049
if minReplicas < 0 {
1051-
return clusterconfig.Config{}, ErrorMinInstancesLowerThan(0)
1050+
return clusterconfig.Config{}, 0, ErrorMinInstancesLowerThan(0)
10521051
}
10531052
if maxReplicas < 0 {
1054-
return clusterconfig.Config{}, ErrorMaxInstancesLowerThan(0)
1053+
return clusterconfig.Config{}, 0, ErrorMaxInstancesLowerThan(0)
10551054
}
10561055
if minReplicas > maxReplicas {
1057-
return clusterconfig.Config{}, ErrorMinInstancesGreaterThanMaxInstances(minReplicas, maxReplicas)
1056+
return clusterconfig.Config{}, 0, ErrorMinInstancesGreaterThanMaxInstances(minReplicas, maxReplicas)
10581057
}
10591058

10601059
if ng.MinInstances == minReplicas && ng.MaxInstances == maxReplicas {
@@ -1080,16 +1079,11 @@ func updateNodeGroupScale(clusterConfig clusterconfig.Config, targetNg string, d
10801079

10811080
clusterConfig.NodeGroups[idx].MinInstances = minReplicas
10821081
clusterConfig.NodeGroups[idx].MaxInstances = maxReplicas
1083-
ngFound = true
1084-
break
1082+
return clusterConfig, idx, nil
10851083
}
10861084
}
10871085

1088-
if !ngFound {
1089-
return clusterconfig.Config{}, ErrorNodeGroupNotFound(targetNg, clusterName, region, availableNodeGroups)
1090-
}
1091-
1092-
return clusterConfig, nil
1086+
return clusterconfig.Config{}, 0, ErrorNodeGroupNotFound(targetNg, clusterName, region, availableNodeGroups)
10931087
}
10941088

10951089
func createS3BucketIfNotFound(awsClient *aws.Client, bucket string, tags map[string]string) error {

cli/cmd/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func ErrorMaxInstancesLowerThan(minValue int64) error {
220220
func ErrorMinInstancesGreaterThanMaxInstances(minInstances, maxInstances int64) error {
221221
return errors.WithStack(&errors.Error{
222222
Kind: ErrMinInstancesGreaterThanMaxInstances,
223-
Message: "min instances (%d) cannot be set to a value higher than max instances (%d)",
223+
Message: fmt.Sprintf("min instances (%d) cannot be set to a value higher than max instances (%d)", minInstances, maxInstances),
224224
})
225225
}
226226

0 commit comments

Comments
 (0)