Merge pull request #130618 from natasha41575/dropDisabledPodStatusUpdates

call dropDisabledPodFields from pod status strategy
This commit is contained in:
Kubernetes Prow Robot 2025-03-06 11:53:44 -08:00 committed by GitHub
commit d3548f487d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 84 additions and 0 deletions

View File

@ -226,6 +226,8 @@ func (podStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.
if newPod.Status.QOSClass == "" {
newPod.Status.QOSClass = oldPod.Status.QOSClass
}
podutil.DropDisabledPodFields(newPod, oldPod)
}
func (podStatusStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {

View File

@ -3325,3 +3325,85 @@ func TestEphemeralContainersPrepareForUpdate(t *testing.T) {
})
}
}
func TestStatusPrepareForUpdate(t *testing.T) {
testCases := []struct {
description string
oldPod *api.Pod
newPod *api.Pod
expected *api.Pod
}{
{
description: "preserve old owner references",
oldPod: &api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod",
OwnerReferences: []metav1.OwnerReference{{APIVersion: "v1", Kind: "ReplicaSet", Name: "rs-1"}},
},
},
newPod: &api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod",
OwnerReferences: []metav1.OwnerReference{{APIVersion: "v1", Kind: "ReplicaSet", Name: "rs-2"}},
},
},
expected: &api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod",
OwnerReferences: []metav1.OwnerReference{{APIVersion: "v1", Kind: "ReplicaSet", Name: "rs-1"}},
},
},
},
{
description: "preserve old qos if empty",
oldPod: &api.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "pod"},
Status: api.PodStatus{
QOSClass: "Guaranteed",
},
},
newPod: &api.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "pod"},
},
expected: &api.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "pod"},
Status: api.PodStatus{
QOSClass: "Guaranteed",
},
},
},
{
description: "drop disabled status fields",
oldPod: &api.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "pod"},
Status: api.PodStatus{},
},
newPod: &api.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "pod"},
Status: api.PodStatus{
ResourceClaimStatuses: []api.PodResourceClaimStatus{
{Name: "my-claim", ResourceClaimName: ptr.To("pod-my-claim")},
},
ContainerStatuses: []api.ContainerStatus{
{Resources: &api.ResourceRequirements{}},
},
},
},
expected: &api.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "pod"},
Status: api.PodStatus{
ContainerStatuses: []api.ContainerStatus{{}},
},
},
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
StatusStrategy.PrepareForUpdate(genericapirequest.NewContext(), tc.newPod, tc.oldPod)
if !cmp.Equal(tc.expected, tc.newPod) {
t.Errorf("StatusStrategy.PrepareForUpdate() diff = %v", cmp.Diff(tc.expected, tc.newPod))
}
})
}
}