diff --git a/pkg/types/clusterconfig/cluster_config.go b/pkg/types/clusterconfig/cluster_config.go index b86e5fe474..59ed9d72e5 100644 --- a/pkg/types/clusterconfig/cluster_config.go +++ b/pkg/types/clusterconfig/cluster_config.go @@ -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) }, }, { @@ -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 { diff --git a/pkg/types/clusterconfig/errors.go b/pkg/types/clusterconfig/errors.go index 5ac429f01a..414e6fd81b 100644 --- a/pkg/types/clusterconfig/errors.go +++ b/pkg/types/clusterconfig/errors.go @@ -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" @@ -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,