|
| 1 | +/* |
| 2 | +Copyright 2019 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package e2e_kubeadm |
| 18 | + |
| 19 | +import ( |
| 20 | + "k8s.io/kubernetes/test/e2e/framework" |
| 21 | + |
| 22 | + . "github.com/onsi/ginkgo" |
| 23 | + . "github.com/onsi/gomega" |
| 24 | +) |
| 25 | + |
| 26 | +const ( |
| 27 | + dnsService = "kube-dns" |
| 28 | + |
| 29 | + coreDNSServiceAccountName = "coredns" |
| 30 | + coreDNSConfigMap = "coredns" |
| 31 | + coreDNSConfigMapKey = "Corefile" |
| 32 | + coreDNSRoleName = "system:coredns" |
| 33 | + coreDNSRoleBindingName = coreDNSRoleName |
| 34 | + coreDNSDeploymentName = "coredns" |
| 35 | + |
| 36 | + kubeDNSServiceAccountName = "kube-dns" |
| 37 | + kubeDNSDeploymentName = "kube-dns" |
| 38 | +) |
| 39 | + |
| 40 | +var ( |
| 41 | + dnsType = "" |
| 42 | +) |
| 43 | + |
| 44 | +// Define container for all the test specification aimed at verifying |
| 45 | +// that kubeadm configures the dns as expected |
| 46 | +var _ = KubeadmDescribe("DNS addon", func() { |
| 47 | + |
| 48 | + // Get an instance of the k8s test framework |
| 49 | + f := framework.NewDefaultFramework("DNS") |
| 50 | + |
| 51 | + // Tests in this container are not expected to create new objects in the cluster |
| 52 | + // so we are disabling the creation of a namespace in order to get a faster execution |
| 53 | + f.SkipNamespaceCreation = true |
| 54 | + |
| 55 | + // kubeadm supports two type of DNS addon, and so |
| 56 | + // it is necessary to get it from the kubeadm-config ConfigMap before testing |
| 57 | + BeforeEach(func() { |
| 58 | + // if the dnsType name is already known exit |
| 59 | + if dnsType != "" { |
| 60 | + return |
| 61 | + } |
| 62 | + |
| 63 | + // gets the ClusterConfiguration from the kubeadm kubeadm-config ConfigMap as a untyped map |
| 64 | + m := getClusterConfiguration(f.ClientSet) |
| 65 | + |
| 66 | + // Extract the dnsType |
| 67 | + dnsType = "CoreDNS" |
| 68 | + if _, ok := m["dns"]; ok { |
| 69 | + d := m["dns"].(map[interface{}]interface{}) |
| 70 | + if t, ok := d["type"]; ok { |
| 71 | + dnsType = t.(string) |
| 72 | + } |
| 73 | + } |
| 74 | + }) |
| 75 | + |
| 76 | + Context("kube-dns", func() { |
| 77 | + Context("kube-dns ServiceAccount", func() { |
| 78 | + It("should exist", func() { |
| 79 | + if dnsType != "kube-dns" { |
| 80 | + framework.Skipf("Skipping because DNS type is %s", dnsType) |
| 81 | + } |
| 82 | + |
| 83 | + ExpectServiceAccount(f.ClientSet, kubeSystemNamespace, kubeDNSServiceAccountName) |
| 84 | + }) |
| 85 | + }) |
| 86 | + |
| 87 | + Context("kube-dns Deployment", func() { |
| 88 | + It("should exist and be properly configured", func() { |
| 89 | + if dnsType != "kube-dns" { |
| 90 | + framework.Skipf("Skipping because DNS type is %s", dnsType) |
| 91 | + } |
| 92 | + |
| 93 | + d := GetDeployment(f.ClientSet, kubeSystemNamespace, kubeDNSDeploymentName) |
| 94 | + |
| 95 | + Expect(d.Spec.Template.Spec.ServiceAccountName).To(Equal(kubeDNSServiceAccountName)) |
| 96 | + }) |
| 97 | + }) |
| 98 | + }) |
| 99 | + |
| 100 | + Context("CoreDNS", func() { |
| 101 | + Context("CoreDNS ServiceAccount", func() { |
| 102 | + It("should exist", func() { |
| 103 | + if dnsType != "CoreDNS" { |
| 104 | + framework.Skipf("Skipping because DNS type is %s", dnsType) |
| 105 | + } |
| 106 | + |
| 107 | + ExpectServiceAccount(f.ClientSet, kubeSystemNamespace, coreDNSServiceAccountName) |
| 108 | + }) |
| 109 | + |
| 110 | + It("should have related ClusterRole and ClusterRoleBinding", func() { |
| 111 | + if dnsType != "CoreDNS" { |
| 112 | + framework.Skipf("Skipping because DNS type is %s", dnsType) |
| 113 | + } |
| 114 | + |
| 115 | + ExpectClusterRole(f.ClientSet, coreDNSRoleName) |
| 116 | + ExpectClusterRoleBinding(f.ClientSet, coreDNSRoleBindingName) |
| 117 | + }) |
| 118 | + }) |
| 119 | + |
| 120 | + Context("CoreDNS ConfigMap", func() { |
| 121 | + It("should exist and be properly configured", func() { |
| 122 | + if dnsType != "CoreDNS" { |
| 123 | + framework.Skipf("Skipping because DNS type is %s", dnsType) |
| 124 | + } |
| 125 | + |
| 126 | + cm := GetConfigMap(f.ClientSet, kubeSystemNamespace, coreDNSConfigMap) |
| 127 | + |
| 128 | + Expect(cm.Data).To(HaveKey(coreDNSConfigMapKey)) |
| 129 | + }) |
| 130 | + }) |
| 131 | + |
| 132 | + Context("CoreDNS Deployment", func() { |
| 133 | + It("should exist and be properly configured", func() { |
| 134 | + if dnsType != "CoreDNS" { |
| 135 | + framework.Skipf("Skipping because DNS type is %s", dnsType) |
| 136 | + } |
| 137 | + |
| 138 | + d := GetDeployment(f.ClientSet, kubeSystemNamespace, coreDNSDeploymentName) |
| 139 | + |
| 140 | + Expect(d.Spec.Template.Spec.ServiceAccountName).To(Equal(coreDNSServiceAccountName)) |
| 141 | + }) |
| 142 | + }) |
| 143 | + }) |
| 144 | + |
| 145 | + Context("DNS Service", func() { |
| 146 | + It("should exist", func() { |
| 147 | + ExpectService(f.ClientSet, kubeSystemNamespace, dnsService) |
| 148 | + }) |
| 149 | + }) |
| 150 | +}) |
0 commit comments