k8s.io/kubernetes@v1.29.3/test/e2e_kubeadm/controlplane_nodes_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 corev1 "k8s.io/api/core/v1" 23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 "k8s.io/apimachinery/pkg/labels" 25 clientset "k8s.io/client-go/kubernetes" 26 "k8s.io/kubernetes/test/e2e/framework" 27 e2enode "k8s.io/kubernetes/test/e2e/framework/node" 28 admissionapi "k8s.io/pod-security-admission/api" 29 30 "github.com/onsi/ginkgo/v2" 31 "github.com/onsi/gomega" 32 ) 33 34 const ( 35 controlPlaneLabel = "node-role.kubernetes.io/control-plane" 36 ) 37 38 // Define container for all the test specification aimed at verifying 39 // that kubeadm configures the control-plane node as expected 40 var _ = Describe("control-plane node", func() { 41 42 // Get an instance of the k8s test framework 43 f := framework.NewDefaultFramework("control-plane node") 44 f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged 45 46 // Tests in this container are not expected to create new objects in the cluster 47 // so we are disabling the creation of a namespace in order to get a faster execution 48 f.SkipNamespaceCreation = true 49 50 // Important! please note that this test can't be run on single-node clusters 51 // in case you can skip this test with SKIP=multi-node 52 ginkgo.It("should be labelled and tainted [multi-node]", func(ctx context.Context) { 53 // get all control-plane nodes (and this implicitly checks that node are properly labeled) 54 controlPlanes := getControlPlaneNodes(ctx, f.ClientSet) 55 56 // checks if there is at least one control-plane node 57 gomega.Expect(controlPlanes.Items).NotTo(gomega.BeEmpty(), "at least one node with label %s should exist. if you are running test on a single-node cluster, you can skip this test with SKIP=multi-node", controlPlaneLabel) 58 59 // checks that the control-plane nodes have the expected taints 60 for _, cp := range controlPlanes.Items { 61 e2enode.ExpectNodeHasTaint(ctx, f.ClientSet, cp.GetName(), &corev1.Taint{Key: controlPlaneLabel, Effect: corev1.TaintEffectNoSchedule}) 62 } 63 }) 64 }) 65 66 func getControlPlaneNodes(ctx context.Context, c clientset.Interface) *corev1.NodeList { 67 selector := labels.Set{controlPlaneLabel: ""}.AsSelector() 68 cpNodes, err := c.CoreV1().Nodes(). 69 List(ctx, metav1.ListOptions{LabelSelector: selector.String()}) 70 framework.ExpectNoError(err, "error reading control-plane nodes") 71 return cpNodes 72 }