@@ -329,14 +329,19 @@ func TestAdmitPreferNonmutating(t *testing.T) {
329
329
changedPod := unprivilegedRunAsAnyPod .DeepCopy ()
330
330
changedPod .Spec .Containers [0 ].Image = "myimage2"
331
331
332
+ podWithSC := unprivilegedRunAsAnyPod .DeepCopy ()
333
+ podWithSC .Annotations = map [string ]string {psputil .ValidatedPSPAnnotation : privilegedPSP .Name }
334
+ changedPodWithSC := changedPod .DeepCopy ()
335
+ changedPodWithSC .Annotations = map [string ]string {psputil .ValidatedPSPAnnotation : privilegedPSP .Name }
336
+
332
337
gcChangedPod := unprivilegedRunAsAnyPod .DeepCopy ()
333
338
gcChangedPod .OwnerReferences = []metav1.OwnerReference {{Kind : "Foo" , Name : "bar" }}
334
339
gcChangedPod .Finalizers = []string {"foo" }
335
340
336
341
tests := map [string ]struct {
337
342
operation kadmission.Operation
338
343
pod * kapi.Pod
339
- oldPod * kapi.Pod
344
+ podBeforeUpdate * kapi.Pod
340
345
psps []* extensions.PodSecurityPolicy
341
346
shouldPassAdmit bool
342
347
shouldPassValidate bool
@@ -380,8 +385,8 @@ func TestAdmitPreferNonmutating(t *testing.T) {
380
385
},
381
386
"pod should prefer non-mutating PSP on update" : {
382
387
operation : kadmission .Update ,
383
- pod : unprivilegedRunAsAnyPod .DeepCopy (),
384
- oldPod : changedPod .DeepCopy (),
388
+ pod : changedPodWithSC .DeepCopy (),
389
+ podBeforeUpdate : podWithSC .DeepCopy (),
385
390
psps : []* extensions.PodSecurityPolicy {mutating2 , mutating1 , privilegedPSP },
386
391
shouldPassAdmit : true ,
387
392
shouldPassValidate : true ,
@@ -390,12 +395,12 @@ func TestAdmitPreferNonmutating(t *testing.T) {
390
395
expectedContainerUser : nil ,
391
396
expectedPSP : privilegedPSP .Name ,
392
397
},
393
- "pod should not allow mutation on update" : {
398
+ "pod should not mutate on update, but fail validation " : {
394
399
operation : kadmission .Update ,
395
- pod : unprivilegedRunAsAnyPod .DeepCopy (),
396
- oldPod : changedPod .DeepCopy (),
400
+ pod : changedPod .DeepCopy (),
401
+ podBeforeUpdate : unprivilegedRunAsAnyPod .DeepCopy (),
397
402
psps : []* extensions.PodSecurityPolicy {mutating2 , mutating1 },
398
- shouldPassAdmit : false ,
403
+ shouldPassAdmit : true ,
399
404
shouldPassValidate : false ,
400
405
expectMutation : false ,
401
406
expectedPodUser : nil ,
@@ -405,7 +410,7 @@ func TestAdmitPreferNonmutating(t *testing.T) {
405
410
"pod should be allowed if completely unchanged on update" : {
406
411
operation : kadmission .Update ,
407
412
pod : unprivilegedRunAsAnyPod .DeepCopy (),
408
- oldPod : unprivilegedRunAsAnyPod .DeepCopy (),
413
+ podBeforeUpdate : unprivilegedRunAsAnyPod .DeepCopy (),
409
414
psps : []* extensions.PodSecurityPolicy {mutating2 , mutating1 },
410
415
shouldPassAdmit : true ,
411
416
shouldPassValidate : true ,
@@ -416,8 +421,8 @@ func TestAdmitPreferNonmutating(t *testing.T) {
416
421
},
417
422
"pod should be allowed if unchanged on update except finalizers,ownerrefs" : {
418
423
operation : kadmission .Update ,
419
- pod : unprivilegedRunAsAnyPod .DeepCopy (),
420
- oldPod : gcChangedPod .DeepCopy (),
424
+ pod : gcChangedPod .DeepCopy (),
425
+ podBeforeUpdate : unprivilegedRunAsAnyPod .DeepCopy (),
421
426
psps : []* extensions.PodSecurityPolicy {mutating2 , mutating1 },
422
427
shouldPassAdmit : true ,
423
428
shouldPassValidate : true ,
@@ -429,7 +434,7 @@ func TestAdmitPreferNonmutating(t *testing.T) {
429
434
}
430
435
431
436
for k , v := range tests {
432
- testPSPAdmitAdvanced (k , v .operation , v .psps , v .pod , v .oldPod , v .shouldPassAdmit , v .shouldPassValidate , v .expectMutation , v .expectedPSP , t )
437
+ testPSPAdmitAdvanced (k , v .operation , v .psps , v .pod , v .podBeforeUpdate , v .shouldPassAdmit , v .shouldPassValidate , v .expectMutation , v .expectedPSP , t )
433
438
434
439
if v .shouldPassAdmit {
435
440
actualPodUser := (* int64 )(nil )
0 commit comments