mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Merge pull request #78385 from thz/externalNameTrailingDot
Allow trailing dot for service.spec.externalName
This commit is contained in:
commit
3ccb63bb1b
@ -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"), ""))
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user