Skip to content

Commit d3548f4

Browse files
authored
Merge pull request kubernetes#130618 from natasha41575/dropDisabledPodStatusUpdates
call dropDisabledPodFields from pod status strategy
2 parents 949abfc + abdc760 commit d3548f4

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

pkg/registry/core/pod/strategy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ func (podStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.
226226
if newPod.Status.QOSClass == "" {
227227
newPod.Status.QOSClass = oldPod.Status.QOSClass
228228
}
229+
230+
podutil.DropDisabledPodFields(newPod, oldPod)
229231
}
230232

231233
func (podStatusStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {

pkg/registry/core/pod/strategy_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,3 +3325,85 @@ func TestEphemeralContainersPrepareForUpdate(t *testing.T) {
33253325
})
33263326
}
33273327
}
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

Comments
 (0)