dns_addon_test.go 4.2 KB

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