Move default to avoid nil check

Signed-off-by: Simon Croome <simon.croome@storageos.com>
pull/9416/head
Simon Croome 4 years ago
parent ba325bdf7e
commit 54de1c1f25
No known key found for this signature in database
GPG Key ID: AD35B1845B04F4B6

@ -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
}
}

Loading…
Cancel
Save