...

Source file src/sigs.k8s.io/controller-runtime/pkg/internal/testing/controlplane/plane_test.go

Documentation: sigs.k8s.io/controller-runtime/pkg/internal/testing/controlplane

     1  /*
     2  Copyright 2021 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 controlplane_test
    18  
    19  import (
    20  	"context"
    21  
    22  	. "github.com/onsi/ginkgo/v2"
    23  	. "github.com/onsi/gomega"
    24  	kauthn "k8s.io/api/authorization/v1"
    25  
    26  	"sigs.k8s.io/controller-runtime/pkg/client"
    27  	. "sigs.k8s.io/controller-runtime/pkg/internal/testing/controlplane"
    28  )
    29  
    30  var _ = Describe("Control Plane", func() {
    31  	It("should start and stop successfully with a default etcd & apiserver", func() {
    32  		plane := &ControlPlane{}
    33  		Expect(plane.Start()).To(Succeed())
    34  		Expect(plane.Stop()).To(Succeed())
    35  	})
    36  	It("should use the given etcd & apiserver when starting, if present", func() {
    37  		apiServer := &APIServer{}
    38  		etcd := &Etcd{}
    39  		plane := &ControlPlane{
    40  			APIServer: apiServer,
    41  			Etcd:      etcd,
    42  		}
    43  		Expect(plane.Start()).To(Succeed())
    44  		defer func() { Expect(plane.Stop()).To(Succeed()) }()
    45  
    46  		Expect(plane.APIServer).To(BeIdenticalTo(apiServer))
    47  		Expect(plane.Etcd).To(BeIdenticalTo(etcd))
    48  	})
    49  
    50  	It("should be able to restart", func() {
    51  		// NB(directxman12): currently restarting invalidates all current users
    52  		// when using CertAuthn.  We need to support restarting as per our previous
    53  		// contract, but it's not clear how much else we actually need to handle, or
    54  		// whether or not this is a safe operation.
    55  		plane := &ControlPlane{}
    56  		Expect(plane.Start()).To(Succeed())
    57  		Expect(plane.Stop()).To(Succeed())
    58  		Expect(plane.Start()).To(Succeed())
    59  		Expect(plane.Stop()).To(Succeed())
    60  	})
    61  
    62  	Context("after having started", func() {
    63  		var plane *ControlPlane
    64  		BeforeEach(func() {
    65  			plane = &ControlPlane{}
    66  			Expect(plane.Start()).To(Succeed())
    67  		})
    68  		AfterEach(func() {
    69  			Expect(plane.Stop()).To(Succeed())
    70  		})
    71  
    72  		It("should provision a working legacy user and legacy kubectl", func() {
    73  			By("grabbing the legacy kubectl")
    74  			Expect(plane.KubeCtl()).NotTo(BeNil())
    75  
    76  			By("grabbing the legacy REST config and testing it")
    77  			cfg, err := plane.RESTClientConfig()
    78  			Expect(err).NotTo(HaveOccurred(), "should be able to grab the legacy REST config")
    79  			cl, err := client.New(cfg, client.Options{})
    80  			Expect(err).NotTo(HaveOccurred(), "should be able to create a client")
    81  
    82  			sar := &kauthn.SelfSubjectAccessReview{
    83  				Spec: kauthn.SelfSubjectAccessReviewSpec{
    84  					ResourceAttributes: &kauthn.ResourceAttributes{
    85  						Verb:     "*",
    86  						Group:    "*",
    87  						Version:  "*",
    88  						Resource: "*",
    89  					},
    90  				},
    91  			}
    92  			Expect(cl.Create(context.Background(), sar)).To(Succeed(), "should be able to make a Self-SAR")
    93  			Expect(sar.Status.Allowed).To(BeTrue(), "admin user should be able to do everything")
    94  		})
    95  
    96  		// TODO(directxman12): more explicit tests for AddUser -- it's tested indirectly via the
    97  		// legacy user flow, but we should be explicit
    98  
    99  		Describe("adding users", func() {
   100  			PIt("should be able to provision new users that have a corresponding REST config and & kubectl", func() {
   101  
   102  			})
   103  
   104  			PIt("should produce a default base REST config if none is given to add", func() {
   105  
   106  			})
   107  		})
   108  	})
   109  })
   110  

View as plain text