k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/test/e2e_kubeadm/kubelet_config_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 rbacv1 "k8s.io/api/rbac/v1" 23 "k8s.io/kubernetes/test/e2e/framework" 24 admissionapi "k8s.io/pod-security-admission/api" 25 26 "github.com/onsi/ginkgo/v2" 27 "github.com/onsi/gomega" 28 ) 29 30 const ( 31 kubeletConfigConfigMapKey = "kubelet" 32 ) 33 34 var ( 35 kubeletConfigConfigMapName string 36 kubeletConfigRoleName string 37 kubeletConfigRoleBindingName string 38 ) 39 40 // Define container for all the test specification aimed at verifying 41 // that kubeadm creates the kubelet-config ConfigMap, that it is properly configured 42 // and that all the related RBAC rules are in place 43 var _ = Describe("kubelet-config ConfigMap", func() { 44 45 // Get an instance of the k8s test framework 46 f := framework.NewDefaultFramework("kubelet-config") 47 f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged 48 49 // Tests in this container are not expected to create new objects in the cluster 50 // so we are disabling the creation of a namespace in order to get a faster execution 51 f.SkipNamespaceCreation = true 52 53 // kubelet-config map is named using the kubernetesVersion as a suffix, and so 54 // it is necessary to get it from the kubeadm-config ConfigMap before testing 55 ginkgo.BeforeEach(func() { 56 // if the kubelet-config map name is already known exit 57 if kubeletConfigConfigMapName != "" { 58 return 59 } 60 61 kubeletConfigConfigMapName = "kubelet-config" 62 kubeletConfigRoleName = "kubeadm:kubelet-config" 63 kubeletConfigRoleBindingName = kubeletConfigRoleName 64 }) 65 66 ginkgo.It("should exist and be properly configured", func(ctx context.Context) { 67 cm := GetConfigMap(f.ClientSet, kubeSystemNamespace, kubeletConfigConfigMapName) 68 gomega.Expect(cm.Data).To(gomega.HaveKey(kubeletConfigConfigMapKey)) 69 }) 70 71 ginkgo.It("should have related Role and RoleBinding", func(ctx context.Context) { 72 ExpectRole(f.ClientSet, kubeSystemNamespace, kubeletConfigRoleName) 73 ExpectRoleBinding(f.ClientSet, kubeSystemNamespace, kubeletConfigRoleBindingName) 74 }) 75 76 ginkgo.It("should be accessible for bootstrap tokens", func(ctx context.Context) { 77 ExpectSubjectHasAccessToResource(f.ClientSet, 78 rbacv1.GroupKind, bootstrapTokensGroup, 79 kubeadmConfigConfigMapResource, 80 ) 81 }) 82 83 ginkgo.It("should be accessible for nodes", func(ctx context.Context) { 84 ExpectSubjectHasAccessToResource(f.ClientSet, 85 rbacv1.GroupKind, nodesGroup, 86 kubeadmConfigConfigMapResource, 87 ) 88 }) 89 })