@@ -3325,3 +3325,85 @@ func TestEphemeralContainersPrepareForUpdate(t *testing.T) {
3325
3325
})
3326
3326
}
3327
3327
}
3328
+
3329
+ func TestStatusPrepareForUpdate (t * testing.T ) {
3330
+ testCases := []struct {
3331
+ description string
3332
+ oldPod * api.Pod
3333
+ newPod * api.Pod
3334
+ expected * api.Pod
3335
+ }{
3336
+ {
3337
+ description : "preserve old owner references" ,
3338
+ oldPod : & api.Pod {
3339
+ ObjectMeta : metav1.ObjectMeta {
3340
+ Name : "pod" ,
3341
+ OwnerReferences : []metav1.OwnerReference {{APIVersion : "v1" , Kind : "ReplicaSet" , Name : "rs-1" }},
3342
+ },
3343
+ },
3344
+ newPod : & api.Pod {
3345
+ ObjectMeta : metav1.ObjectMeta {
3346
+ Name : "pod" ,
3347
+ OwnerReferences : []metav1.OwnerReference {{APIVersion : "v1" , Kind : "ReplicaSet" , Name : "rs-2" }},
3348
+ },
3349
+ },
3350
+ expected : & api.Pod {
3351
+ ObjectMeta : metav1.ObjectMeta {
3352
+ Name : "pod" ,
3353
+ OwnerReferences : []metav1.OwnerReference {{APIVersion : "v1" , Kind : "ReplicaSet" , Name : "rs-1" }},
3354
+ },
3355
+ },
3356
+ },
3357
+ {
3358
+ description : "preserve old qos if empty" ,
3359
+ oldPod : & api.Pod {
3360
+ ObjectMeta : metav1.ObjectMeta {Name : "pod" },
3361
+ Status : api.PodStatus {
3362
+ QOSClass : "Guaranteed" ,
3363
+ },
3364
+ },
3365
+ newPod : & api.Pod {
3366
+ ObjectMeta : metav1.ObjectMeta {Name : "pod" },
3367
+ },
3368
+ expected : & api.Pod {
3369
+ ObjectMeta : metav1.ObjectMeta {Name : "pod" },
3370
+ Status : api.PodStatus {
3371
+ QOSClass : "Guaranteed" ,
3372
+ },
3373
+ },
3374
+ },
3375
+ {
3376
+ description : "drop disabled status fields" ,
3377
+ oldPod : & api.Pod {
3378
+ ObjectMeta : metav1.ObjectMeta {Name : "pod" },
3379
+ Status : api.PodStatus {},
3380
+ },
3381
+ newPod : & api.Pod {
3382
+ ObjectMeta : metav1.ObjectMeta {Name : "pod" },
3383
+ Status : api.PodStatus {
3384
+ ResourceClaimStatuses : []api.PodResourceClaimStatus {
3385
+ {Name : "my-claim" , ResourceClaimName : ptr .To ("pod-my-claim" )},
3386
+ },
3387
+ ContainerStatuses : []api.ContainerStatus {
3388
+ {Resources : & api.ResourceRequirements {}},
3389
+ },
3390
+ },
3391
+ },
3392
+ expected : & api.Pod {
3393
+ ObjectMeta : metav1.ObjectMeta {Name : "pod" },
3394
+ Status : api.PodStatus {
3395
+ ContainerStatuses : []api.ContainerStatus {{}},
3396
+ },
3397
+ },
3398
+ },
3399
+ }
3400
+
3401
+ for _ , tc := range testCases {
3402
+ t .Run (tc .description , func (t * testing.T ) {
3403
+ StatusStrategy .PrepareForUpdate (genericapirequest .NewContext (), tc .newPod , tc .oldPod )
3404
+ if ! cmp .Equal (tc .expected , tc .newPod ) {
3405
+ t .Errorf ("StatusStrategy.PrepareForUpdate() diff = %v" , cmp .Diff (tc .expected , tc .newPod ))
3406
+ }
3407
+ })
3408
+ }
3409
+ }
0 commit comments