From 68beadefe414e28a9cd42bf5cfd45c9f135437d1 Mon Sep 17 00:00:00 2001 From: zhouhaibing089 Date: Wed, 27 Feb 2019 14:16:54 -0800 Subject: [PATCH] validation: allow trailing period in dns search The trailing period tells the resolver to stop immediately instead of trying recursively. With that said, trailing period should be acceptable in searches. --- pkg/apis/core/validation/validation.go | 4 ++++ pkg/apis/core/validation/validation_test.go | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/apis/core/validation/validation.go b/pkg/apis/core/validation/validation.go index f7ba935ff8e..821341f5f03 100644 --- a/pkg/apis/core/validation/validation.go +++ b/pkg/apis/core/validation/validation.go @@ -2695,6 +2695,10 @@ func validatePodDNSConfig(dnsConfig *core.PodDNSConfig, dnsPolicy *core.DNSPolic allErrs = append(allErrs, field.Invalid(fldPath.Child("searches"), dnsConfig.Searches, "must not have more than 256 characters (including spaces) in the search list")) } for i, search := range dnsConfig.Searches { + // it is fine to have a trailing dot + if strings.HasSuffix(search, ".") { + search = search[0 : len(search)-1] + } allErrs = append(allErrs, ValidateDNS1123Subdomain(search, fldPath.Child("searches").Index(i))...) } // Validate options. diff --git a/pkg/apis/core/validation/validation_test.go b/pkg/apis/core/validation/validation_test.go index 45ec2c359c1..271dcfbd5ef 100644 --- a/pkg/apis/core/validation/validation_test.go +++ b/pkg/apis/core/validation/validation_test.go @@ -5873,11 +5873,18 @@ func TestValidatePodDNSConfig(t *testing.T) { }, expectedError: false, }, + { + desc: "valid: 1 search path with trailing period", + dnsConfig: &core.PodDNSConfig{ + Searches: []string{"custom."}, + }, + expectedError: false, + }, { desc: "valid: 3 nameservers and 6 search paths", dnsConfig: &core.PodDNSConfig{ Nameservers: []string{"127.0.0.1", "10.0.0.10", "8.8.8.8"}, - Searches: []string{"custom", "mydomain.com", "local", "cluster.local", "svc.cluster.local", "default.svc.cluster.local"}, + Searches: []string{"custom", "mydomain.com", "local", "cluster.local", "svc.cluster.local", "default.svc.cluster.local."}, }, expectedError: false, },