Skip to content

Commit fa27da7

Browse files
author
Moritz Clasmeier
committed
Do not ever update the status in case the generation has changed
1 parent c68e641 commit fa27da7

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

pkg/reconciler/internal/updater/updater.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (u *Updater) Apply(ctx context.Context, baseObj *unstructured.Unstructured)
144144
updateErr := u.client.Status().Update(ctx, obj)
145145
if errors.IsConflict(updateErr) && u.enableAggressiveConflictResolution {
146146
u.logger.V(1).Info("Status update conflict detected")
147-
resolved, resolveErr := u.tryRefresh(ctx, baseObj, isSafeForStatusUpdate)
147+
resolved, resolveErr := u.tryRefresh(ctx, baseObj, isSafeForUpdate)
148148
if resolveErr != nil {
149149
return resolveErr
150150
}
@@ -195,11 +195,17 @@ func (u *Updater) Apply(ctx context.Context, baseObj *unstructured.Unstructured)
195195
return err
196196
}
197197

198-
func isSafeForStatusUpdate(_ logr.Logger, _ *unstructured.Unstructured, _ *unstructured.Unstructured) bool {
199-
return true
200-
}
201-
202198
func isSafeForUpdate(logger logr.Logger, inMemory *unstructured.Unstructured, onCluster *unstructured.Unstructured) bool {
199+
if inMemory.GetGeneration() != onCluster.GetGeneration() {
200+
// Diff in generation. Nothing we can do about it -> Fail.
201+
logger.V(1).Info("Not refreshing object due to generation mismatch",
202+
"namespace", inMemory.GetNamespace(),
203+
"name", inMemory.GetName(),
204+
"gkv", inMemory.GroupVersionKind(),
205+
)
206+
return false
207+
}
208+
// Extra verification to make sure that the spec has not changed.
203209
if !reflect.DeepEqual(inMemory.Object["spec"], onCluster.Object["spec"]) {
204210
// Diff in object spec. Nothing we can do about it -> Fail.
205211
logger.V(1).Info("Not refreshing object due to spec mismatch",

0 commit comments

Comments
 (0)