mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #63265 from rajansandeep/dnsconfigtest
Automatic merge from submit-queue (batch tested with PRs 64174, 64187, 64216, 63265, 64223). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Extend dns configmap tests to include CoreDNS **What this PR does / why we need it**: This PR extends the DNS configmap e2e tests to include testing the CoreDNS ConfigMap. The tests now test the equivalent `stubdomain`, `federation` and `upstreamnameserver` configuration of kube-dns for CoreDNS, when CoreDNS is the installed DNS server. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #62865 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
52f44cdb2a
@ -55,9 +55,8 @@ type dnsTestCommon struct {
|
|||||||
|
|
||||||
func newDnsTestCommon() dnsTestCommon {
|
func newDnsTestCommon() dnsTestCommon {
|
||||||
return dnsTestCommon{
|
return dnsTestCommon{
|
||||||
f: framework.NewDefaultFramework("dns-config-map"),
|
f: framework.NewDefaultFramework("dns-config-map"),
|
||||||
ns: "kube-system",
|
ns: "kube-system",
|
||||||
name: "kube-dns",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,6 +71,12 @@ func (t *dnsTestCommon) init() {
|
|||||||
|
|
||||||
t.dnsPod = &pods.Items[0]
|
t.dnsPod = &pods.Items[0]
|
||||||
framework.Logf("Using DNS pod: %v", t.dnsPod.Name)
|
framework.Logf("Using DNS pod: %v", t.dnsPod.Name)
|
||||||
|
|
||||||
|
if strings.Contains(t.dnsPod.Name, "coredns") {
|
||||||
|
t.name = "coredns"
|
||||||
|
} else {
|
||||||
|
t.name = "kube-dns"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *dnsTestCommon) checkDNSRecord(name string, predicate func([]string) bool, timeout time.Duration) {
|
func (t *dnsTestCommon) checkDNSRecord(name string, predicate func([]string) bool, timeout time.Duration) {
|
||||||
@ -102,6 +107,8 @@ func (t *dnsTestCommon) checkDNSRecordFrom(name string, predicate func([]string)
|
|||||||
func (t *dnsTestCommon) runDig(dnsName, target string) []string {
|
func (t *dnsTestCommon) runDig(dnsName, target string) []string {
|
||||||
cmd := []string{"/usr/bin/dig", "+short"}
|
cmd := []string{"/usr/bin/dig", "+short"}
|
||||||
switch target {
|
switch target {
|
||||||
|
case "coredns":
|
||||||
|
cmd = append(cmd, "@"+t.dnsPod.Status.PodIP)
|
||||||
case "kube-dns":
|
case "kube-dns":
|
||||||
cmd = append(cmd, "@"+t.dnsPod.Status.PodIP, "-p", "10053")
|
cmd = append(cmd, "@"+t.dnsPod.Status.PodIP, "-p", "10053")
|
||||||
case "dnsmasq":
|
case "dnsmasq":
|
||||||
@ -161,6 +168,24 @@ func (t *dnsTestCommon) setConfigMap(cm *v1.ConfigMap) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *dnsTestCommon) fetchDNSConfigMapData() map[string]string {
|
||||||
|
if t.name == "coredns" {
|
||||||
|
pcm, err := t.c.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get(t.name, metav1.GetOptions{})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
return pcm.Data
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *dnsTestCommon) restoreDNSConfigMap(configMapData map[string]string) {
|
||||||
|
if t.name == "coredns" {
|
||||||
|
t.setConfigMap(&v1.ConfigMap{Data: configMapData})
|
||||||
|
t.deleteCoreDNSPods()
|
||||||
|
} else {
|
||||||
|
t.c.CoreV1().ConfigMaps(t.ns).Delete(t.name, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t *dnsTestCommon) deleteConfigMap() {
|
func (t *dnsTestCommon) deleteConfigMap() {
|
||||||
By(fmt.Sprintf("Deleting the ConfigMap (%s:%s)", t.ns, t.name))
|
By(fmt.Sprintf("Deleting the ConfigMap (%s:%s)", t.ns, t.name))
|
||||||
t.cm = nil
|
t.cm = nil
|
||||||
@ -234,6 +259,21 @@ func (t *dnsTestCommon) deleteUtilPod() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deleteCoreDNSPods manually deletes the CoreDNS pods to apply the changes to the ConfigMap.
|
||||||
|
func (t *dnsTestCommon) deleteCoreDNSPods() {
|
||||||
|
|
||||||
|
label := labels.SelectorFromSet(labels.Set(map[string]string{"k8s-app": "kube-dns"}))
|
||||||
|
options := metav1.ListOptions{LabelSelector: label.String()}
|
||||||
|
|
||||||
|
pods, err := t.f.ClientSet.CoreV1().Pods("kube-system").List(options)
|
||||||
|
podClient := t.c.CoreV1().Pods(metav1.NamespaceSystem)
|
||||||
|
|
||||||
|
for _, pod := range pods.Items {
|
||||||
|
err = podClient.Delete(pod.Name, metav1.NewDeleteOptions(0))
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func generateDNSServerPod(aRecords map[string]string) *v1.Pod {
|
func generateDNSServerPod(aRecords map[string]string) *v1.Pod {
|
||||||
pod := &v1.Pod{
|
pod := &v1.Pod{
|
||||||
TypeMeta: metav1.TypeMeta{
|
TypeMeta: metav1.TypeMeta{
|
||||||
|
@ -151,6 +151,8 @@ func (t *dnsNameserverTest) run() {
|
|||||||
|
|
||||||
t.createUtilPod()
|
t.createUtilPod()
|
||||||
defer t.deleteUtilPod()
|
defer t.deleteUtilPod()
|
||||||
|
originalConfigMapData := t.fetchDNSConfigMapData()
|
||||||
|
defer t.restoreDNSConfigMap(originalConfigMapData)
|
||||||
|
|
||||||
t.createDNSServer(map[string]string{
|
t.createDNSServer(map[string]string{
|
||||||
"abc.acme.local": "1.1.1.1",
|
"abc.acme.local": "1.1.1.1",
|
||||||
@ -159,10 +161,28 @@ func (t *dnsNameserverTest) run() {
|
|||||||
})
|
})
|
||||||
defer t.deleteDNSServerPod()
|
defer t.deleteDNSServerPod()
|
||||||
|
|
||||||
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{
|
if t.name == "coredns" {
|
||||||
"stubDomains": fmt.Sprintf(`{"acme.local":["%v"]}`, t.dnsServerPod.Status.PodIP),
|
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{
|
||||||
"upstreamNameservers": fmt.Sprintf(`["%v"]`, t.dnsServerPod.Status.PodIP),
|
"Corefile": fmt.Sprintf(`.:53 {
|
||||||
}})
|
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
||||||
|
pods insecure
|
||||||
|
upstream
|
||||||
|
fallthrough in-addr.arpa ip6.arpa
|
||||||
|
}
|
||||||
|
proxy . %v
|
||||||
|
}
|
||||||
|
acme.local:53 {
|
||||||
|
proxy . %v
|
||||||
|
}`, t.dnsServerPod.Status.PodIP, t.dnsServerPod.Status.PodIP),
|
||||||
|
}})
|
||||||
|
|
||||||
|
t.deleteCoreDNSPods()
|
||||||
|
} else {
|
||||||
|
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{
|
||||||
|
"stubDomains": fmt.Sprintf(`{"acme.local":["%v"]}`, t.dnsServerPod.Status.PodIP),
|
||||||
|
"upstreamNameservers": fmt.Sprintf(`["%v"]`, t.dnsServerPod.Status.PodIP),
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
|
||||||
t.checkDNSRecordFrom(
|
t.checkDNSRecordFrom(
|
||||||
"abc.acme.local",
|
"abc.acme.local",
|
||||||
@ -180,7 +200,7 @@ func (t *dnsNameserverTest) run() {
|
|||||||
"dnsmasq",
|
"dnsmasq",
|
||||||
moreForeverTestTimeout)
|
moreForeverTestTimeout)
|
||||||
|
|
||||||
t.c.CoreV1().ConfigMaps(t.ns).Delete(t.name, nil)
|
t.restoreDNSConfigMap(originalConfigMapData)
|
||||||
// Wait for the deleted ConfigMap to take effect, otherwise the
|
// Wait for the deleted ConfigMap to take effect, otherwise the
|
||||||
// configuration can bleed into other tests.
|
// configuration can bleed into other tests.
|
||||||
t.checkDNSRecordFrom(
|
t.checkDNSRecordFrom(
|
||||||
@ -199,6 +219,8 @@ func (t *dnsPtrFwdTest) run() {
|
|||||||
|
|
||||||
t.createUtilPod()
|
t.createUtilPod()
|
||||||
defer t.deleteUtilPod()
|
defer t.deleteUtilPod()
|
||||||
|
originalConfigMapData := t.fetchDNSConfigMapData()
|
||||||
|
defer t.restoreDNSConfigMap(originalConfigMapData)
|
||||||
|
|
||||||
t.createDNSServerWithPtrRecord()
|
t.createDNSServerWithPtrRecord()
|
||||||
defer t.deleteDNSServerPod()
|
defer t.deleteDNSServerPod()
|
||||||
@ -210,9 +232,24 @@ func (t *dnsPtrFwdTest) run() {
|
|||||||
"dnsmasq",
|
"dnsmasq",
|
||||||
moreForeverTestTimeout)
|
moreForeverTestTimeout)
|
||||||
|
|
||||||
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{
|
if t.name == "coredns" {
|
||||||
"upstreamNameservers": fmt.Sprintf(`["%v"]`, t.dnsServerPod.Status.PodIP),
|
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{
|
||||||
}})
|
"Corefile": fmt.Sprintf(`.:53 {
|
||||||
|
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
||||||
|
pods insecure
|
||||||
|
upstream
|
||||||
|
fallthrough in-addr.arpa ip6.arpa
|
||||||
|
}
|
||||||
|
proxy . %v
|
||||||
|
}`, t.dnsServerPod.Status.PodIP),
|
||||||
|
}})
|
||||||
|
|
||||||
|
t.deleteCoreDNSPods()
|
||||||
|
} else {
|
||||||
|
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{
|
||||||
|
"upstreamNameservers": fmt.Sprintf(`["%v"]`, t.dnsServerPod.Status.PodIP),
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
|
||||||
t.checkDNSRecordFrom(
|
t.checkDNSRecordFrom(
|
||||||
"123.2.0.192.in-addr.arpa",
|
"123.2.0.192.in-addr.arpa",
|
||||||
@ -220,7 +257,7 @@ func (t *dnsPtrFwdTest) run() {
|
|||||||
"dnsmasq",
|
"dnsmasq",
|
||||||
moreForeverTestTimeout)
|
moreForeverTestTimeout)
|
||||||
|
|
||||||
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{}})
|
t.restoreDNSConfigMap(originalConfigMapData)
|
||||||
t.checkDNSRecordFrom(
|
t.checkDNSRecordFrom(
|
||||||
"123.2.0.192.in-addr.arpa",
|
"123.2.0.192.in-addr.arpa",
|
||||||
func(actual []string) bool { return len(actual) == 0 },
|
func(actual []string) bool { return len(actual) == 0 },
|
||||||
@ -237,6 +274,8 @@ func (t *dnsExternalNameTest) run() {
|
|||||||
|
|
||||||
t.createUtilPod()
|
t.createUtilPod()
|
||||||
defer t.deleteUtilPod()
|
defer t.deleteUtilPod()
|
||||||
|
originalConfigMapData := t.fetchDNSConfigMapData()
|
||||||
|
defer t.restoreDNSConfigMap(originalConfigMapData)
|
||||||
|
|
||||||
fooHostname := "foo.example.com"
|
fooHostname := "foo.example.com"
|
||||||
t.createDNSServer(map[string]string{
|
t.createDNSServer(map[string]string{
|
||||||
@ -270,9 +309,24 @@ func (t *dnsExternalNameTest) run() {
|
|||||||
"dnsmasq",
|
"dnsmasq",
|
||||||
moreForeverTestTimeout)
|
moreForeverTestTimeout)
|
||||||
|
|
||||||
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{
|
if t.name == "coredns" {
|
||||||
"upstreamNameservers": fmt.Sprintf(`["%v"]`, t.dnsServerPod.Status.PodIP),
|
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{
|
||||||
}})
|
"Corefile": fmt.Sprintf(`.:53 {
|
||||||
|
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
||||||
|
pods insecure
|
||||||
|
upstream
|
||||||
|
fallthrough in-addr.arpa ip6.arpa
|
||||||
|
}
|
||||||
|
proxy . %v
|
||||||
|
}`, t.dnsServerPod.Status.PodIP),
|
||||||
|
}})
|
||||||
|
|
||||||
|
t.deleteCoreDNSPods()
|
||||||
|
} else {
|
||||||
|
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{
|
||||||
|
"upstreamNameservers": fmt.Sprintf(`["%v"]`, t.dnsServerPod.Status.PodIP),
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
|
||||||
t.checkDNSRecordFrom(
|
t.checkDNSRecordFrom(
|
||||||
fmt.Sprintf("%s.%s.svc.cluster.local", serviceNameLocal, f.Namespace.Name),
|
fmt.Sprintf("%s.%s.svc.cluster.local", serviceNameLocal, f.Namespace.Name),
|
||||||
@ -282,7 +336,7 @@ func (t *dnsExternalNameTest) run() {
|
|||||||
"dnsmasq",
|
"dnsmasq",
|
||||||
moreForeverTestTimeout)
|
moreForeverTestTimeout)
|
||||||
|
|
||||||
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{}})
|
t.restoreDNSConfigMap(originalConfigMapData)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = SIGDescribe("DNS configMap nameserver", func() {
|
var _ = SIGDescribe("DNS configMap nameserver", func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user