dns_addon_test.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 kubeadm
  14. import (
  15. "k8s.io/kubernetes/test/e2e/framework"
  16. e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
  17. "github.com/onsi/ginkgo"
  18. "github.com/onsi/gomega"
  19. )
  20. const (
  21. dnsService = "kube-dns"
  22. coreDNSServiceAccountName = "coredns"
  23. coreDNSConfigMap = "coredns"
  24. coreDNSConfigMapKey = "Corefile"
  25. coreDNSRoleName = "system:coredns"
  26. coreDNSRoleBindingName = coreDNSRoleName
  27. coreDNSDeploymentName = "coredns"
  28. kubeDNSServiceAccountName = "kube-dns"
  29. kubeDNSDeploymentName = "kube-dns"
  30. )
  31. var (
  32. dnsType = ""
  33. )
  34. // Define container for all the test specification aimed at verifying
  35. // that kubeadm configures the dns as expected
  36. var _ = Describe("DNS addon", func() {
  37. // Get an instance of the k8s test framework
  38. f := framework.NewDefaultFramework("DNS")
  39. // Tests in this container are not expected to create new objects in the cluster
  40. // so we are disabling the creation of a namespace in order to get a faster execution
  41. f.SkipNamespaceCreation = true
  42. // kubeadm supports two type of DNS addon, and so
  43. // it is necessary to get it from the kubeadm-config ConfigMap before testing
  44. ginkgo.BeforeEach(func() {
  45. // if the dnsType name is already known exit
  46. if dnsType != "" {
  47. return
  48. }
  49. // gets the ClusterConfiguration from the kubeadm kubeadm-config ConfigMap as a untyped map
  50. m := getClusterConfiguration(f.ClientSet)
  51. // Extract the dnsType
  52. dnsType = "CoreDNS"
  53. if _, ok := m["dns"]; ok {
  54. d := m["dns"].(map[interface{}]interface{})
  55. if t, ok := d["type"]; ok {
  56. dnsType = t.(string)
  57. }
  58. }
  59. })
  60. ginkgo.Context("kube-dns", func() {
  61. ginkgo.Context("kube-dns ServiceAccount", func() {
  62. ginkgo.It("should exist", func() {
  63. if dnsType != "kube-dns" {
  64. e2eskipper.Skipf("Skipping because DNS type is %s", dnsType)
  65. }
  66. ExpectServiceAccount(f.ClientSet, kubeSystemNamespace, kubeDNSServiceAccountName)
  67. })
  68. })
  69. ginkgo.Context("kube-dns Deployment", func() {
  70. ginkgo.It("should exist and be properly configured", func() {
  71. if dnsType != "kube-dns" {
  72. e2eskipper.Skipf("Skipping because DNS type is %s", dnsType)
  73. }
  74. d := GetDeployment(f.ClientSet, kubeSystemNamespace, kubeDNSDeploymentName)
  75. framework.ExpectEqual(d.Spec.Template.Spec.ServiceAccountName, kubeDNSServiceAccountName)
  76. })
  77. })
  78. })
  79. ginkgo.Context("CoreDNS", func() {
  80. ginkgo.Context("CoreDNS ServiceAccount", func() {
  81. ginkgo.It("should exist", func() {
  82. if dnsType != "CoreDNS" {
  83. e2eskipper.Skipf("Skipping because DNS type is %s", dnsType)
  84. }
  85. ExpectServiceAccount(f.ClientSet, kubeSystemNamespace, coreDNSServiceAccountName)
  86. })
  87. ginkgo.It("should have related ClusterRole and ClusterRoleBinding", func() {
  88. if dnsType != "CoreDNS" {
  89. e2eskipper.Skipf("Skipping because DNS type is %s", dnsType)
  90. }
  91. ExpectClusterRole(f.ClientSet, coreDNSRoleName)
  92. ExpectClusterRoleBinding(f.ClientSet, coreDNSRoleBindingName)
  93. })
  94. })
  95. ginkgo.Context("CoreDNS ConfigMap", func() {
  96. ginkgo.It("should exist and be properly configured", func() {
  97. if dnsType != "CoreDNS" {
  98. e2eskipper.Skipf("Skipping because DNS type is %s", dnsType)
  99. }
  100. cm := GetConfigMap(f.ClientSet, kubeSystemNamespace, coreDNSConfigMap)
  101. gomega.Expect(cm.Data).To(gomega.HaveKey(coreDNSConfigMapKey))
  102. })
  103. })
  104. ginkgo.Context("CoreDNS Deployment", func() {
  105. ginkgo.It("should exist and be properly configured", func() {
  106. if dnsType != "CoreDNS" {
  107. e2eskipper.Skipf("Skipping because DNS type is %s", dnsType)
  108. }
  109. d := GetDeployment(f.ClientSet, kubeSystemNamespace, coreDNSDeploymentName)
  110. framework.ExpectEqual(d.Spec.Template.Spec.ServiceAccountName, coreDNSServiceAccountName)
  111. })
  112. })
  113. })
  114. ginkgo.Context("DNS Service", func() {
  115. ginkgo.It("should exist", func() {
  116. ExpectService(f.ClientSet, kubeSystemNamespace, dnsService)
  117. })
  118. })
  119. })