refactor logic to override pod fields

This commit is contained in:
Anish Shah 2024-10-22 19:38:20 -07:00
parent 878c54fc9a
commit 07ca0b09bb

View File

@ -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)