Skip to content

Allow nodegroups to be scaled down to max_instances == 0 #2095

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 2 commits into from
Apr 16, 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
8 changes: 6 additions & 2 deletions pkg/types/clusterconfig/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ var ManagedConfigStructFieldValidations = []*cr.StructFieldValidation{
{
StructField: "MaxInstances",
Int64Validation: &cr.Int64Validation{
Default: int64(5),
GreaterThan: pointer.Int64(0),
Default: int64(5),
GreaterThanOrEqualTo: pointer.Int64(0), // this will be validated to be > 0 during cluster up (can be scaled down later)
},
},
{
Expand Down Expand Up @@ -795,6 +795,10 @@ func (cc *Config) Validate(awsClient *aws.Client, skipQuotaVerification bool) er
ngNames := []string{}
instances := []aws.InstanceTypeRequests{}
for _, nodeGroup := range cc.NodeGroups {
// setting max_instances to 0 during cluster creation is not permitted (but scaling max_instances to 0 afterwards is allowed)
if nodeGroup.MaxInstances == 0 {
return errors.Wrap(ErrorNodeGroupMaxInstancesIsZero(), NodeGroupsKey, nodeGroup.Name)
}
if !slices.HasString(ngNames, nodeGroup.Name) {
ngNames = append(ngNames, nodeGroup.Name)
} else {
Expand Down
8 changes: 8 additions & 0 deletions pkg/types/clusterconfig/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
ErrInvalidLegacyProvider = "cli.invalid_legacy_provider"
ErrInvalidRegion = "clusterconfig.invalid_region"
ErrNoNodeGroupSpecified = "clusterconfig.no_nodegroup_specified"
ErrNodeGroupMaxInstancesIsZero = "clusterconfig.node_group_max_instances_is_zero"
ErrMaxNumOfNodeGroupsReached = "clusterconfig.max_num_of_nodegroups_reached"
ErrDuplicateNodeGroupName = "clusterconfig.duplicate_nodegroup_name"
ErrInstanceTypeTooSmall = "clusterconfig.instance_type_too_small"
Expand Down Expand Up @@ -96,6 +97,13 @@ func ErrorNoNodeGroupSpecified() error {
})
}

func ErrorNodeGroupMaxInstancesIsZero() error {
return errors.WithStack(&errors.Error{
Kind: ErrNodeGroupMaxInstancesIsZero,
Message: fmt.Sprintf("nodegroups cannot be created with `%s` set to 0 (but `%s` can be scaled to 0 after the cluster has been created)", MaxInstancesKey, MaxInstancesKey),
})
}

func ErrorMaxNumOfNodeGroupsReached(maxNodeGroups int64) error {
return errors.WithStack(&errors.Error{
Kind: ErrMaxNumOfNodeGroupsReached,
Expand Down