...
1
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
52
53
54
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
97
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