controlplane_nodes_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package e2e_kubeadm
  14. import (
  15. corev1 "k8s.io/api/core/v1"
  16. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  17. "k8s.io/apimachinery/pkg/labels"
  18. clientset "k8s.io/client-go/kubernetes"
  19. "k8s.io/kubernetes/test/e2e/framework"
  20. . "github.com/onsi/ginkgo"
  21. . "github.com/onsi/gomega"
  22. )
  23. const (
  24. controlPlaneTaint = "node-role.kubernetes.io/master"
  25. )
  26. // Define container for all the test specification aimed at verifying
  27. // that kubeadm configures the control-plane node as expected
  28. var _ = KubeadmDescribe("control-plane node", func() {
  29. // Get an instance of the k8s test framework
  30. f := framework.NewDefaultFramework("control-plane node")
  31. // Tests in this container are not expected to create new objects in the cluster
  32. // so we are disabling the creation of a namespace in order to get a faster execution
  33. f.SkipNamespaceCreation = true
  34. // Important! please note that this test can't be run on single-node clusters
  35. // in case you can skip this test with SKIP=multi-node
  36. It("should be labelled and tainted [multi-node]", func() {
  37. // get all control-plane nodes (and this implicitly checks that node are properly labeled)
  38. controlPlanes := getControlPlaneNodes(f.ClientSet)
  39. // checks if there is at least one control-plane node
  40. Expect(controlPlanes.Items).NotTo(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", controlPlaneTaint)
  41. // checks that the control-plane nodes have the expected taint
  42. for _, cp := range controlPlanes.Items {
  43. framework.ExpectNodeHasTaint(f.ClientSet, cp.GetName(), &corev1.Taint{Key: controlPlaneTaint, Effect: corev1.TaintEffectNoSchedule})
  44. }
  45. })
  46. })
  47. func getControlPlaneNodes(c clientset.Interface) *corev1.NodeList {
  48. selector := labels.Set{controlPlaneTaint: ""}.AsSelector()
  49. masters, err := c.CoreV1().Nodes().
  50. List(metav1.ListOptions{LabelSelector: selector.String()})
  51. framework.ExpectNoError(err, "error reading control-plane nodes")
  52. return masters
  53. }