Skip to content

Support clusters with no node groups #2269

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 4 commits into from
Jun 21, 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
2 changes: 1 addition & 1 deletion pkg/lib/configreader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type StructListValidation struct {
StructValidation *StructValidation
Required bool
AllowExplicitNull bool
TreatNullAsEmpty bool // If explicit null or if it's top level and the file is empty, treat as empty map
TreatNullAsEmpty bool // If explicit null or if it's top level and the file is empty, treat as empty list
MinLength int
MaxLength int
InvalidLengths []int
Expand Down
8 changes: 8 additions & 0 deletions pkg/operator/resources/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
ErrRealtimeAPIUsedByTrafficSplitter = "resources.realtime_api_used_by_traffic_splitter"
ErrAPIsNotDeployed = "resources.apis_not_deployed"
ErrInvalidNodeGroupSelector = "resources.invalid_node_group_selector"
ErrNoNodeGroups = "resources.no_node_groups"
)

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

func ErrorNoNodeGroups() error {
return errors.WithStack(&errors.Error{
Kind: ErrNoNodeGroups,
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`"),
})
}

func podResourceRequestsTable(api *userconfig.API, compute userconfig.Compute) string {
sidecarCPUNote := ""
sidecarMemNote := ""
Expand Down
4 changes: 4 additions & 0 deletions pkg/operator/resources/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func ValidateClusterAPIs(apis []userconfig.API) error {
return spec.ErrorNoAPIs()
}

if len(config.ClusterConfig.NodeGroups) == 0 {
return ErrorNoNodeGroups()
}

virtualServices, err := config.K8s.ListVirtualServices(nil)
if err != nil {
return err
Expand Down
40 changes: 23 additions & 17 deletions pkg/types/clusterconfig/availability_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ func (cc *Config) setDefaultAvailabilityZones(awsClient *aws.Client) error {
}
instanceTypesSlice := instanceTypes.Slice()

zones, err := awsClient.ListSupportedAvailabilityZones(instanceTypesSlice[0], instanceTypesSlice[1:]...)
if err != nil {
// Try again without checking instance types
var zones strset.Set
var err error
if len(instanceTypesSlice) > 0 {
zones, err = awsClient.ListSupportedAvailabilityZones(instanceTypesSlice[0], instanceTypesSlice[1:]...)
}
if len(zones) == 0 || err != nil {
// Try without checking instance types
zones, err = awsClient.ListAvailabilityZonesInRegion()
if err != nil {
return nil // Let eksctl choose the availability zones
Expand All @@ -75,12 +79,6 @@ func (cc *Config) setDefaultAvailabilityZones(awsClient *aws.Client) error {
}

func (cc *Config) validateUserAvailabilityZones(awsClient *aws.Client) error {
instanceTypes := strset.New()
for _, ng := range cc.NodeGroups {
instanceTypes.Add(ng.InstanceType)
}
instanceTypesSlice := instanceTypes.Slice()

allZones, err := awsClient.ListAvailabilityZonesInRegion()
if err != nil {
return nil // Skip validation
Expand All @@ -92,15 +90,23 @@ func (cc *Config) validateUserAvailabilityZones(awsClient *aws.Client) error {
}
}

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

for _, userZone := range cc.AvailabilityZones {
if !supportedZones.Has(userZone) {
return ErrorUnsupportedAvailabilityZone(userZone, instanceTypesSlice[0], instanceTypesSlice[1:]...)
supportedZones, err := awsClient.ListSupportedAvailabilityZones(instanceTypesSlice[0], instanceTypesSlice[1:]...)
if err != nil {
// Skip validation instance-based validation
supportedZones = strset.Difference(allZones, _azBlacklist)
}

for _, userZone := range cc.AvailabilityZones {
if !supportedZones.Has(userZone) {
return ErrorUnsupportedAvailabilityZone(userZone, instanceTypesSlice[0], instanceTypesSlice[1:]...)
}
}
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/types/clusterconfig/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,9 @@ var ManagedConfigStructFieldValidations = []*cr.StructFieldValidation{
{
StructField: "NodeGroups",
StructListValidation: &cr.StructListValidation{
Required: true,
StructValidation: nodeGroupsFieldValidation,
AllowExplicitNull: true,
TreatNullAsEmpty: true,
StructValidation: nodeGroupsFieldValidation,
},
},
{
Expand Down Expand Up @@ -890,9 +891,6 @@ func (cc *CoreConfig) SQSNamePrefix() string {

func (cc *Config) validate(awsClient *aws.Client) error {
numNodeGroups := len(cc.NodeGroups)
if numNodeGroups == 0 {
return ErrorNoNodeGroupSpecified()
}
if numNodeGroups > MaxNodePoolsOrGroups {
return ErrorMaxNumOfNodeGroupsReached(MaxNodePoolsOrGroups)
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/types/clusterconfig/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const (
ErrInvalidLegacyProvider = "clusterconfig.invalid_legacy_provider"
ErrDisallowedField = "clusterconfig.disallowed_field"
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"
Expand Down Expand Up @@ -105,13 +104,6 @@ func ErrorInvalidRegion(region string) error {
})
}

func ErrorNoNodeGroupSpecified() error {
return errors.WithStack(&errors.Error{
Kind: ErrNoNodeGroupSpecified,
Message: "no nodegroup was specified; please specify at least 1 nodegroup",
})
}

func ErrorNodeGroupMaxInstancesIsZero() error {
return errors.WithStack(&errors.Error{
Kind: ErrNodeGroupMaxInstancesIsZero,
Expand Down