mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
Add e2e test for forwarding PTR records to upstream nameserver.
createDNSServerWithPtrRecord in dns_common.go is added to generate dns server pod with PTR record.
This commit is contained in:
parent
666b6b9e85
commit
6a072b9085
@ -318,4 +318,5 @@ var _ = SIGDescribe("DNS", func() {
|
|||||||
|
|
||||||
// TODO: Add more test cases for other DNSPolicies.
|
// TODO: Add more test cases for other DNSPolicies.
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -110,6 +110,9 @@ func (t *dnsTestCommon) runDig(dnsName, target string) []string {
|
|||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("invalid target: " + target))
|
panic(fmt.Errorf("invalid target: " + target))
|
||||||
}
|
}
|
||||||
|
if strings.HasSuffix(dnsName, "in-addr.arpa") || strings.HasSuffix(dnsName, "in-addr.arpa.") {
|
||||||
|
cmd = append(cmd, []string{"-t", "ptr"}...)
|
||||||
|
}
|
||||||
cmd = append(cmd, dnsName)
|
cmd = append(cmd, dnsName)
|
||||||
|
|
||||||
stdout, stderr, err := t.f.ExecWithOptions(framework.ExecOptions{
|
stdout, stderr, err := t.f.ExecWithOptions(framework.ExecOptions{
|
||||||
@ -266,8 +269,8 @@ func generateDNSServerPod(aRecords map[string]string) *v1.Pod {
|
|||||||
return pod
|
return pod
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *dnsTestCommon) createDNSServer(aRecords map[string]string) {
|
func (t *dnsTestCommon) createDNSPodFromObj(pod *v1.Pod) {
|
||||||
t.dnsServerPod = generateDNSServerPod(aRecords)
|
t.dnsServerPod = pod
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
t.dnsServerPod, err = t.c.CoreV1().Pods(t.f.Namespace.Name).Create(t.dnsServerPod)
|
t.dnsServerPod, err = t.c.CoreV1().Pods(t.f.Namespace.Name).Create(t.dnsServerPod)
|
||||||
@ -280,6 +283,40 @@ func (t *dnsTestCommon) createDNSServer(aRecords map[string]string) {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *dnsTestCommon) createDNSServer(aRecords map[string]string) {
|
||||||
|
t.createDNSPodFromObj(generateDNSServerPod(aRecords))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *dnsTestCommon) createDNSServerWithPtrRecord() {
|
||||||
|
pod := &v1.Pod{
|
||||||
|
TypeMeta: metav1.TypeMeta{
|
||||||
|
Kind: "Pod",
|
||||||
|
},
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
GenerateName: "e2e-dns-configmap-dns-server-",
|
||||||
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "dns",
|
||||||
|
Image: imageutils.GetE2EImage(imageutils.DNSMasq),
|
||||||
|
Command: []string{
|
||||||
|
"/usr/sbin/dnsmasq",
|
||||||
|
"-u", "root",
|
||||||
|
"-k",
|
||||||
|
"--log-facility", "-",
|
||||||
|
"--host-record=my.test,192.0.2.123",
|
||||||
|
"-q",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DNSPolicy: "Default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
t.createDNSPodFromObj(pod)
|
||||||
|
}
|
||||||
|
|
||||||
func (t *dnsTestCommon) deleteDNSServerPod() {
|
func (t *dnsTestCommon) deleteDNSServerPod() {
|
||||||
podClient := t.c.CoreV1().Pods(t.f.Namespace.Name)
|
podClient := t.c.CoreV1().Pods(t.f.Namespace.Name)
|
||||||
if err := podClient.Delete(t.dnsServerPod.Name, metav1.NewDeleteOptions(0)); err != nil {
|
if err := podClient.Delete(t.dnsServerPod.Name, metav1.NewDeleteOptions(0)); err != nil {
|
||||||
|
@ -34,10 +34,10 @@ type dnsFederationsConfigMapTest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var _ = SIGDescribe("DNS configMap federations", func() {
|
var _ = SIGDescribe("DNS configMap federations", func() {
|
||||||
t := &dnsNameserverTest{dnsTestCommon: newDnsTestCommon()}
|
|
||||||
BeforeEach(func() { t.c = t.f.ClientSet })
|
|
||||||
|
|
||||||
It("should be able to change federation configuration [Slow][Serial]", func() {
|
It("should be able to change federation configuration [Slow][Serial]", func() {
|
||||||
|
t := &dnsNameserverTest{dnsTestCommon: newDnsTestCommon()}
|
||||||
|
t.c = t.f.ClientSet
|
||||||
t.run()
|
t.run()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -185,11 +185,50 @@ func (t *dnsNameserverTest) run() {
|
|||||||
moreForeverTestTimeout)
|
moreForeverTestTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type dnsPtrFwdTest struct {
|
||||||
|
dnsTestCommon
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *dnsPtrFwdTest) run() {
|
||||||
|
t.init()
|
||||||
|
|
||||||
|
t.createUtilPod()
|
||||||
|
defer t.deleteUtilPod()
|
||||||
|
|
||||||
|
t.createDNSServerWithPtrRecord()
|
||||||
|
defer t.deleteDNSServerPod()
|
||||||
|
|
||||||
|
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{
|
||||||
|
"upstreamNameservers": fmt.Sprintf(`["%v"]`, t.dnsServerPod.Status.PodIP),
|
||||||
|
}})
|
||||||
|
|
||||||
|
moreForeverTestTimeout := 2 * 60 * time.Second
|
||||||
|
|
||||||
|
t.checkDNSRecordFrom(
|
||||||
|
"123.2.0.192.in-addr.arpa",
|
||||||
|
func(actual []string) bool { return len(actual) == 1 && actual[0] == "my.test." },
|
||||||
|
"dnsmasq",
|
||||||
|
moreForeverTestTimeout)
|
||||||
|
|
||||||
|
t.c.CoreV1().ConfigMaps(t.ns).Delete(t.name, nil)
|
||||||
|
t.checkDNSRecordFrom(
|
||||||
|
"123.2.0.192.in-addr.arpa",
|
||||||
|
func(actual []string) bool { return len(actual) == 0 },
|
||||||
|
"dnsmasq",
|
||||||
|
moreForeverTestTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
var _ = SIGDescribe("DNS configMap nameserver", func() {
|
var _ = SIGDescribe("DNS configMap nameserver", func() {
|
||||||
t := &dnsNameserverTest{dnsTestCommon: newDnsTestCommon()}
|
|
||||||
BeforeEach(func() { t.c = t.f.ClientSet })
|
|
||||||
|
|
||||||
It("should be able to change stubDomain configuration [Slow][Serial]", func() {
|
It("should be able to change stubDomain configuration [Slow][Serial]", func() {
|
||||||
t.run()
|
nsTest := &dnsNameserverTest{dnsTestCommon: newDnsTestCommon()}
|
||||||
|
nsTest.c = nsTest.f.ClientSet
|
||||||
|
nsTest.run()
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should forward PTR records lookup to upstream nameserver [Slow][Serial]", func() {
|
||||||
|
fwdTest := &dnsPtrFwdTest{dnsTestCommon: newDnsTestCommon()}
|
||||||
|
fwdTest.c = fwdTest.f.ClientSet
|
||||||
|
fwdTest.run()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user