From b249b4ca9bbc48b58a690fe61a7a2a9e457a8435 Mon Sep 17 00:00:00 2001 From: Gunju Kim Date: Sun, 19 Mar 2023 19:25:23 +0900 Subject: [PATCH] Promote ExpandedDNSConfig feature to the GA stage --- pkg/api/pod/util.go | 35 +- pkg/api/pod/util_test.go | 359 -------------------- pkg/apis/core/validation/validation.go | 24 +- pkg/apis/core/validation/validation_test.go | 18 +- pkg/features/kube_features.go | 3 +- pkg/kubelet/network/dns/dns.go | 12 +- pkg/kubelet/network/dns/dns_test.go | 93 ++--- 7 files changed, 42 insertions(+), 502 deletions(-) diff --git a/pkg/api/pod/util.go b/pkg/api/pod/util.go index 7370a7b13fd..b063a21e135 100644 --- a/pkg/api/pod/util.go +++ b/pkg/api/pod/util.go @@ -342,37 +342,6 @@ func usesIndivisibleHugePagesValues(podSpec *api.PodSpec) bool { return false } -// haveSameExpandedDNSConfig returns true if the oldPodSpec already had -// ExpandedDNSConfig and podSpec has the same DNSConfig -func haveSameExpandedDNSConfig(podSpec, oldPodSpec *api.PodSpec) bool { - if oldPodSpec == nil || oldPodSpec.DNSConfig == nil { - return false - } - if podSpec == nil || podSpec.DNSConfig == nil { - return false - } - - if len(oldPodSpec.DNSConfig.Searches) <= apivalidation.MaxDNSSearchPathsLegacy && - len(strings.Join(oldPodSpec.DNSConfig.Searches, " ")) <= apivalidation.MaxDNSSearchListCharsLegacy { - // didn't have ExpandedDNSConfig - return false - } - - if len(oldPodSpec.DNSConfig.Searches) != len(podSpec.DNSConfig.Searches) { - // updates DNSConfig - return false - } - - for i, oldSearch := range oldPodSpec.DNSConfig.Searches { - if podSpec.DNSConfig.Searches[i] != oldSearch { - // updates DNSConfig - return false - } - } - - return true -} - // hasInvalidTopologySpreadConstraintLabelSelector return true if spec.TopologySpreadConstraints have any entry with invalid labelSelector func hasInvalidTopologySpreadConstraintLabelSelector(spec *api.PodSpec) bool { for _, constraint := range spec.TopologySpreadConstraints { @@ -390,9 +359,7 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po opts := apivalidation.PodValidationOptions{ AllowInvalidPodDeletionCost: !utilfeature.DefaultFeatureGate.Enabled(features.PodDeletionCost), // Do not allow pod spec to use non-integer multiple of huge page unit size default - AllowIndivisibleHugePagesValues: false, - // Allow pod spec with expanded DNS configuration - AllowExpandedDNSConfig: utilfeature.DefaultFeatureGate.Enabled(features.ExpandedDNSConfig) || haveSameExpandedDNSConfig(podSpec, oldPodSpec), + AllowIndivisibleHugePagesValues: false, AllowInvalidLabelValueInSelector: false, AllowInvalidTopologySpreadConstraintLabelSelector: false, AllowMutableNodeSelectorAndNodeAffinity: utilfeature.DefaultFeatureGate.Enabled(features.PodSchedulingReadiness), diff --git a/pkg/api/pod/util_test.go b/pkg/api/pod/util_test.go index f63802c5717..f399eab4285 100644 --- a/pkg/api/pod/util_test.go +++ b/pkg/api/pod/util_test.go @@ -1094,365 +1094,6 @@ func TestValidatePodDeletionCostOption(t *testing.T) { } } -func TestHaveSameExpandedDNSConfig(t *testing.T) { - testCases := []struct { - desc string - podSpec *api.PodSpec - oldPodSpec *api.PodSpec - want bool - }{ - { - desc: "nil DNSConfig", - podSpec: &api.PodSpec{}, - oldPodSpec: &api.PodSpec{}, - want: false, - }, - { - desc: "empty DNSConfig", - podSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{}, - }, - oldPodSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{}, - }, - want: false, - }, - { - desc: "same legacy DNSConfig", - podSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "3.com", - "4.com", - "5.com", - "6.com", - }, - }, - }, - oldPodSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "3.com", - "4.com", - "5.com", - "6.com", - }, - }, - }, - want: false, - }, - { - desc: "update legacy DNSConfig", - podSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "baz.com", - "4.com", - "5.com", - "6.com", - }, - }, - }, - oldPodSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "3.com", - "4.com", - "5.com", - "6.com", - }, - }, - }, - want: false, - }, - { - desc: "same expanded DNSConfig", - podSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "3.com", - "4.com", - "5.com", - "6.com", - "7.expanded.com", - "8.expanded.com", - "9.expanded.com", - "10.expanded.com", - "11.expanded.com", - "12.expanded.com", - "13.expanded.com", - "14.expanded.com", - "15.expanded.com", - "16.expanded.com", - "17.expanded.com", - "18.expanded.com", - "19.expanded.com", - "20.expanded.com", - "21.expanded.com", - "22.expanded.com", - "23.expanded.com", - "24.expanded.com", - "25.expanded.com", - "26.expanded.com", - "27.expanded.com", - "28.expanded.com", - "29.expanded.com", - "30.expanded.com", - "31.expanded.com", - "32.expanded.com", - }, - }, - }, - oldPodSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "3.com", - "4.com", - "5.com", - "6.com", - "7.expanded.com", - "8.expanded.com", - "9.expanded.com", - "10.expanded.com", - "11.expanded.com", - "12.expanded.com", - "13.expanded.com", - "14.expanded.com", - "15.expanded.com", - "16.expanded.com", - "17.expanded.com", - "18.expanded.com", - "19.expanded.com", - "20.expanded.com", - "21.expanded.com", - "22.expanded.com", - "23.expanded.com", - "24.expanded.com", - "25.expanded.com", - "26.expanded.com", - "27.expanded.com", - "28.expanded.com", - "29.expanded.com", - "30.expanded.com", - "31.expanded.com", - "32.expanded.com", - }, - }, - }, - want: true, - }, - { - desc: "update expanded DNSConfig", - podSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "3.com", - "4.com", - "5.com", - "6.com", - "baz.expanded.com", - "8.expanded.com", - "9.expanded.com", - "10.expanded.com", - "11.expanded.com", - "12.expanded.com", - "13.expanded.com", - "14.expanded.com", - "15.expanded.com", - "16.expanded.com", - "17.expanded.com", - "18.expanded.com", - "19.expanded.com", - "20.expanded.com", - "21.expanded.com", - "22.expanded.com", - "23.expanded.com", - "24.expanded.com", - "25.expanded.com", - "26.expanded.com", - "27.expanded.com", - "28.expanded.com", - "29.expanded.com", - "30.expanded.com", - "31.expanded.com", - "32.expanded.com", - }, - }, - }, - oldPodSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "3.com", - "4.com", - "5.com", - "6.com", - "7.expanded.com", - "8.expanded.com", - "9.expanded.com", - "10.expanded.com", - "11.expanded.com", - "12.expanded.com", - "13.expanded.com", - "14.expanded.com", - "15.expanded.com", - "16.expanded.com", - "17.expanded.com", - "18.expanded.com", - "19.expanded.com", - "20.expanded.com", - "21.expanded.com", - "22.expanded.com", - "23.expanded.com", - "24.expanded.com", - "25.expanded.com", - "26.expanded.com", - "27.expanded.com", - "28.expanded.com", - "29.expanded.com", - "30.expanded.com", - "31.expanded.com", - "32.expanded.com", - }, - }, - }, - want: false, - }, - { - desc: "update to legacy DNSConfig", - podSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "baz.com", - "4.com", - "5.com", - "6.com", - }, - }, - }, - oldPodSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "3.com", - "4.com", - "5.com", - "6.com", - "7.expanded.com", - "8.expanded.com", - "9.expanded.com", - "10.expanded.com", - "11.expanded.com", - "12.expanded.com", - "13.expanded.com", - "14.expanded.com", - "15.expanded.com", - "16.expanded.com", - "17.expanded.com", - "18.expanded.com", - "19.expanded.com", - "20.expanded.com", - "21.expanded.com", - "22.expanded.com", - "23.expanded.com", - "24.expanded.com", - "25.expanded.com", - "26.expanded.com", - "27.expanded.com", - "28.expanded.com", - "29.expanded.com", - "30.expanded.com", - "31.expanded.com", - "32.expanded.com", - }, - }, - }, - want: false, - }, - { - desc: "update to expanded DNSConfig", - podSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "3.com", - "4.com", - "5.com", - "6.com", - "baz.expanded.com", - "8.expanded.com", - "9.expanded.com", - "10.expanded.com", - "11.expanded.com", - "12.expanded.com", - "13.expanded.com", - "14.expanded.com", - "15.expanded.com", - "16.expanded.com", - "17.expanded.com", - "18.expanded.com", - "19.expanded.com", - "20.expanded.com", - "21.expanded.com", - "22.expanded.com", - "23.expanded.com", - "24.expanded.com", - "25.expanded.com", - "26.expanded.com", - "27.expanded.com", - "28.expanded.com", - "29.expanded.com", - "30.expanded.com", - "31.expanded.com", - "32.expanded.com", - }, - }, - }, - oldPodSpec: &api.PodSpec{ - DNSConfig: &api.PodDNSConfig{ - Searches: []string{ - "foo.com", - "bar.io", - "3.com", - "4.com", - "5.com", - "6.com", - }, - }, - }, - want: false, - }, - } - - for _, tc := range testCases { - t.Run(tc.desc, func(t *testing.T) { - got := haveSameExpandedDNSConfig(tc.podSpec, tc.oldPodSpec) - if tc.want != got { - t.Errorf("unexpected diff, want: %v, got: %v", tc.want, got) - } - }) - } -} - func TestDropDisabledTopologySpreadConstraintsFields(t *testing.T) { testCases := []struct { name string diff --git a/pkg/apis/core/validation/validation.go b/pkg/apis/core/validation/validation.go index bb39e507abb..fe428a3e8b9 100644 --- a/pkg/apis/core/validation/validation.go +++ b/pkg/apis/core/validation/validation.go @@ -3399,14 +3399,10 @@ const ( // restrictions in Linux libc name resolution handling. // Max number of DNS name servers. MaxDNSNameservers = 3 - // Expanded max number of domains in the search path list. - MaxDNSSearchPathsExpanded = 32 - // Expanded max number of characters in the search path. - MaxDNSSearchListCharsExpanded = 2048 // Max number of domains in the search path list. - MaxDNSSearchPathsLegacy = 6 - // Max number of characters in the search path list. - MaxDNSSearchListCharsLegacy = 256 + MaxDNSSearchPaths = 32 + // Max number of characters in the search path. + MaxDNSSearchListChars = 2048 ) func validateReadinessGates(readinessGates []core.PodReadinessGate, fldPath *field.Path) field.ErrorList { @@ -3455,16 +3451,12 @@ func validatePodDNSConfig(dnsConfig *core.PodDNSConfig, dnsPolicy *core.DNSPolic } } // Validate searches. - maxDNSSearchPaths, maxDNSSearchListChars := MaxDNSSearchPathsLegacy, MaxDNSSearchListCharsLegacy - if opts.AllowExpandedDNSConfig { - maxDNSSearchPaths, maxDNSSearchListChars = MaxDNSSearchPathsExpanded, MaxDNSSearchListCharsExpanded - } - if len(dnsConfig.Searches) > maxDNSSearchPaths { - allErrs = append(allErrs, field.Invalid(fldPath.Child("searches"), dnsConfig.Searches, fmt.Sprintf("must not have more than %v search paths", maxDNSSearchPaths))) + if len(dnsConfig.Searches) > MaxDNSSearchPaths { + allErrs = append(allErrs, field.Invalid(fldPath.Child("searches"), dnsConfig.Searches, fmt.Sprintf("must not have more than %v search paths", MaxDNSSearchPaths))) } // Include the space between search paths. - if len(strings.Join(dnsConfig.Searches, " ")) > maxDNSSearchListChars { - allErrs = append(allErrs, field.Invalid(fldPath.Child("searches"), dnsConfig.Searches, fmt.Sprintf("must not have more than %v characters (including spaces) in the search list", maxDNSSearchListChars))) + if len(strings.Join(dnsConfig.Searches, " ")) > MaxDNSSearchListChars { + allErrs = append(allErrs, field.Invalid(fldPath.Child("searches"), dnsConfig.Searches, fmt.Sprintf("must not have more than %v characters (including spaces) in the search list", MaxDNSSearchListChars))) } for i, search := range dnsConfig.Searches { // it is fine to have a trailing dot @@ -3688,8 +3680,6 @@ type PodValidationOptions struct { AllowInvalidLabelValueInSelector bool // Allow pod spec to use non-integer multiple of huge page unit size AllowIndivisibleHugePagesValues bool - // Allow more DNSSearchPaths and longer DNSSearchListChars - AllowExpandedDNSConfig bool // Allow invalid topologySpreadConstraint labelSelector for backward compatibility AllowInvalidTopologySpreadConstraintLabelSelector bool // Allow node selector additions for gated pods. diff --git a/pkg/apis/core/validation/validation_test.go b/pkg/apis/core/validation/validation_test.go index 5caae4e1354..e804092474c 100644 --- a/pkg/apis/core/validation/validation_test.go +++ b/pkg/apis/core/validation/validation_test.go @@ -8353,9 +8353,6 @@ func TestValidatePodDNSConfig(t *testing.T) { 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.", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"}, }, - opts: PodValidationOptions{ - AllowExpandedDNSConfig: true, - }, expectedError: false, }, { desc: "valid: 256 characters in search path list(legacy)", @@ -8410,9 +8407,6 @@ func TestValidatePodDNSConfig(t *testing.T) { generateTestSearchPathFunc(63), }, }, - opts: PodValidationOptions{ - AllowExpandedDNSConfig: true, - }, expectedError: false, }, { desc: "valid: ipv6 nameserver", @@ -8427,22 +8421,18 @@ func TestValidatePodDNSConfig(t *testing.T) { }, expectedError: true, }, { - desc: "invalid: 7 search paths(legacy)", + desc: "valid: 7 search paths", dnsConfig: &core.PodDNSConfig{ Searches: []string{"custom", "mydomain.com", "local", "cluster.local", "svc.cluster.local", "default.svc.cluster.local", "exceeded"}, }, - expectedError: true, }, { desc: "invalid: 33 search paths", dnsConfig: &core.PodDNSConfig{ Searches: []string{"custom", "mydomain.com", "local", "cluster.local", "svc.cluster.local", "default.svc.cluster.local.", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33"}, }, - opts: PodValidationOptions{ - AllowExpandedDNSConfig: true, - }, expectedError: true, }, { - desc: "invalid: 257 characters in search path list", + desc: "valid: 257 characters in search path list", dnsConfig: &core.PodDNSConfig{ // We can have 256 - (6 - 1) = 251 characters in total for 6 search paths. Searches: []string{ @@ -8454,7 +8444,6 @@ func TestValidatePodDNSConfig(t *testing.T) { generateTestSearchPathFunc(50), }, }, - expectedError: true, }, { desc: "invalid: 2049 characters in search path list", dnsConfig: &core.PodDNSConfig{ @@ -8494,9 +8483,6 @@ func TestValidatePodDNSConfig(t *testing.T) { generateTestSearchPathFunc(63), }, }, - opts: PodValidationOptions{ - AllowExpandedDNSConfig: true, - }, expectedError: true, }, { desc: "invalid search path", diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index 98564cc5ede..7a57cddf669 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -278,6 +278,7 @@ const ( // kep: https://kep.k8s.io/2595 // alpha: v1.22 // beta: v1.26 + // GA: v1.28 // // Enables apiserver and kubelet to allow up to 32 DNSSearchPaths and up to 2048 DNSSearchListChars. ExpandedDNSConfig featuregate.Feature = "ExpandedDNSConfig" @@ -933,7 +934,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS ExecProbeTimeout: {Default: true, PreRelease: featuregate.GA}, // lock to default and remove after v1.22 based on KEP #1972 update - ExpandedDNSConfig: {Default: true, PreRelease: featuregate.Beta}, + ExpandedDNSConfig: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.30 ExperimentalHostUserNamespaceDefaultingGate: {Default: false, PreRelease: featuregate.Deprecated, LockToDefault: true}, // remove in 1.30 diff --git a/pkg/kubelet/network/dns/dns.go b/pkg/kubelet/network/dns/dns.go index 0bb5ab1bb48..1ffe9d20f8c 100644 --- a/pkg/kubelet/network/dns/dns.go +++ b/pkg/kubelet/network/dns/dns.go @@ -27,11 +27,9 @@ import ( v1 "k8s.io/api/core/v1" utilerrors "k8s.io/apimachinery/pkg/util/errors" utilvalidation "k8s.io/apimachinery/pkg/util/validation" - utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/client-go/tools/record" runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" "k8s.io/kubernetes/pkg/apis/core/validation" - "k8s.io/kubernetes/pkg/features" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" "k8s.io/kubernetes/pkg/kubelet/util/format" @@ -103,10 +101,7 @@ func omitDuplicates(strs []string) []string { func (c *Configurer) formDNSSearchFitsLimits(composedSearch []string, pod *v1.Pod) []string { limitsExceeded := false - maxDNSSearchPaths, maxDNSSearchListChars := validation.MaxDNSSearchPathsLegacy, validation.MaxDNSSearchListCharsLegacy - if utilfeature.DefaultFeatureGate.Enabled(features.ExpandedDNSConfig) { - maxDNSSearchPaths, maxDNSSearchListChars = validation.MaxDNSSearchPathsExpanded, validation.MaxDNSSearchListCharsExpanded - } + maxDNSSearchPaths, maxDNSSearchListChars := validation.MaxDNSSearchPaths, validation.MaxDNSSearchListChars if len(composedSearch) > maxDNSSearchPaths { composedSearch = composedSearch[:maxDNSSearchPaths] @@ -195,10 +190,7 @@ func (c *Configurer) CheckLimitsForResolvConf() { return } - domainCountLimit, maxDNSSearchListChars := validation.MaxDNSSearchPathsLegacy, validation.MaxDNSSearchListCharsLegacy - if utilfeature.DefaultFeatureGate.Enabled(features.ExpandedDNSConfig) { - domainCountLimit, maxDNSSearchListChars = validation.MaxDNSSearchPathsExpanded, validation.MaxDNSSearchListCharsExpanded - } + domainCountLimit, maxDNSSearchListChars := validation.MaxDNSSearchPaths, validation.MaxDNSSearchListChars if c.ClusterDomain != "" { domainCountLimit -= 3 diff --git a/pkg/kubelet/network/dns/dns_test.go b/pkg/kubelet/network/dns/dns_test.go index c74fb4e307e..1cf9e20fa0f 100644 --- a/pkg/kubelet/network/dns/dns_test.go +++ b/pkg/kubelet/network/dns/dns_test.go @@ -28,12 +28,9 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" - utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/client-go/tools/record" - featuregatetesting "k8s.io/component-base/featuregate/testing" runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" "k8s.io/kubernetes/pkg/apis/core/validation" - "k8s.io/kubernetes/pkg/features" netutils "k8s.io/utils/net" "github.com/stretchr/testify/assert" @@ -156,11 +153,10 @@ func TestFormDNSSearchFitsLimits(t *testing.T) { } testCases := []struct { - desc string - hostNames []string - resultSearch []string - events []string - expandedDNSConfig bool + desc string + hostNames []string + resultSearch []string + events []string }{ { desc: "valid: 3 search paths", @@ -184,57 +180,50 @@ func TestFormDNSSearchFitsLimits(t *testing.T) { }, { - desc: "valid ExpandedDNSConfig: 2048 characters in search path list", - hostNames: searchPathList2048Chars, - resultSearch: searchPathList2048Chars, - events: []string{}, - expandedDNSConfig: true, + desc: "valid: 2048 characters in search path list", + hostNames: searchPathList2048Chars, + resultSearch: searchPathList2048Chars, + events: []string{}, }, { - desc: "invalid ExpandedDNSConfig: 2050 characters in search path list", - hostNames: append(searchPathList2048Chars, "B"), - resultSearch: searchPathList2048Chars, - events: []string{fmt.Sprintf("Search Line limits were exceeded, some search paths have been omitted, the applied search line is: %s", strings.Join(searchPathList2048Chars, " "))}, - expandedDNSConfig: true, + desc: "invalid: 2050 characters in search path list", + hostNames: append(searchPathList2048Chars, "B"), + resultSearch: searchPathList2048Chars, + events: []string{fmt.Sprintf("Search Line limits were exceeded, some search paths have been omitted, the applied search line is: %s", strings.Join(searchPathList2048Chars, " "))}, }, { - desc: "invalid ExpandedDNSConfig: 256 characters search path", - hostNames: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "AAA", strings.Repeat("B", 256), "BBB"}, - resultSearch: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "AAA", "BBB"}, - events: []string{"Search Line limits were exceeded, some search paths have been omitted, the applied search line is: testNS.svc.TEST svc.TEST TEST AAA BBB"}, - expandedDNSConfig: true, + desc: "invalid: 256 characters search path", + hostNames: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "AAA", strings.Repeat("B", 256), "BBB"}, + resultSearch: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "AAA", "BBB"}, + events: []string{"Search Line limits were exceeded, some search paths have been omitted, the applied search line is: testNS.svc.TEST svc.TEST TEST AAA BBB"}, }, { - desc: "invalid: 7 search paths", + desc: "valid: 7 search paths", hostNames: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "AAA", "BBB", "CCC", "DDD"}, - resultSearch: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "AAA", "BBB", "CCC"}, - events: []string{"Search Line limits were exceeded, some search paths have been omitted, the applied search line is: testNS.svc.TEST svc.TEST TEST AAA BBB CCC"}, + resultSearch: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "AAA", "BBB", "CCC", "DDD"}, + events: []string{}, }, { - desc: "valid ExpandedDNSConfig: 32 search paths", - hostNames: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"}, - resultSearch: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"}, - events: []string{}, - expandedDNSConfig: true, + desc: "valid: 32 search paths", + hostNames: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"}, + resultSearch: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"}, + events: []string{}, }, { - desc: "invalid ExpandedDNSConfig: 33 search paths", - hostNames: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33"}, - resultSearch: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"}, - events: []string{"Search Line limits were exceeded, some search paths have been omitted, the applied search line is: testNS.svc.TEST svc.TEST TEST 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32"}, - expandedDNSConfig: true, + desc: "invalid: 33 search paths", + hostNames: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33"}, + resultSearch: []string{"testNS.svc.TEST", "svc.TEST", "TEST", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"}, + events: []string{"Search Line limits were exceeded, some search paths have been omitted, the applied search line is: testNS.svc.TEST svc.TEST TEST 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32"}, }, } for i, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ExpandedDNSConfig, tc.expandedDNSConfig)() - dnsSearch := configurer.formDNSSearchFitsLimits(tc.hostNames, pod) assert.EqualValues(t, tc.resultSearch, dnsSearch, "test [%d]", i) for _, expectedEvent := range tc.events { @@ -456,29 +445,6 @@ func TestGetPodDNSType(t *testing.T) { } func TestGetPodDNS(t *testing.T) { - testCases := []struct { - desc string - expandedDNSConfig bool - }{ - { - desc: "Not ExpandedDNSConfig", - expandedDNSConfig: false, - }, - { - desc: "ExpandedDNSConfig", - expandedDNSConfig: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.desc, func(t *testing.T) { - defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ExpandedDNSConfig, tc.expandedDNSConfig)() - testGetPodDNS(t) - }) - } -} - -func testGetPodDNS(t *testing.T) { recorder := record.NewFakeRecorder(20) nodeRef := &v1.ObjectReference{ Kind: "Node", @@ -554,10 +520,7 @@ func testGetPodDNS(t *testing.T) { } expLength := len(options[1].DNSSearch) + 3 - maxDNSSearchPaths := validation.MaxDNSSearchPathsLegacy - if utilfeature.DefaultFeatureGate.Enabled(features.ExpandedDNSConfig) { - maxDNSSearchPaths = validation.MaxDNSSearchPathsExpanded - } + maxDNSSearchPaths := validation.MaxDNSSearchPaths if expLength > maxDNSSearchPaths { expLength = maxDNSSearchPaths