Merge pull request #8140 from vishh/namespace
Update Namespace names to follow DNS label format
This commit is contained in:
@@ -129,7 +129,7 @@ func ValidateNodeName(name string, prefix bool) (bool, string) {
|
||||
// Prefix indicates this name will be used as part of generation, in which case
|
||||
// trailing dashes are allowed.
|
||||
func ValidateNamespaceName(name string, prefix bool) (bool, string) {
|
||||
return nameIsDNSSubdomain(name, prefix)
|
||||
return nameIsDNSLabel(name, prefix)
|
||||
}
|
||||
|
||||
// ValidateLimitRangeName can be used to check whether the given limit range name is valid.
|
||||
@@ -179,6 +179,17 @@ func nameIsDNSSubdomain(name string, prefix bool) (bool, string) {
|
||||
return false, dnsSubdomainErrorMsg
|
||||
}
|
||||
|
||||
// nameIsDNSLabel is a ValidateNameFunc for names that must be a DNS 1123 label.
|
||||
func nameIsDNSLabel(name string, prefix bool) (bool, string) {
|
||||
if prefix {
|
||||
name = maskTrailingDash(name)
|
||||
}
|
||||
if util.IsDNS1123Label(name) {
|
||||
return true, ""
|
||||
}
|
||||
return false, dns1123LabelErrorMsg
|
||||
}
|
||||
|
||||
// nameIsDNS952Label is a ValidateNameFunc for names that must be a DNS 952 label.
|
||||
func nameIsDNS952Label(name string, prefix bool) (bool, string) {
|
||||
if prefix {
|
||||
@@ -213,8 +224,8 @@ func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn Val
|
||||
if requiresNamespace {
|
||||
if len(meta.Namespace) == 0 {
|
||||
allErrs = append(allErrs, errs.NewFieldRequired("namespace"))
|
||||
} else if !util.IsDNS1123Subdomain(meta.Namespace) {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", meta.Namespace, dnsSubdomainErrorMsg))
|
||||
} else if ok, _ := ValidateNamespaceName(meta.Namespace, false); !ok {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", meta.Namespace, dns1123LabelErrorMsg))
|
||||
}
|
||||
} else {
|
||||
if len(meta.Namespace) != 0 {
|
||||
|
Reference in New Issue
Block a user