k8s.io/kubernetes@v1.29.3/test/e2e_kubeadm/dns_addon_test.go (about)

     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 kubeadm
    18  
    19  import (
    20  	"context"
    21  
    22  	"k8s.io/kubernetes/test/e2e/framework"
    23  	admissionapi "k8s.io/pod-security-admission/api"
    24  
    25  	"github.com/onsi/ginkgo/v2"
    26  	"github.com/onsi/gomega"
    27  )
    28  
    29  const (
    30  	dnsService = "kube-dns"
    31  
    32  	coreDNSServiceAccountName = "coredns"
    33  	coreDNSConfigMap          = "coredns"
    34  	coreDNSConfigMapKey       = "Corefile"
    35  	coreDNSRoleName           = "system:coredns"
    36  	coreDNSRoleBindingName    = coreDNSRoleName
    37  	coreDNSDeploymentName     = "coredns"
    38  )
    39  
    40  // Define container for all the test specification aimed at verifying
    41  // that kubeadm configures the DNS addon as expected
    42  var _ = Describe("DNS addon", func() {
    43  
    44  	// Get an instance of the k8s test framework
    45  	f := framework.NewDefaultFramework("DNS")
    46  	f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
    47  
    48  	// Tests in this container are not expected to create new objects in the cluster
    49  	// so we are disabling the creation of a namespace in order to get a faster execution
    50  	f.SkipNamespaceCreation = true
    51  
    52  	ginkgo.Context("CoreDNS", func() {
    53  		ginkgo.Context("CoreDNS ServiceAccount", func() {
    54  			ginkgo.It("should exist", func(ctx context.Context) {
    55  				ExpectServiceAccount(f.ClientSet, kubeSystemNamespace, coreDNSServiceAccountName)
    56  			})
    57  
    58  			ginkgo.It("should have related ClusterRole and ClusterRoleBinding", func(ctx context.Context) {
    59  				ExpectClusterRole(f.ClientSet, coreDNSRoleName)
    60  				ExpectClusterRoleBinding(f.ClientSet, coreDNSRoleBindingName)
    61  			})
    62  		})
    63  
    64  		ginkgo.Context("CoreDNS ConfigMap", func() {
    65  			ginkgo.It("should exist and be properly configured", func(ctx context.Context) {
    66  				cm := GetConfigMap(f.ClientSet, kubeSystemNamespace, coreDNSConfigMap)
    67  				gomega.Expect(cm.Data).To(gomega.HaveKey(coreDNSConfigMapKey))
    68  			})
    69  		})
    70  
    71  		ginkgo.Context("CoreDNS Deployment", func() {
    72  			ginkgo.It("should exist and be properly configured", func(ctx context.Context) {
    73  				d := GetDeployment(f.ClientSet, kubeSystemNamespace, coreDNSDeploymentName)
    74  				gomega.Expect(d.Spec.Template.Spec.ServiceAccountName).To(gomega.Equal(coreDNSServiceAccountName))
    75  			})
    76  		})
    77  	})
    78  
    79  	ginkgo.Context("DNS Service", func() {
    80  		ginkgo.It("should exist", func(ctx context.Context) {
    81  			ExpectService(f.ClientSet, kubeSystemNamespace, dnsService)
    82  		})
    83  	})
    84  })