Unverified Commit 3ccb63bb authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #78385 from thz/externalNameTrailingDot

Allow trailing dot for service.spec.externalName
parents 4fed7530 8829efae
...@@ -3692,8 +3692,11 @@ func ValidateService(service *core.Service) field.ErrorList { ...@@ -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"), ""))
} }
......
...@@ -9307,6 +9307,15 @@ func TestValidateService(t *testing.T) { ...@@ -9307,6 +9307,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) {
s.Spec.Type = core.ServiceTypeExternalName s.Spec.Type = core.ServiceTypeExternalName
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment