Skip to content

Commit 06495ef

Browse files
authored
Allow nodegroups to be scaled down to max_instances == 0 (#2095)
1 parent 3d61ec4 commit 06495ef

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pkg/types/clusterconfig/cluster_config.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ var ManagedConfigStructFieldValidations = []*cr.StructFieldValidation{
462462
{
463463
StructField: "MaxInstances",
464464
Int64Validation: &cr.Int64Validation{
465-
Default: int64(5),
466-
GreaterThan: pointer.Int64(0),
465+
Default: int64(5),
466+
GreaterThanOrEqualTo: pointer.Int64(0), // this will be validated to be > 0 during cluster up (can be scaled down later)
467467
},
468468
},
469469
{
@@ -795,6 +795,10 @@ func (cc *Config) Validate(awsClient *aws.Client, skipQuotaVerification bool) er
795795
ngNames := []string{}
796796
instances := []aws.InstanceTypeRequests{}
797797
for _, nodeGroup := range cc.NodeGroups {
798+
// setting max_instances to 0 during cluster creation is not permitted (but scaling max_instances to 0 afterwards is allowed)
799+
if nodeGroup.MaxInstances == 0 {
800+
return errors.Wrap(ErrorNodeGroupMaxInstancesIsZero(), NodeGroupsKey, nodeGroup.Name)
801+
}
798802
if !slices.HasString(ngNames, nodeGroup.Name) {
799803
ngNames = append(ngNames, nodeGroup.Name)
800804
} else {

pkg/types/clusterconfig/errors.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const (
3232
ErrInvalidLegacyProvider = "cli.invalid_legacy_provider"
3333
ErrInvalidRegion = "clusterconfig.invalid_region"
3434
ErrNoNodeGroupSpecified = "clusterconfig.no_nodegroup_specified"
35+
ErrNodeGroupMaxInstancesIsZero = "clusterconfig.node_group_max_instances_is_zero"
3536
ErrMaxNumOfNodeGroupsReached = "clusterconfig.max_num_of_nodegroups_reached"
3637
ErrDuplicateNodeGroupName = "clusterconfig.duplicate_nodegroup_name"
3738
ErrInstanceTypeTooSmall = "clusterconfig.instance_type_too_small"
@@ -96,6 +97,13 @@ func ErrorNoNodeGroupSpecified() error {
9697
})
9798
}
9899

100+
func ErrorNodeGroupMaxInstancesIsZero() error {
101+
return errors.WithStack(&errors.Error{
102+
Kind: ErrNodeGroupMaxInstancesIsZero,
103+
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),
104+
})
105+
}
106+
99107
func ErrorMaxNumOfNodeGroupsReached(maxNodeGroups int64) error {
100108
return errors.WithStack(&errors.Error{
101109
Kind: ErrMaxNumOfNodeGroupsReached,

0 commit comments

Comments
 (0)