mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
extend configmap tests to include CoreDNS
This commit is contained in:
parent
9b7439d77d
commit
d4ff4ca87f
@ -58,7 +58,6 @@ func newDnsTestCommon() dnsTestCommon {
|
||||
return dnsTestCommon{
|
||||
f: framework.NewDefaultFramework("dns-config-map"),
|
||||
ns: "kube-system",
|
||||
name: "kube-dns",
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,6 +72,12 @@ func (t *dnsTestCommon) init() {
|
||||
|
||||
t.dnsPod = &pods.Items[0]
|
||||
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) {
|
||||
@ -103,6 +108,8 @@ func (t *dnsTestCommon) checkDNSRecordFrom(name string, predicate func([]string)
|
||||
func (t *dnsTestCommon) runDig(dnsName, target string) []string {
|
||||
cmd := []string{"/usr/bin/dig", "+short"}
|
||||
switch target {
|
||||
case "coredns":
|
||||
cmd = append(cmd, "@"+t.dnsPod.Status.PodIP)
|
||||
case "kube-dns":
|
||||
cmd = append(cmd, "@"+t.dnsPod.Status.PodIP, "-p", "10053")
|
||||
case "dnsmasq":
|
||||
@ -162,6 +169,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() {
|
||||
By(fmt.Sprintf("Deleting the ConfigMap (%s:%s)", t.ns, t.name))
|
||||
t.cm = nil
|
||||
@ -235,6 +260,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 {
|
||||
pod := &v1.Pod{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
|
@ -151,6 +151,8 @@ func (t *dnsNameserverTest) run() {
|
||||
|
||||
t.createUtilPod()
|
||||
defer t.deleteUtilPod()
|
||||
originalConfigMapData := t.fetchDNSConfigMapData()
|
||||
defer t.restoreDNSConfigMap(originalConfigMapData)
|
||||
|
||||
t.createDNSServer(map[string]string{
|
||||
"abc.acme.local": "1.1.1.1",
|
||||
@ -159,10 +161,28 @@ func (t *dnsNameserverTest) run() {
|
||||
})
|
||||
defer t.deleteDNSServerPod()
|
||||
|
||||
if t.name == "coredns" {
|
||||
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
|
||||
}
|
||||
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(
|
||||
"abc.acme.local",
|
||||
@ -180,7 +200,7 @@ func (t *dnsNameserverTest) run() {
|
||||
"dnsmasq",
|
||||
moreForeverTestTimeout)
|
||||
|
||||
t.c.CoreV1().ConfigMaps(t.ns).Delete(t.name, nil)
|
||||
t.restoreDNSConfigMap(originalConfigMapData)
|
||||
// Wait for the deleted ConfigMap to take effect, otherwise the
|
||||
// configuration can bleed into other tests.
|
||||
t.checkDNSRecordFrom(
|
||||
@ -199,6 +219,8 @@ func (t *dnsPtrFwdTest) run() {
|
||||
|
||||
t.createUtilPod()
|
||||
defer t.deleteUtilPod()
|
||||
originalConfigMapData := t.fetchDNSConfigMapData()
|
||||
defer t.restoreDNSConfigMap(originalConfigMapData)
|
||||
|
||||
t.createDNSServerWithPtrRecord()
|
||||
defer t.deleteDNSServerPod()
|
||||
@ -210,9 +232,24 @@ func (t *dnsPtrFwdTest) run() {
|
||||
"dnsmasq",
|
||||
moreForeverTestTimeout)
|
||||
|
||||
if t.name == "coredns" {
|
||||
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(
|
||||
"123.2.0.192.in-addr.arpa",
|
||||
@ -220,7 +257,7 @@ func (t *dnsPtrFwdTest) run() {
|
||||
"dnsmasq",
|
||||
moreForeverTestTimeout)
|
||||
|
||||
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{}})
|
||||
t.restoreDNSConfigMap(originalConfigMapData)
|
||||
t.checkDNSRecordFrom(
|
||||
"123.2.0.192.in-addr.arpa",
|
||||
func(actual []string) bool { return len(actual) == 0 },
|
||||
@ -237,6 +274,8 @@ func (t *dnsExternalNameTest) run() {
|
||||
|
||||
t.createUtilPod()
|
||||
defer t.deleteUtilPod()
|
||||
originalConfigMapData := t.fetchDNSConfigMapData()
|
||||
defer t.restoreDNSConfigMap(originalConfigMapData)
|
||||
|
||||
fooHostname := "foo.example.com"
|
||||
t.createDNSServer(map[string]string{
|
||||
@ -270,9 +309,24 @@ func (t *dnsExternalNameTest) run() {
|
||||
"dnsmasq",
|
||||
moreForeverTestTimeout)
|
||||
|
||||
if t.name == "coredns" {
|
||||
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(
|
||||
fmt.Sprintf("%s.%s.svc.cluster.local", serviceNameLocal, f.Namespace.Name),
|
||||
@ -282,7 +336,7 @@ func (t *dnsExternalNameTest) run() {
|
||||
"dnsmasq",
|
||||
moreForeverTestTimeout)
|
||||
|
||||
t.setConfigMap(&v1.ConfigMap{Data: map[string]string{}})
|
||||
t.restoreDNSConfigMap(originalConfigMapData)
|
||||
}
|
||||
|
||||
var _ = SIGDescribe("DNS configMap nameserver", func() {
|
||||
|
Loading…
Reference in New Issue
Block a user