nodes_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. rbacv1 "k8s.io/api/rbac/v1"
  16. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  17. "k8s.io/kubernetes/test/e2e/framework"
  18. . "github.com/onsi/ginkgo"
  19. . "github.com/onsi/gomega"
  20. )
  21. const (
  22. nodesGroup = "system:nodes"
  23. nodesCertificateRotationClusterRoleName = "system:certificates.k8s.io:certificatesigningrequests:selfnodeclient"
  24. nodesCertificateRotationClusterRoleBinding = "kubeadm:node-autoapprove-certificate-rotation"
  25. nodesCRISocketAnnotation = "kubeadm.alpha.kubernetes.io/cri-socket"
  26. )
  27. // Define container for all the test specification aimed at verifying
  28. // that kubeadm configures the nodes and system:nodes group as expected
  29. var _ = KubeadmDescribe("nodes", func() {
  30. // Get an instance of the k8s test framework
  31. f := framework.NewDefaultFramework("nodes")
  32. // Tests in this container are not expected to create new objects in the cluster
  33. // so we are disabling the creation of a namespace in order to get a faster execution
  34. f.SkipNamespaceCreation = true
  35. It("should have CRI annotation", func() {
  36. nodes, err := f.ClientSet.CoreV1().Nodes().
  37. List(metav1.ListOptions{})
  38. framework.ExpectNoError(err, "error reading nodes")
  39. // checks that the nodes have the CRI annotation
  40. for _, node := range nodes.Items {
  41. Expect(node.Annotations).To(HaveKey(nodesCRISocketAnnotation))
  42. }
  43. })
  44. It("should be allowed to rotate CSR", func() {
  45. // Nb. this is technically implemented a part of the bootstrap-token phase
  46. ExpectClusterRoleBindingWithSubjectAndRole(f.ClientSet,
  47. nodesCertificateRotationClusterRoleBinding,
  48. rbacv1.GroupKind, nodesGroup,
  49. nodesCertificateRotationClusterRoleName,
  50. )
  51. })
  52. })