@@ -166,14 +166,16 @@ func MergePodSpecUpdates(ctx context.Context, current *corev1.PodSpec, revised *
166
166
}
167
167
}
168
168
169
- if current .TerminationGracePeriodSeconds != nil && revised .TerminationGracePeriodSeconds != nil {
170
- if * current .TerminationGracePeriodSeconds != * revised .TerminationGracePeriodSeconds {
171
- scopedLog .Info ("Pod TerminationGracePeriodSeconds differs" ,
172
- "current" , current .TerminationGracePeriodSeconds ,
173
- "revised" , revised .TerminationGracePeriodSeconds )
174
- current .TerminationGracePeriodSeconds = revised .TerminationGracePeriodSeconds
175
- result = true
176
- }
169
+ if (current .TerminationGracePeriodSeconds == nil && revised .TerminationGracePeriodSeconds != nil ) ||
170
+ (current .TerminationGracePeriodSeconds != nil && revised .TerminationGracePeriodSeconds == nil ) ||
171
+ (current .TerminationGracePeriodSeconds != nil && revised .TerminationGracePeriodSeconds != nil &&
172
+ * current .TerminationGracePeriodSeconds != * revised .TerminationGracePeriodSeconds ) {
173
+
174
+ scopedLog .Info ("Pod TerminationGracePeriodSeconds differs" ,
175
+ "current" , current .TerminationGracePeriodSeconds ,
176
+ "revised" , revised .TerminationGracePeriodSeconds )
177
+ current .TerminationGracePeriodSeconds = revised .TerminationGracePeriodSeconds
178
+ result = true
177
179
}
178
180
179
181
// check for changes in container images; assume that the ordering is same for pods with > 1 container
@@ -254,14 +256,44 @@ func MergePodSpecUpdates(ctx context.Context, current *corev1.PodSpec, revised *
254
256
current .Containers [idx ].StartupProbe = revised .Containers [idx ].StartupProbe
255
257
result = true
256
258
}
257
- setPreStopLifecycleHandler (current , idx )
259
+
260
+ // check PreStop Lifecycle
261
+ if hasPreStopChanged (current .Containers [idx ].Lifecycle , revised .Containers [idx ].Lifecycle ) {
262
+ scopedLog .Info ("Pod Container PreStop Lifecycle differ" ,
263
+ "current" , current .Containers [idx ].Lifecycle ,
264
+ "revised" , revised .Containers [idx ].Lifecycle )
265
+ setPreStopLifecycleHandler (current , idx )
266
+ result = true
267
+ }
258
268
}
259
269
}
260
270
261
271
return result
262
272
}
263
273
264
- // set the PreStop lifecycle handler for the specified container index
274
+ // Function to check if PreStop Lifecycle has changed
275
+ func hasPreStopChanged (current , revised * corev1.Lifecycle ) bool {
276
+ // If both are nil, there's no change
277
+ if current == nil && revised == nil {
278
+ return false
279
+ }
280
+
281
+ // If one is nil and the other isn't, there's a change
282
+ if (current == nil || current .PreStop == nil || current .PreStop .Exec == nil ) &&
283
+ (revised != nil && revised .PreStop != nil && revised .PreStop .Exec != nil ) {
284
+ return true
285
+ }
286
+
287
+ if (revised == nil || revised .PreStop == nil || revised .PreStop .Exec == nil ) &&
288
+ (current != nil && current .PreStop != nil && current .PreStop .Exec != nil ) {
289
+ return true
290
+ }
291
+
292
+ // If both are non-nil, compare the command
293
+ return ! reflect .DeepEqual (current .PreStop .Exec .Command , revised .PreStop .Exec .Command )
294
+ }
295
+
296
+ // Set the PreStop lifecycle handler for the specified container index
265
297
func setPreStopLifecycleHandler (podSpec * corev1.PodSpec , idx int ) {
266
298
podSpec .Containers [idx ].Lifecycle = & corev1.Lifecycle {
267
299
PreStop : & corev1.LifecycleHandler {
0 commit comments