Change:
}) f := framework.NewDefaultFramework("dns") ginkgo.It("should support configurable pod DNS servers", func() { <ins> ginkgo.By("Getting the IP address of the internal Kubernetes service") svc, err := f.ClientSet.CoreV1().Services("kube-system").Get(context.TODO(), "kube-dns", metav1.GetOptions{}) framework.ExpectNoError(err) </ins> ginkgo.By("Preparing a test DNS service with injected DNS names...") <del> testInjectedIP := "1.1.1.1" testSearchPath := "resolv.conf.local" ginkgo.By("Creating a pod with dnsPolicy=None and customized dnsConfig...") testUtilsPod := e2epod.NewAgnhostPod(f.Namespace.Name, "e2e-dns-utils", nil, nil, nil) testUtilsPod.Spec.DNSPolicy = v1.DNSNone testUtilsPod.Spec.DNSConfig = &v1.PodDNSConfig{ Nameservers: []string{testInjectedIP}, </del> <ins> // the default service IP will vary from cluster to cluster, but will always be present and is a good DNS test target testInjectedIP := svc.Spec.ClusterIP testSearchPath := "default.svc.cluster.local" ginkgo.By("Creating a windows pod with dnsPolicy=None and customized dnsConfig...") testPod := e2epod.NewAgnhostPod(f.Namespace.Name, "e2e-dns-utils", nil, nil, nil) testPod.Spec.DNSPolicy = v1.DNSNone testPod.Spec.DNSConfig = &v1.PodDNSConfig{ Nameservers: []string{testInjectedIP, "1.1.1.1"}, </ins> Searches:    []string{testSearchPath}, } <del> testUtilsPod.Spec.NodeSelector = map[string]string{ </del> <ins> testPod.Spec.NodeSelector = map[string]string{ </ins> "kubernetes.io/os": "windows", } <del> testUtilsPod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), testUtilsPod, metav1.CreateOptions{}) </del> <ins> testPod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), testPod, metav1.CreateOptions{}) </ins> framework.ExpectNoError(err) <del> framework.Logf("Created pod %v", testUtilsPod) </del> <ins> ginkgo.By("confirming that the pod has a windows label") framework.ExpectEqual(testPod.Spec.NodeSelector["kubernetes.io/os"], "windows") framework.Logf("Created pod %v", testPod) </ins> defer func() { <del> framework.Logf("Deleting pod %s...", testUtilsPod.Name) if err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(context.TODO(), testUtilsPod.Name, *metav1.NewDeleteOptions(0)); err != nil { framework.Failf("Failed to delete pod %s: %v", testUtilsPod.Name, err) </del> <ins> framework.Logf("Deleting pod %s...", testPod.Name) if err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(context.TODO(), testPod.Name, *metav1.NewDeleteOptions(0)); err != nil { framework.Failf("Failed to delete pod %s: %v", testPod.Name, err) </ins> } }() <del> framework.ExpectNoError(e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, testUtilsPod.Name, f.Namespace.Name), "failed to wait for pod %s to be running", testUtilsPod.Name) </del> <ins> framework.ExpectNoError(e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, testPod.Name, f.Namespace.Name), "failed to wait for pod %s to be running", testPod.Name) </ins> <del> ginkgo.By("Verifying customized DNS option is configured on pod...") </del> <ins> // This isn't the best 'test' but it is a great diagnostic, see later test for the 'real' test. ginkgo.By("Calling ipconfig to get debugging info for this pod's DNS and confirm that a dns server 1.1.1.1 can be injected, along with ") </ins> cmd := []string{"ipconfig", "/all"} stdout, _, err := f.ExecWithOptions(framework.ExecOptions{ Command:       cmd, Namespace:     f.Namespace.Name, <del> PodName:       testUtilsPod.Name, </del> <ins> PodName:       testPod.Name, </ins> ContainerName: "agnhost-container", CaptureStdout: true, CaptureStderr: true, }) framework.ExpectNoError(err) framework.Logf("ipconfig /all:n%s", stdout) <del> dnsRegex, err := regexp.Compile(`DNS Servers[s*.]*:(s*[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})+`) framework.ExpectNoError(err) if dnsRegex.MatchString(stdout) { match := dnsRegex.FindString(stdout) </del> <ins> if !strings.Contains(stdout, "1.1.1.1") { framework.Failf("One of the custom DNS options 1.1.1.1, not found in ipconfig /all") } </ins> <del> if !strings.Contains(match, testInjectedIP) { framework.Failf("customized DNS options not found in ipconfig /all, got: %s", match) } } else { framework.Failf("cannot find DNS server info in ipconfig /all output: n%s", stdout) </del> <ins> // We've now verified that the DNS stuff is injected...  now lets make sure that curl'ing 'wrong' endpoints fails, i.e. // a negative control, to run before we run our final test... ginkgo.By("Verifying that curl queries FAIL for wrong URLs") // the below tests use curl because nslookup doesnt seem to use ndots properly // ideally we'd use the powershell native ResolveDns but, that is not a part of agnhost images (as of k8s 1.20) // TODO @jayunit100 add ResolveHost to agn images cmd = []string{"curl.exe", "-k", "https://kubernetezzzzzzzz:443"} stdout, _, err = f.ExecWithOptions(framework.ExecOptions{ Command:       cmd, Namespace:     f.Namespace.Name, PodName:       testPod.Name, ContainerName: "agnhost-container", CaptureStdout: true, CaptureStderr: true, }) if err == nil { framework.Logf("Warning: Somehow the curl command succeeded... The output was n %v", stdout) framework.Failf("Expected a bogus URL query to fail - something is wrong with this test harness, cannot proceed.") } ginkgo.By("Verifying that injected dns records for 'kubernetes' resolve to the valid ip address") cmd = []string{"curl.exe", "-k", "https://kubernetes:443"} stdout, _, err = f.ExecWithOptions(framework.ExecOptions{ Command:       cmd, Namespace:     f.Namespace.Name, PodName:       testPod.Name, ContainerName: "agnhost-container", CaptureStdout: true, CaptureStderr: true, }) framework.Logf("Result of curling the kubernetes service... (Failure ok, only testing for the sake of DNS resolution) %v ... error = %v", stdout, err) // curl returns an error if the host isnt resolved, otherwise, it will return a passing result. if err != nil { framework.ExpectNoError(err) </ins> } // TODO: Add more test cases for other DNSPolicies. }) })

Discussion:
What would you like to be : a check of output for the dnsPolicy tests Why is this needed: dnsPolicy tests right now are confusing to interpret, bc they grep a regex out of the output of . its great to print the output of but i think its more important to really measure wether DNS is plumbed properly into the container by directly attempting to resolve a hostname, since that is what the definition of implies .
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the label and provide further guidance. The label can be by org members by writing in a comment. <detailsInstructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
/sig windows
/assign
cc