Allow trailing dot for service.spec.externalName

parent da31c50d
......@@ -3692,8 +3692,11 @@ func ValidateService(service *core.Service) field.ErrorList {
if service.Spec.ClusterIP != "" {
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 {
allErrs = append(allErrs, field.Required(specPath.Child("externalName"), ""))
}
......
......@@ -9307,6 +9307,15 @@ func TestValidateService(t *testing.T) {
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)",
tweakSvc: func(s *core.Service) {
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