@@ -48,15 +48,32 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
48
48
testNamespace * v1.Namespace
49
49
)
50
50
const (
51
- namespaceName = "openshift-validation-webhook"
52
- serviceName = "validation-webhook"
53
- daemonsetName = "validation-webhook"
54
- configMapName = "webhook-cert"
55
- secretName = "webhook-cert"
56
- saName = "webhook-sa"
57
- testNsName = "osde2e-temp-ns"
51
+ namespaceName = "openshift-validation-webhook"
52
+ serviceName = "validation-webhook"
53
+ daemonsetName = "validation-webhook"
54
+ configMapName = "webhook-cert"
55
+ secretName = "webhook-cert"
56
+ testNsName = "osde2e-temp-ns"
57
+ privilegedNamespace = "openshift-backplane"
58
+ unprivilegedNamespace = "openshift-logging"
58
59
)
59
60
61
+ createNS := func (ns string ) {
62
+ testNamespace = & v1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : ns }}
63
+ err := client .Create (context .TODO (), testNamespace )
64
+ By ("checking the custom namespace exists" )
65
+ err = wait .For (conditions .New (client .Resources ).ResourceMatch (testNamespace , func (object k8s.Object ) bool {
66
+ return true
67
+ }))
68
+ Expect (err ).ShouldNot (HaveOccurred (), "Unable to create test namespace" )
69
+ }
70
+
71
+ deleteNS := func (ns * v1.Namespace ) {
72
+ err := client .Delete (context .TODO (), ns )
73
+ err = wait .For (conditions .New (client .Resources ).ResourceDeleted (ns ))
74
+ Expect (err ).ShouldNot (HaveOccurred (), "Unable to delete test namespace" )
75
+ }
76
+
60
77
BeforeAll (func () {
61
78
log .SetLogger (GinkgoLogr )
62
79
var err error
@@ -134,6 +151,8 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
134
151
135
152
err := client .Create (context .TODO (), pod )
136
153
Expect (err ).NotTo (HaveOccurred ())
154
+ err = client .Delete (ctx , pod )
155
+ Expect (err ).NotTo (HaveOccurred ())
137
156
})
138
157
139
158
Describe ("sre-pod-validation" , Ordered , func () {
@@ -218,23 +237,16 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
218
237
}, SpecTimeout (createPodWaitDuration .Seconds ()+ deletePodWaitDuration .Seconds ()))
219
238
220
239
It ("allows cluster-admin to schedule pods onto master/infra nodes" , func (ctx context.Context ) {
221
- sa := & v1.ServiceAccount {}
222
-
223
- err := client .Get (ctx , saName , namespaceName , sa )
224
-
225
- if err == nil {
226
- err = client .Delete (ctx , sa )
227
- Expect (err ).ToNot (HaveOccurred (), "Failed to delete existing Service Account" )
228
- }
229
-
230
- sa = & v1.ServiceAccount {
240
+ sa := & v1.ServiceAccount {
231
241
ObjectMeta : metav1.ObjectMeta {
232
- Name : saName ,
242
+ Name : "webhook-sa" ,
233
243
Namespace : namespaceName ,
234
244
},
235
245
}
236
- err = client .Create (ctx , sa )
246
+ err : = client .Create (ctx , sa )
237
247
Expect (err ).ShouldNot (HaveOccurred (), "Unable to create service account" )
248
+ err = client .Delete (ctx , sa )
249
+ Expect (err ).ShouldNot (HaveOccurred (), "Unable to delete service account" )
238
250
239
251
pod = withNamespace (pod , privilegedNamespace )
240
252
err = client .Create (ctx , pod )
@@ -320,22 +332,18 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
320
332
)
321
333
322
334
BeforeAll (func (ctx context.Context ) {
323
- testNamespace = & v1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : testNsName }}
324
- err := client .Create (ctx , testNamespace )
325
- Expect (err ).ShouldNot (HaveOccurred (), "Unable to create test namespace" )
335
+ createNS (testNsName )
336
+ })
337
+
338
+ AfterAll (func (ctx context.Context ) {
339
+ deleteNS (testNamespace )
326
340
})
327
341
328
342
It ("only blocks configmap/user-ca-bundle changes" , func (ctx context.Context ) {
329
343
cm := & v1.ConfigMap {ObjectMeta : metav1.ObjectMeta {Name : "user-ca-bundle" , Namespace : "openshift-config" }}
330
344
err := dedicatedAdmink8s .Delete (ctx , cm )
331
345
Expect (errors .IsForbidden (err )).To (BeTrue (), "Expected to be forbidden from deleting user-ca-bundle ConfigMap" )
332
346
333
- By ("checking the custom namespace exists" )
334
- err = wait .For (conditions .New (client .Resources ).ResourceMatch (testNamespace , func (object k8s.Object ) bool {
335
- return true
336
- }))
337
- Expect (err ).ToNot (HaveOccurred ())
338
-
339
347
cm = & v1.ConfigMap {
340
348
ObjectMeta : metav1.ObjectMeta {Name : "test" , Namespace : testNsName },
341
349
Data : map [string ]string {"test" : "test" },
@@ -527,7 +535,7 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
527
535
Expect (err ).NotTo (HaveOccurred ())
528
536
}
529
537
530
- updateNamespace := func (ctx context.Context , name string , user string , groups ... string ) error {
538
+ updateNamespace := func (ctx context.Context , name , user string , groups ... string ) error {
531
539
userk8s , err := client .Impersonate (user , groups ... )
532
540
if err != nil {
533
541
return err
@@ -619,10 +627,11 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
619
627
rule := newPrometheusRule (privilegedNamespace )
620
628
err = client .Delete (ctx , rule )
621
629
Expect (err == nil || errors .IsNotFound (err )).To (BeTrue (), "Failed to ensure PrometheusRule deletion" )
630
+ createNS (testNsName )
622
631
})
623
632
624
633
AfterAll (func (ctx context.Context ) {
625
- client . Delete ( ctx , testNamespace )
634
+ deleteNS ( testNamespace )
626
635
})
627
636
628
637
DescribeTable (
0 commit comments