Merge pull request #78385 from thz/externalNameTrailingDot

Allow trailing dot for service.spec.externalName
This commit is contained in:
Kubernetes Prow Robot 2019-05-28 15:53:49 -07:00 committed by GitHub
commit 3ccb63bb1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -3692,8 +3692,11 @@ func ValidateService(service *core.Service) field.ErrorList {
if service.Spec.ClusterIP != "" { if service.Spec.ClusterIP != "" {
allErrs = append(allErrs, field.Forbidden(specPath.Child("clusterIP"), "must be empty for ExternalName services")) allErrs = append(allErrs, field.Forbidden(specPath.Child("clusterIP"), "must be empty for ExternalName services"))
} }
if len(service.Spec.ExternalName) > 0 {
allErrs = append(allErrs, ValidateDNS1123Subdomain(service.Spec.ExternalName, specPath.Child("externalName"))...) // The value (a CNAME) may have a trailing dot to denote it as fully qualified
cname := strings.TrimSuffix(service.Spec.ExternalName, ".")
if len(cname) > 0 {
allErrs = append(allErrs, ValidateDNS1123Subdomain(cname, specPath.Child("externalName"))...)
} else { } else {
allErrs = append(allErrs, field.Required(specPath.Child("externalName"), "")) allErrs = append(allErrs, field.Required(specPath.Child("externalName"), ""))
} }

View File

@ -9306,6 +9306,15 @@ func TestValidateService(t *testing.T) {
}, },
numErrs: 0, numErrs: 0,
}, },
{
name: "valid ExternalName (trailing dot)",
tweakSvc: func(s *core.Service) {
s.Spec.Type = core.ServiceTypeExternalName
s.Spec.ClusterIP = ""
s.Spec.ExternalName = "foo.bar.example.com."
},
numErrs: 0,
},
{ {
name: "invalid ExternalName clusterIP (valid IP)", name: "invalid ExternalName clusterIP (valid IP)",
tweakSvc: func(s *core.Service) { tweakSvc: func(s *core.Service) {