Skip to content

Fix cortex cluster scale cmd #2149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions cli/cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}

Expand Down