mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #74925 from lee0c/windows-dns-config-tests
Windows dns config test
This commit is contained in:
commit
001bb43ad8
@ -6,6 +6,7 @@ go_library(
|
|||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
"density.go",
|
"density.go",
|
||||||
|
"dns.go",
|
||||||
"framework.go",
|
"framework.go",
|
||||||
"gmsa.go",
|
"gmsa.go",
|
||||||
"hybrid_network.go",
|
"hybrid_network.go",
|
||||||
|
112
test/e2e/windows/dns.go
Normal file
112
test/e2e/windows/dns.go
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2019 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package windows
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
|
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
||||||
|
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||||
|
|
||||||
|
"github.com/onsi/ginkgo"
|
||||||
|
)
|
||||||
|
|
||||||
|
const dnsTestPodHostName = "dns-querier-1"
|
||||||
|
const dnsTestServiceName = "dns-test-service"
|
||||||
|
|
||||||
|
var _ = SIGDescribe("DNS", func() {
|
||||||
|
|
||||||
|
ginkgo.BeforeEach(func() {
|
||||||
|
framework.SkipUnlessNodeOSDistroIs("windows")
|
||||||
|
})
|
||||||
|
|
||||||
|
f := framework.NewDefaultFramework("dns")
|
||||||
|
|
||||||
|
ginkgo.It("should support configurable pod DNS servers", func() {
|
||||||
|
ginkgo.By("Preparing a test DNS service with injected DNS names...")
|
||||||
|
testInjectedIP := "1.1.1.1"
|
||||||
|
testSearchPath := "resolv.conf.local"
|
||||||
|
|
||||||
|
ginkgo.By("Creating a pod with dnsPolicy=None and customized dnsConfig...")
|
||||||
|
testUtilsPod := generateDNSUtilsPod()
|
||||||
|
testUtilsPod.Spec.DNSPolicy = v1.DNSNone
|
||||||
|
testUtilsPod.Spec.DNSConfig = &v1.PodDNSConfig{
|
||||||
|
Nameservers: []string{testInjectedIP},
|
||||||
|
Searches: []string{testSearchPath},
|
||||||
|
}
|
||||||
|
testUtilsPod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(testUtilsPod)
|
||||||
|
framework.ExpectNoError(err)
|
||||||
|
e2elog.Logf("Created pod %v", testUtilsPod)
|
||||||
|
defer func() {
|
||||||
|
e2elog.Logf("Deleting pod %s...", testUtilsPod.Name)
|
||||||
|
if err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(testUtilsPod.Name, metav1.NewDeleteOptions(0)); err != nil {
|
||||||
|
e2elog.Failf("Failed to delete pod %s: %v", testUtilsPod.Name, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
framework.ExpectNoError(f.WaitForPodRunning(testUtilsPod.Name), "failed to wait for pod %s to be running", testUtilsPod.Name)
|
||||||
|
|
||||||
|
ginkgo.By("Verifying customized DNS option is configured on pod...")
|
||||||
|
cmd := []string{"ipconfig", "/all"}
|
||||||
|
stdout, _, err := f.ExecWithOptions(framework.ExecOptions{
|
||||||
|
Command: cmd,
|
||||||
|
Namespace: f.Namespace.Name,
|
||||||
|
PodName: testUtilsPod.Name,
|
||||||
|
ContainerName: "util",
|
||||||
|
CaptureStdout: true,
|
||||||
|
CaptureStderr: true,
|
||||||
|
})
|
||||||
|
framework.ExpectNoError(err)
|
||||||
|
|
||||||
|
e2elog.Logf("ipconfig /all:\n%s", stdout)
|
||||||
|
dnsRegex, err := regexp.Compile(`DNS Servers[\s*.]*:(\s*[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})+`)
|
||||||
|
|
||||||
|
if dnsRegex.MatchString(stdout) {
|
||||||
|
match := dnsRegex.FindString(stdout)
|
||||||
|
|
||||||
|
if !strings.Contains(match, testInjectedIP) {
|
||||||
|
e2elog.Failf("customized DNS options not found in ipconfig /all, got: %s", match)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
e2elog.Failf("cannot find DNS server info in ipconfig /all output: \n%s", stdout)
|
||||||
|
}
|
||||||
|
// TODO: Add more test cases for other DNSPolicies.
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
func generateDNSUtilsPod() *v1.Pod {
|
||||||
|
return &v1.Pod{
|
||||||
|
TypeMeta: metav1.TypeMeta{
|
||||||
|
Kind: "Pod",
|
||||||
|
},
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
GenerateName: "e2e-dns-utils-",
|
||||||
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "util",
|
||||||
|
Image: imageutils.GetE2EImage(imageutils.Dnsutils),
|
||||||
|
Command: []string{"sleep", "10000"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user