Skip to content

Commit f0948be

Browse files
authored
Support clusters with no node groups (#2269)
1 parent af1b2f0 commit f0948be

File tree

6 files changed

+39
-31
lines changed

6 files changed

+39
-31
lines changed

pkg/lib/configreader/reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type StructListValidation struct {
9494
StructValidation *StructValidation
9595
Required bool
9696
AllowExplicitNull bool
97-
TreatNullAsEmpty bool // If explicit null or if it's top level and the file is empty, treat as empty map
97+
TreatNullAsEmpty bool // If explicit null or if it's top level and the file is empty, treat as empty list
9898
MinLength int
9999
MaxLength int
100100
InvalidLengths []int

pkg/operator/resources/errors.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const (
4444
ErrRealtimeAPIUsedByTrafficSplitter = "resources.realtime_api_used_by_traffic_splitter"
4545
ErrAPIsNotDeployed = "resources.apis_not_deployed"
4646
ErrInvalidNodeGroupSelector = "resources.invalid_node_group_selector"
47+
ErrNoNodeGroups = "resources.no_node_groups"
4748
)
4849

4950
func ErrorOperationIsOnlySupportedForKind(resource operator.DeployedResource, supportedKind userconfig.Kind, supportedKinds ...userconfig.Kind) error {
@@ -118,6 +119,13 @@ func ErrorInvalidNodeGroupSelector(selected string, availableNodeGroups []string
118119
})
119120
}
120121

122+
func ErrorNoNodeGroups() error {
123+
return errors.WithStack(&errors.Error{
124+
Kind: ErrNoNodeGroups,
125+
Message: fmt.Sprintf("your api cannot be deployed because your cluster doesn't have any node groups; create a node group with `cortex cluster configure CLUSTER_CONFIG_FILE`"),
126+
})
127+
}
128+
121129
func podResourceRequestsTable(api *userconfig.API, compute userconfig.Compute) string {
122130
sidecarCPUNote := ""
123131
sidecarMemNote := ""

pkg/operator/resources/validations.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func ValidateClusterAPIs(apis []userconfig.API) error {
3636
return spec.ErrorNoAPIs()
3737
}
3838

39+
if len(config.ClusterConfig.NodeGroups) == 0 {
40+
return ErrorNoNodeGroups()
41+
}
42+
3943
virtualServices, err := config.K8s.ListVirtualServices(nil)
4044
if err != nil {
4145
return err

pkg/types/clusterconfig/availability_zones.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ func (cc *Config) setDefaultAvailabilityZones(awsClient *aws.Client) error {
4747
}
4848
instanceTypesSlice := instanceTypes.Slice()
4949

50-
zones, err := awsClient.ListSupportedAvailabilityZones(instanceTypesSlice[0], instanceTypesSlice[1:]...)
51-
if err != nil {
52-
// Try again without checking instance types
50+
var zones strset.Set
51+
var err error
52+
if len(instanceTypesSlice) > 0 {
53+
zones, err = awsClient.ListSupportedAvailabilityZones(instanceTypesSlice[0], instanceTypesSlice[1:]...)
54+
}
55+
if len(zones) == 0 || err != nil {
56+
// Try without checking instance types
5357
zones, err = awsClient.ListAvailabilityZonesInRegion()
5458
if err != nil {
5559
return nil // Let eksctl choose the availability zones
@@ -75,12 +79,6 @@ func (cc *Config) setDefaultAvailabilityZones(awsClient *aws.Client) error {
7579
}
7680

7781
func (cc *Config) validateUserAvailabilityZones(awsClient *aws.Client) error {
78-
instanceTypes := strset.New()
79-
for _, ng := range cc.NodeGroups {
80-
instanceTypes.Add(ng.InstanceType)
81-
}
82-
instanceTypesSlice := instanceTypes.Slice()
83-
8482
allZones, err := awsClient.ListAvailabilityZonesInRegion()
8583
if err != nil {
8684
return nil // Skip validation
@@ -92,15 +90,23 @@ func (cc *Config) validateUserAvailabilityZones(awsClient *aws.Client) error {
9290
}
9391
}
9492

95-
supportedZones, err := awsClient.ListSupportedAvailabilityZones(instanceTypesSlice[0], instanceTypesSlice[1:]...)
96-
if err != nil {
97-
// Skip validation instance-based validation
98-
supportedZones = strset.Difference(allZones, _azBlacklist)
99-
}
93+
if len(cc.NodeGroups) > 0 {
94+
instanceTypes := strset.New()
95+
for _, ng := range cc.NodeGroups {
96+
instanceTypes.Add(ng.InstanceType)
97+
}
98+
instanceTypesSlice := instanceTypes.Slice()
10099

101-
for _, userZone := range cc.AvailabilityZones {
102-
if !supportedZones.Has(userZone) {
103-
return ErrorUnsupportedAvailabilityZone(userZone, instanceTypesSlice[0], instanceTypesSlice[1:]...)
100+
supportedZones, err := awsClient.ListSupportedAvailabilityZones(instanceTypesSlice[0], instanceTypesSlice[1:]...)
101+
if err != nil {
102+
// Skip validation instance-based validation
103+
supportedZones = strset.Difference(allZones, _azBlacklist)
104+
}
105+
106+
for _, userZone := range cc.AvailabilityZones {
107+
if !supportedZones.Has(userZone) {
108+
return ErrorUnsupportedAvailabilityZone(userZone, instanceTypesSlice[0], instanceTypesSlice[1:]...)
109+
}
104110
}
105111
}
106112

pkg/types/clusterconfig/cluster_config.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,9 @@ var ManagedConfigStructFieldValidations = []*cr.StructFieldValidation{
517517
{
518518
StructField: "NodeGroups",
519519
StructListValidation: &cr.StructListValidation{
520-
Required: true,
521-
StructValidation: nodeGroupsFieldValidation,
520+
AllowExplicitNull: true,
521+
TreatNullAsEmpty: true,
522+
StructValidation: nodeGroupsFieldValidation,
522523
},
523524
},
524525
{
@@ -890,9 +891,6 @@ func (cc *CoreConfig) SQSNamePrefix() string {
890891

891892
func (cc *Config) validate(awsClient *aws.Client) error {
892893
numNodeGroups := len(cc.NodeGroups)
893-
if numNodeGroups == 0 {
894-
return ErrorNoNodeGroupSpecified()
895-
}
896894
if numNodeGroups > MaxNodePoolsOrGroups {
897895
return ErrorMaxNumOfNodeGroupsReached(MaxNodePoolsOrGroups)
898896
}

pkg/types/clusterconfig/errors.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const (
3232
ErrInvalidLegacyProvider = "clusterconfig.invalid_legacy_provider"
3333
ErrDisallowedField = "clusterconfig.disallowed_field"
3434
ErrInvalidRegion = "clusterconfig.invalid_region"
35-
ErrNoNodeGroupSpecified = "clusterconfig.no_nodegroup_specified"
3635
ErrNodeGroupMaxInstancesIsZero = "clusterconfig.node_group_max_instances_is_zero"
3736
ErrMaxNumOfNodeGroupsReached = "clusterconfig.max_num_of_nodegroups_reached"
3837
ErrDuplicateNodeGroupName = "clusterconfig.duplicate_nodegroup_name"
@@ -105,13 +104,6 @@ func ErrorInvalidRegion(region string) error {
105104
})
106105
}
107106

108-
func ErrorNoNodeGroupSpecified() error {
109-
return errors.WithStack(&errors.Error{
110-
Kind: ErrNoNodeGroupSpecified,
111-
Message: "no nodegroup was specified; please specify at least 1 nodegroup",
112-
})
113-
}
114-
115107
func ErrorNodeGroupMaxInstancesIsZero() error {
116108
return errors.WithStack(&errors.Error{
117109
Kind: ErrNodeGroupMaxInstancesIsZero,

0 commit comments

Comments
 (0)