mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 16:29:21 +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
|
// dropNonEphemeralContainerUpdates discards all changes except for pod.Spec.EphemeralContainers and certain metadata
|
||||||
func dropNonEphemeralContainerUpdates(newPod, oldPod *api.Pod) *api.Pod {
|
func dropNonEphemeralContainerUpdates(newPod, oldPod *api.Pod) *api.Pod {
|
||||||
pod := oldPod.DeepCopy()
|
pod := mungePod(newPod, oldPod)
|
||||||
pod.Name = newPod.Name
|
|
||||||
pod.Namespace = newPod.Namespace
|
|
||||||
pod.ResourceVersion = newPod.ResourceVersion
|
|
||||||
pod.UID = newPod.UID
|
|
||||||
pod.Spec.EphemeralContainers = newPod.Spec.EphemeralContainers
|
pod.Spec.EphemeralContainers = newPod.Spec.EphemeralContainers
|
||||||
return pod
|
return pod
|
||||||
}
|
}
|
||||||
@ -286,11 +282,7 @@ var ResizeStrategy = podResizeStrategy{Strategy}
|
|||||||
|
|
||||||
// dropNonPodResizeUpdates discards all changes except for pod.Spec.Containers[*].Resources,ResizePolicy and certain metadata
|
// dropNonPodResizeUpdates discards all changes except for pod.Spec.Containers[*].Resources,ResizePolicy and certain metadata
|
||||||
func dropNonPodResizeUpdates(newPod, oldPod *api.Pod) *api.Pod {
|
func dropNonPodResizeUpdates(newPod, oldPod *api.Pod) *api.Pod {
|
||||||
pod := oldPod.DeepCopy()
|
pod := mungePod(newPod, oldPod)
|
||||||
pod.Name = newPod.Name
|
|
||||||
pod.Namespace = newPod.Namespace
|
|
||||||
pod.ResourceVersion = newPod.ResourceVersion
|
|
||||||
pod.UID = newPod.UID
|
|
||||||
|
|
||||||
oldCtrToIndex := make(map[string]int)
|
oldCtrToIndex := make(map[string]int)
|
||||||
for idx, ctr := range pod.Spec.Containers {
|
for idx, ctr := range pod.Spec.Containers {
|
||||||
@ -329,6 +321,17 @@ func (podResizeStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.
|
|||||||
return nil
|
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.
|
// GetAttrs returns labels and fields of a given object for filtering purposes.
|
||||||
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
|
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
|
||||||
pod, ok := obj.(*api.Pod)
|
pod, ok := obj.(*api.Pod)
|
||||||
|
Loading…
Reference in New Issue
Block a user