...

Source file src/k8s.io/kubernetes/test/e2e_kubeadm/nodes_test.go

Documentation: k8s.io/kubernetes/test/e2e_kubeadm

     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  	rbacv1 "k8s.io/api/rbac/v1"
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/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  	nodesGroup                                 = "system:nodes"
    33  	nodesCertificateRotationClusterRoleName    = "system:certificates.k8s.io:certificatesigningrequests:selfnodeclient"
    34  	nodesCertificateRotationClusterRoleBinding = "kubeadm:node-autoapprove-certificate-rotation"
    35  	nodesCRISocketAnnotation                   = "kubeadm.alpha.kubernetes.io/cri-socket"
    36  )
    37  
    38  // Define container for all the test specification aimed at verifying
    39  // that kubeadm configures the nodes and system:nodes group as expected
    40  var _ = Describe("nodes", func() {
    41  
    42  	// Get an instance of the k8s test framework
    43  	f := framework.NewDefaultFramework("nodes")
    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  	ginkgo.It("should have CRI annotation", func(ctx context.Context) {
    51  		nodes, err := f.ClientSet.CoreV1().Nodes().
    52  			List(ctx, metav1.ListOptions{})
    53  		framework.ExpectNoError(err, "error reading nodes")
    54  
    55  		// Checks that the nodes have the CRI socket annotation
    56  		// and that it is prefixed with a URL scheme
    57  		for _, node := range nodes.Items {
    58  			gomega.Expect(node.Annotations).To(gomega.HaveKey(nodesCRISocketAnnotation))
    59  			gomega.Expect(node.Annotations[nodesCRISocketAnnotation]).To(gomega.HavePrefix("unix://"))
    60  		}
    61  	})
    62  
    63  	ginkgo.It("should be allowed to rotate CSR", func(ctx context.Context) {
    64  		// Nb. this is technically implemented a part of the bootstrap-token phase
    65  		ExpectClusterRoleBindingWithSubjectAndRole(f.ClientSet,
    66  			nodesCertificateRotationClusterRoleBinding,
    67  			rbacv1.GroupKind, nodesGroup,
    68  			nodesCertificateRotationClusterRoleName,
    69  		)
    70  	})
    71  })
    72  

View as plain text