k8s.io/kubernetes@v1.29.3/test/e2e_kubeadm/cluster_info_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  	authv1 "k8s.io/api/authorization/v1"
    23  	rbacv1 "k8s.io/api/rbac/v1"
    24  	bootstrapapi "k8s.io/cluster-bootstrap/token/api"
    25  	"k8s.io/kubernetes/test/e2e/framework"
    26  	admissionapi "k8s.io/pod-security-admission/api"
    27  
    28  	"github.com/onsi/ginkgo/v2"
    29  	"github.com/onsi/gomega"
    30  )
    31  
    32  const (
    33  	clusterInfoConfigMapName   = "cluster-info"
    34  	clusterInfoRoleName        = "kubeadm:bootstrap-signer-clusterinfo"
    35  	clusterInfoRoleBindingName = clusterInfoRoleName
    36  )
    37  
    38  var (
    39  	clusterInfoConfigMapResource = &authv1.ResourceAttributes{
    40  		Namespace: kubePublicNamespace,
    41  		Name:      clusterInfoConfigMapName,
    42  		Resource:  "configmaps",
    43  		Verb:      "get",
    44  	}
    45  )
    46  
    47  // Define container for all the test specification aimed at verifying
    48  // that kubeadm creates the cluster-info ConfigMap, that it is properly configured
    49  // and that all the related RBAC rules are in place
    50  var _ = Describe("cluster-info ConfigMap", func() {
    51  
    52  	// Get an instance of the k8s test framework
    53  	f := framework.NewDefaultFramework("cluster-info")
    54  	f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
    55  
    56  	// Tests in this container are not expected to create new objects in the cluster
    57  	// so we are disabling the creation of a namespace in order to get a faster execution
    58  	f.SkipNamespaceCreation = true
    59  
    60  	ginkgo.It("should exist and be properly configured", func(ctx context.Context) {
    61  		// Nb. this is technically implemented a part of the bootstrap-token phase
    62  		cm := GetConfigMap(f.ClientSet, kubePublicNamespace, clusterInfoConfigMapName)
    63  
    64  		gomega.Expect(cm.Data).To(gomega.HaveKey(gomega.HavePrefix(bootstrapapi.JWSSignatureKeyPrefix)))
    65  		gomega.Expect(cm.Data).To(gomega.HaveKey(bootstrapapi.KubeConfigKey))
    66  
    67  		//TODO: What else? server?
    68  	})
    69  
    70  	ginkgo.It("should have related Role and RoleBinding", func(ctx context.Context) {
    71  		// Nb. this is technically implemented a part of the bootstrap-token phase
    72  		ExpectRole(f.ClientSet, kubePublicNamespace, clusterInfoRoleName)
    73  		ExpectRoleBinding(f.ClientSet, kubePublicNamespace, clusterInfoRoleBindingName)
    74  	})
    75  
    76  	ginkgo.It("should be accessible for anonymous", func(ctx context.Context) {
    77  		ExpectSubjectHasAccessToResource(f.ClientSet,
    78  			rbacv1.UserKind, anonymousUser,
    79  			clusterInfoConfigMapResource,
    80  		)
    81  	})
    82  })