k8s.io/kubernetes@v1.29.3/test/e2e_kubeadm/proxy_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 authv1 "k8s.io/api/authorization/v1" 23 rbacv1 "k8s.io/api/rbac/v1" 24 "k8s.io/kubernetes/test/e2e/framework" 25 admissionapi "k8s.io/pod-security-admission/api" 26 27 "github.com/onsi/ginkgo/v2" 28 "github.com/onsi/gomega" 29 ) 30 31 const ( 32 kubeProxyServiceAccountName = "kube-proxy" 33 kubeProxyConfigMap = "kube-proxy" 34 kubeProxyConfigMapKey = "config.conf" 35 kubeProxyConfigMapKeyKubeconfig = "kubeconfig.conf" 36 kubeProxyClusterRoleName = "system:node-proxier" 37 kubeProxyClusterRoleBindingName = "kubeadm:node-proxier" 38 kubeProxyRoleName = "kube-proxy" 39 kubeProxyRoleBindingName = kubeProxyRoleName 40 kubeProxyDaemonSetName = "kube-proxy" 41 ) 42 43 var ( 44 kubeProxyConfigMapResource = &authv1.ResourceAttributes{ 45 Namespace: kubeSystemNamespace, 46 Name: kubeProxyConfigMap, 47 Resource: "configmaps", 48 Verb: "get", 49 } 50 ) 51 52 // Define container for all the test specification aimed at verifying 53 // that kubeadm configures the proxy addon as expected 54 var _ = Describe("proxy addon", func() { 55 56 // Get an instance of the k8s test framework 57 f := framework.NewDefaultFramework("proxy") 58 f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged 59 60 // Tests in this container are not expected to create new objects in the cluster 61 // so we are disabling the creation of a namespace in order to get a faster execution 62 f.SkipNamespaceCreation = true 63 64 ginkgo.Context("kube-proxy ServiceAccount", func() { 65 ginkgo.It("should exist", func(ctx context.Context) { 66 ExpectServiceAccount(f.ClientSet, kubeSystemNamespace, kubeProxyServiceAccountName) 67 }) 68 69 ginkgo.It("should be bound to the system:node-proxier cluster role", func(ctx context.Context) { 70 ExpectClusterRoleBindingWithSubjectAndRole(f.ClientSet, 71 kubeProxyClusterRoleBindingName, 72 rbacv1.ServiceAccountKind, kubeProxyServiceAccountName, 73 kubeProxyClusterRoleName, 74 ) 75 }) 76 }) 77 78 ginkgo.Context("kube-proxy ConfigMap", func() { 79 ginkgo.It("should exist and be properly configured", func(ctx context.Context) { 80 cm := GetConfigMap(f.ClientSet, kubeSystemNamespace, kubeProxyConfigMap) 81 82 gomega.Expect(cm.Data).To(gomega.HaveKey(kubeProxyConfigMapKey)) 83 gomega.Expect(cm.Data).To(gomega.HaveKey(kubeProxyConfigMapKeyKubeconfig)) 84 }) 85 86 ginkgo.It("should have related Role and RoleBinding", func(ctx context.Context) { 87 ExpectRole(f.ClientSet, kubeSystemNamespace, kubeProxyRoleName) 88 ExpectRoleBinding(f.ClientSet, kubeSystemNamespace, kubeProxyRoleBindingName) 89 }) 90 91 ginkgo.It("should be accessible by bootstrap tokens", func(ctx context.Context) { 92 ExpectSubjectHasAccessToResource(f.ClientSet, 93 rbacv1.GroupKind, bootstrapTokensGroup, 94 kubeProxyConfigMapResource, 95 ) 96 }) 97 }) 98 99 ginkgo.Context("kube-proxy DaemonSet", func() { 100 ginkgo.It("should exist and be properly configured", func(ctx context.Context) { 101 ds := GetDaemonSet(f.ClientSet, kubeSystemNamespace, kubeProxyDaemonSetName) 102 103 gomega.Expect(ds.Spec.Template.Spec.ServiceAccountName).To(gomega.Equal(kubeProxyServiceAccountName)) 104 }) 105 }) 106 })