nodes_test.go 2.3 KB

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