Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
Add validations to make kube-node-label.service not to fail at run time
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Feb 16, 2017
1 parent 7b008bc commit a61aff3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/controlplane/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,15 @@ func (c Cluster) valid() error {
return fmt.Errorf("selected worker tenancy (%s) is incompatible with spot instances", c.WorkerTenancy)
}

clusterNamePlaceholder := "<my-cluster-name>"
nestedStackNamePlaceHolder := "<my-nested-stack-name>"
replacer := strings.NewReplacer(clusterNamePlaceholder, "", nestedStackNamePlaceHolder, "")
simulatedLcName := fmt.Sprintf("%s-%s-1N2C4K3LLBEDZ-%sLC-BC2S9P3JG2QD", clusterNamePlaceholder, nestedStackNamePlaceHolder, c.Controller.LogicalName())
limit := 63 - len(replacer.Replace(simulatedLcName))
if c.Experimental.AwsNodeLabels.Enabled && len(c.ClusterName) > limit {
return fmt.Errorf("awsNodeLabels can't be enabled for controllers because the total number of characters in clusterName(=\"%s\") exceeds the limit of %d", c.ClusterName, limit)
}

return nil
}

Expand Down
9 changes: 9 additions & 0 deletions core/nodepool/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ func (c ProvidedConfig) valid() error {
return err
}

clusterNamePlaceholder := "<my-cluster-name>"
nestedStackNamePlaceHolder := "<my-nested-stack-name>"
replacer := strings.NewReplacer(clusterNamePlaceholder, "", nestedStackNamePlaceHolder, "")
simulatedLcName := fmt.Sprintf("%s-%s-1N2C4K3LLBEDZ-%sLC-BC2S9P3JG2QD", clusterNamePlaceholder, nestedStackNamePlaceHolder, c.LogicalName())
limit := 63 - len(replacer.Replace(simulatedLcName))
if c.Experimental.AwsNodeLabels.Enabled && len(c.ClusterName+c.NodePoolName) > limit {
return fmt.Errorf("awsNodeLabels can't be enabled for node pool because the total number of characters in clusterName(=\"%s\") + node pool's name(=\"%s\") exceeds the limit of %d", c.ClusterName, c.NodePoolName, limit)
}

return nil
}

Expand Down
28 changes: 28 additions & 0 deletions test/integration/maincluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,34 @@ worker:
`,
expectedErrorMessage: "Effect must be NoSchdule or PreferNoSchedule, but was UnknownEffect",
},
{
context: "WithAwsNodeLabelEnabledForTooLongClusterNameAndPoolName",
configYaml: minimalValidConfigYaml + `
# clusterName + nodePools[].name should be less than or equal to 25 characters or the launch configuration name
# "mykubeawsclustername-mynestedstackname-1N2C4K3LLBEDZ-ControllersLC-BC2S9P3JG2QD" exceeds the limit of 63 characters
# See https://kubernetes.io/docs/user-guide/labels/#syntax-and-character-set
clusterName: my_cluster1 # 11 characters
worker:
nodePools:
- name: workernodepool1 # 15 characters
awsNodeLabels:
enabled: true
`,
expectedErrorMessage: "awsNodeLabels can't be enabled for node pool because the total number of characters in clusterName(=\"my_cluster1\") + node pool's name(=\"workernodepool1\") exceeds the limit of 25",
},
{
context: "WithAwsNodeLabelEnabledForTooLongClusterName",
configYaml: minimalValidConfigYaml + `
# clusterName should be less than or equal to 21 characters or the launch configuration name
# "mykubeawsclustername-mynestedstackname-1N2C4K3LLBEDZ-ControllersLC-BC2S9P3JG2QD" exceeds the limit of 63 characters
# See https://kubernetes.io/docs/user-guide/labels/#syntax-and-character-set
clusterName: my_long_long_cluster_1 # 22 characters
experimental:
awsNodeLabels:
enabled: true
`,
expectedErrorMessage: "awsNodeLabels can't be enabled for controllers because the total number of characters in clusterName(=\"my_long_long_cluster_1\") exceeds the limit of 21",
},
{
context: "WithNonZeroWorkerCount",
configYaml: minimalValidConfigYaml + `
Expand Down

0 comments on commit a61aff3

Please sign in to comment.