From b22801211428a471b33c4b1f49dd356e1c5c8e1f Mon Sep 17 00:00:00 2001 From: Ole Markus With Date: Thu, 9 Jul 2020 09:32:07 +0200 Subject: [PATCH 1/3] Validate cloud labels Since moving to LaunchTemplates, cloudLabels cannot have empty values anymore. If one tries to, kops will just loop endlessly with AWS errors when trying to create the launch template --- pkg/apis/kops/validation/instancegroup.go | 15 +++++++++++++++ pkg/apis/kops/validation/instancegroup_test.go | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/pkg/apis/kops/validation/instancegroup.go b/pkg/apis/kops/validation/instancegroup.go index 82b2bbaccdb46..0b045d81bd266 100644 --- a/pkg/apis/kops/validation/instancegroup.go +++ b/pkg/apis/kops/validation/instancegroup.go @@ -119,6 +119,8 @@ func ValidateInstanceGroup(g *kops.InstanceGroup, cloud fi.Cloud) field.ErrorLis allErrs = append(allErrs, awsValidateInstanceGroup(g, cloud.(awsup.AWSCloud))...) } + allErrs = append(allErrs, validateCloudLabels(g.Spec.CloudLabels, field.NewPath("spec", "cloudLabels"))...) + return allErrs } @@ -244,3 +246,16 @@ func validateInstanceProfile(v *kops.IAMProfileSpec, fldPath *field.Path) field. } return allErrs } + +func validateCloudLabels(labels map[string]string, fldPath *field.Path) field.ErrorList { + allErrs := field.ErrorList{} + for tag, val := range labels { + if tag == "" { + allErrs = append(allErrs, field.Invalid(fldPath, tag, "cloud labels cannot be cannot be empty strings")) + } + if val == "" { + allErrs = append(allErrs, field.Invalid(fldPath.Child(tag), val, "cloud labels cannot have empty values")) + } + } + return allErrs +} diff --git a/pkg/apis/kops/validation/instancegroup_test.go b/pkg/apis/kops/validation/instancegroup_test.go index c6eadf92568c7..d3c2c9dff3fa2 100644 --- a/pkg/apis/kops/validation/instancegroup_test.go +++ b/pkg/apis/kops/validation/instancegroup_test.go @@ -221,3 +221,19 @@ func TestValidBootDevice(t *testing.T) { testErrors(t, g.volumeType, errs, g.expected) } } + +func TestValidateCloudLabels(t *testing.T) { + labels := map[string]string{ + "nonEmptyLabel": "value", + "emptyValue": "", + "": "emptyTag", + } + + expected := []string{ + "Invalid value::spec.cloudLabels.emptyValue", + "Invalid value::spec.cloudLabels", + } + errs := validateCloudLabels(labels, field.NewPath("spec", "cloudLabels")) + testErrors(t, "cloudLabels", errs, expected) + +} From 35aec8de2a8ed383425bf854cc4bc31d386a1fb3 Mon Sep 17 00:00:00 2001 From: Ole Markus With Date: Thu, 9 Jul 2020 14:27:08 +0200 Subject: [PATCH 2/3] Add breaking change to release notes --- docs/releases/1.19-NOTES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/releases/1.19-NOTES.md b/docs/releases/1.19-NOTES.md index 62d6ebf652232..abe3587dd4a6e 100644 --- a/docs/releases/1.19-NOTES.md +++ b/docs/releases/1.19-NOTES.md @@ -4,7 +4,7 @@ # Significant changes -* On AWS kops now defaults to using launch templates instead of launch configurations. +* On AWS kops now defaults to using launch templates instead of launch configurations. See "Breaking changes" below. * Clusters using the Amazon VPC CNI provider now perform an `ec2.DescribeInstanceTypes` call at instance launch time. In large clusters or AWS accounts this may lead to API throttling which could delay node readiness. If this becomes a problem please open a GitHub issue. @@ -18,6 +18,8 @@ * Support for the Romana networking provider has been removed. +* Launch templates do not support empty tag keys or values. Ensure that all keys specified in `spec.cloudLabels` in any instance group are non-empty values. + # Required Actions # Deprecations From 0ac26e5ef17a59fdb7947b6532671fb768e18ceb Mon Sep 17 00:00:00 2001 From: Ole Markus With Date: Thu, 9 Jul 2020 15:54:35 +0200 Subject: [PATCH 3/3] Update pkg/apis/kops/validation/instancegroup.go Co-authored-by: Peter Rifel --- pkg/apis/kops/validation/instancegroup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/kops/validation/instancegroup.go b/pkg/apis/kops/validation/instancegroup.go index 0b045d81bd266..b65c6e54a201a 100644 --- a/pkg/apis/kops/validation/instancegroup.go +++ b/pkg/apis/kops/validation/instancegroup.go @@ -251,7 +251,7 @@ func validateCloudLabels(labels map[string]string, fldPath *field.Path) field.Er allErrs := field.ErrorList{} for tag, val := range labels { if tag == "" { - allErrs = append(allErrs, field.Invalid(fldPath, tag, "cloud labels cannot be cannot be empty strings")) + allErrs = append(allErrs, field.Invalid(fldPath, tag, "cloud labels cannot be empty strings")) } if val == "" { allErrs = append(allErrs, field.Invalid(fldPath.Child(tag), val, "cloud labels cannot have empty values"))