@@ -123,7 +123,7 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
123
123
Expect (err ).ToNot (HaveOccurred ())
124
124
})
125
125
126
- It ("should create a pod with the correct security context" , func () {
126
+ It ("should create a pod with the correct security context" , func (ctx context. Context ) {
127
127
pod := & v1.Pod {
128
128
ObjectMeta : metav1.ObjectMeta {
129
129
Name : "testpod" ,
@@ -149,29 +149,25 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
149
149
},
150
150
}
151
151
152
- err := client .Create (context . TODO () , pod )
152
+ err := client .Create (ctx , pod )
153
153
Expect (err ).NotTo (HaveOccurred ())
154
154
err = client .Delete (ctx , pod )
155
155
Expect (err ).NotTo (HaveOccurred ())
156
156
})
157
157
158
158
Describe ("sre-pod-validation" , Ordered , func () {
159
159
const (
160
- privilegedNamespace = "openshift-backplane"
161
- unprivilegedNamespace = "openshift-logging"
162
-
163
160
deletePodWaitDuration = 5 * time .Minute
164
161
createPodWaitDuration = 1 * time .Minute
165
162
)
166
163
167
164
var pod * v1.Pod
168
165
169
166
BeforeAll (func () {
170
- name := envconf .RandomName ("testpod" , 12 )
171
167
pod = & v1.Pod {
172
168
ObjectMeta : metav1.ObjectMeta {
173
- Name : name ,
174
- Namespace : testNsName ,
169
+ Name : envconf . RandomName ( "testpod" , 12 ) ,
170
+ Namespace : privilegedNamespace ,
175
171
},
176
172
Spec : v1.PodSpec {
177
173
Containers : []v1.Container {
@@ -220,20 +216,17 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
220
216
}
221
217
})
222
218
223
- withNamespace := func (pod * v1.Pod , namespace string ) * v1.Pod {
224
- pod .SetNamespace (namespace )
225
- return pod
226
- }
227
-
228
219
It ("blocks pods scheduled onto master/infra nodes" , func (ctx context.Context ) {
229
- err := dedicatedAdmink8s .Create (ctx , withNamespace ( pod , privilegedNamespace ) )
220
+ err := dedicatedAdmink8s .Create (ctx , pod )
230
221
Expect (errors .IsForbidden (err )).To (BeTrue ())
231
222
232
- err = userk8s .Create (ctx , withNamespace ( pod , privilegedNamespace ) )
223
+ err = userk8s .Create (ctx , pod )
233
224
Expect (errors .IsForbidden (err )).To (BeTrue ())
234
225
235
- err = userk8s .Create (ctx , withNamespace (pod , unprivilegedNamespace ))
226
+ pod .SetNamespace (unprivilegedNamespace )
227
+ err = userk8s .Create (ctx , pod )
236
228
Expect (errors .IsForbidden (err )).To (BeTrue ())
229
+ pod .SetNamespace (privilegedNamespace )
237
230
}, SpecTimeout (createPodWaitDuration .Seconds ()+ deletePodWaitDuration .Seconds ()))
238
231
239
232
It ("allows cluster-admin to schedule pods onto master/infra nodes" , func (ctx context.Context ) {
@@ -248,7 +241,6 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
248
241
err = client .Delete (ctx , sa )
249
242
Expect (err ).ShouldNot (HaveOccurred (), "Unable to delete service account" )
250
243
251
- pod = withNamespace (pod , privilegedNamespace )
252
244
err = client .Create (ctx , pod )
253
245
Expect (err ).NotTo (HaveOccurred ())
254
246
err = client .Delete (ctx , pod )
@@ -599,9 +591,6 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
599
591
})
600
592
601
593
Describe ("sre-prometheusrule-validation" , func () {
602
- const privilegedNamespace = "openshift-backplane"
603
- const unprivilegedNamespace = "openshift-logging"
604
-
605
594
newPrometheusRule := func (namespace string ) * monitoringv1.PrometheusRule {
606
595
return & monitoringv1.PrometheusRule {
607
596
ObjectMeta : metav1.ObjectMeta {Name : "prometheus-example-app" , Namespace : namespace },
@@ -665,7 +654,7 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
665
654
})
666
655
667
656
It ("allows non-privileged users to manage PrometheusRules in non-privileged namespaces" , func (ctx context.Context ) {
668
- rule := newPrometheusRule ("osde2e-temp-ns" )
657
+ rule := newPrometheusRule (testNsName )
669
658
670
659
err := dedicatedAdmink8s .Create (ctx , rule )
671
660
Expect (err ).NotTo (HaveOccurred ())
0 commit comments