From 9b7322861d651ea5be5b42df6cb84fa934d5d428 Mon Sep 17 00:00:00 2001 From: Simon Croome Date: Mon, 22 Mar 2021 15:55:23 +0000 Subject: [PATCH] Move default to avoid nil check Signed-off-by: Simon Croome (cherry picked from commit 54de1c1f2549fb84db7f021c08cad6acd80ce7da) --- pkg/lint/rules/template.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/lint/rules/template.go b/pkg/lint/rules/template.go index 2addad122..826a31bfa 100644 --- a/pkg/lint/rules/template.go +++ b/pkg/lint/rules/template.go @@ -210,10 +210,6 @@ func validateYamlContent(err error) error { // DNS (RFC 1123), used by most resources. func validateMetadataName(obj *K8sYamlStruct) error { fn := validateMetadataNameFunc(obj) - if fn == nil { - fn = validation.NameIsDNSSubdomain - } - allErrs := field.ErrorList{} for _, msg := range fn(obj.Metadata.Name, false) { allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("name"), obj.Metadata.Name, msg)) @@ -234,7 +230,9 @@ func validateMetadataName(obj *K8sYamlStruct) error { // // Implementing here to avoid importing k/k. // -// If no mapping is defined, returns nil. +// If no mapping is defined, returns NameIsDNSSubdomain. This is used by object +// kinds that don't have special requirements, so is the most likely to work if +// new kinds are added. func validateMetadataNameFunc(obj *K8sYamlStruct) validation.ValidateNameFunc { switch strings.ToLower(obj.Kind) { case "pod", "node", "secret", "endpoints", "resourcequota", // core @@ -265,7 +263,7 @@ func validateMetadataNameFunc(obj *K8sYamlStruct) validation.ValidateNameFunc { return apipath.IsValidPathSegmentName(name) } default: - return nil + return validation.NameIsDNSSubdomain } }