@@ -86,6 +86,7 @@ func (podStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
86
86
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
87
87
func (podStrategy ) PrepareForCreate (ctx context.Context , obj runtime.Object ) {
88
88
pod := obj .(* api.Pod )
89
+ pod .Generation = 1
89
90
pod .Status = api.PodStatus {
90
91
Phase : api .PodPending ,
91
92
QOSClass : qos .GetPodQOS (pod ),
@@ -104,6 +105,7 @@ func (podStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object
104
105
oldPod := old .(* api.Pod )
105
106
newPod .Status = oldPod .Status
106
107
podutil .DropDisabledPodFields (newPod , oldPod )
108
+ updatePodGeneration (newPod , oldPod )
107
109
}
108
110
109
111
// Validate validates a new pod.
@@ -260,6 +262,7 @@ func (podEphemeralContainersStrategy) PrepareForUpdate(ctx context.Context, obj,
260
262
261
263
* newPod = * dropNonEphemeralContainerUpdates (newPod , oldPod )
262
264
podutil .DropDisabledPodFields (newPod , oldPod )
265
+ updatePodGeneration (newPod , oldPod )
263
266
}
264
267
265
268
func (podEphemeralContainersStrategy ) ValidateUpdate (ctx context.Context , obj , old runtime.Object ) field.ErrorList {
@@ -334,6 +337,7 @@ func (podResizeStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.
334
337
* newPod = * dropNonResizeUpdates (newPod , oldPod )
335
338
podutil .MarkPodProposedForResize (oldPod , newPod )
336
339
podutil .DropDisabledPodFields (newPod , oldPod )
340
+ updatePodGeneration (newPod , oldPod )
337
341
}
338
342
339
343
func (podResizeStrategy ) ValidateUpdate (ctx context.Context , obj , old runtime.Object ) field.ErrorList {
@@ -975,3 +979,11 @@ func apparmorFieldForAnnotation(annotation string) *api.AppArmorProfile {
975
979
// length or if the annotation has an unrecognized value
976
980
return nil
977
981
}
982
+
983
+ // updatePodGeneration bumps metadata.generation if needed for any updates
984
+ // to the podspec.
985
+ func updatePodGeneration (newPod , oldPod * api.Pod ) {
986
+ if ! apiequality .Semantic .DeepEqual (newPod .Spec , oldPod .Spec ) {
987
+ newPod .Generation ++
988
+ }
989
+ }
0 commit comments