Skip to content
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

Validate cloud labels #9536

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 3 additions & 1 deletion docs/releases/1.19-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/kops/validation/instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 empty strings"))
}
if val == "" {
allErrs = append(allErrs, field.Invalid(fldPath.Child(tag), val, "cloud labels cannot have empty values"))
}
}
return allErrs
}
16 changes: 16 additions & 0 deletions pkg/apis/kops/validation/instancegroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
olemarkus marked this conversation as resolved.
Show resolved Hide resolved

expected := []string{
"Invalid value::spec.cloudLabels.emptyValue",
"Invalid value::spec.cloudLabels",
}
errs := validateCloudLabels(labels, field.NewPath("spec", "cloudLabels"))
testErrors(t, "cloudLabels", errs, expected)

}