mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
refactor logic to override pod fields
This commit is contained in:
parent
878c54fc9a
commit
07ca0b09bb
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user