From a61aff309a959055f29a74348e08f4c45e198b4d Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Thu, 16 Feb 2017 13:30:55 +0900 Subject: [PATCH] Add validations to make kube-node-label.service not to fail at run time --- core/controlplane/config/config.go | 9 +++++++++ core/nodepool/config/config.go | 9 +++++++++ test/integration/maincluster_test.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/core/controlplane/config/config.go b/core/controlplane/config/config.go index 9eb9e4408..4fb8bb84c 100644 --- a/core/controlplane/config/config.go +++ b/core/controlplane/config/config.go @@ -848,6 +848,15 @@ func (c Cluster) valid() error { return fmt.Errorf("selected worker tenancy (%s) is incompatible with spot instances", c.WorkerTenancy) } + clusterNamePlaceholder := "" + nestedStackNamePlaceHolder := "" + 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 } diff --git a/core/nodepool/config/config.go b/core/nodepool/config/config.go index a28fc0f17..1bf930bb0 100644 --- a/core/nodepool/config/config.go +++ b/core/nodepool/config/config.go @@ -253,6 +253,15 @@ func (c ProvidedConfig) valid() error { return err } + clusterNamePlaceholder := "" + nestedStackNamePlaceHolder := "" + 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 } diff --git a/test/integration/maincluster_test.go b/test/integration/maincluster_test.go index 8dcb88eda..fd1f112e0 100644 --- a/test/integration/maincluster_test.go +++ b/test/integration/maincluster_test.go @@ -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 + `