diff --git a/pkg/registry/core/pod/strategy.go b/pkg/registry/core/pod/strategy.go index 2022873d4ee..de4d23ee70e 100644 --- a/pkg/registry/core/pod/strategy.go +++ b/pkg/registry/core/pod/strategy.go @@ -247,11 +247,7 @@ var EphemeralContainersStrategy = podEphemeralContainersStrategy{Strategy} // dropNonEphemeralContainerUpdates discards all changes except for pod.Spec.EphemeralContainers and certain metadata func dropNonEphemeralContainerUpdates(newPod, oldPod *api.Pod) *api.Pod { - pod := oldPod.DeepCopy() - pod.Name = newPod.Name - pod.Namespace = newPod.Namespace - pod.ResourceVersion = newPod.ResourceVersion - pod.UID = newPod.UID + pod := mungePod(newPod, oldPod) pod.Spec.EphemeralContainers = newPod.Spec.EphemeralContainers return pod } @@ -286,11 +282,7 @@ var ResizeStrategy = podResizeStrategy{Strategy} // dropNonPodResizeUpdates discards all changes except for pod.Spec.Containers[*].Resources,ResizePolicy and certain metadata func dropNonPodResizeUpdates(newPod, oldPod *api.Pod) *api.Pod { - pod := oldPod.DeepCopy() - pod.Name = newPod.Name - pod.Namespace = newPod.Namespace - pod.ResourceVersion = newPod.ResourceVersion - pod.UID = newPod.UID + pod := mungePod(newPod, oldPod) oldCtrToIndex := make(map[string]int) for idx, ctr := range pod.Spec.Containers { @@ -329,6 +321,17 @@ func (podResizeStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime. return nil } +// mungePod mutates metadata information of old pod with the new pod. +func mungePod(newPod, oldPod *api.Pod) *api.Pod { + pod := oldPod.DeepCopy() + pod.Name = newPod.Name + pod.Namespace = newPod.Namespace + pod.ResourceVersion = newPod.ResourceVersion + pod.UID = newPod.UID + + return pod +} + // GetAttrs returns labels and fields of a given object for filtering purposes. func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) { pod, ok := obj.(*api.Pod)