Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
fix: add configmap get before updating the annotations on the cm
Browse files Browse the repository at this point in the history
  • Loading branch information
jonwinton committed Nov 14, 2023
1 parent 636412f commit 4bfb606
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion controllers/mergesource_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,23 @@ func (r *MergeSourceReconciler) cleanUpWatchedByAnnotation(
func (r *MergeSourceReconciler) annotateWatchedByConfigMap(
ctx context.Context, cm *corev1.ConfigMap, name string,
) error {
return errors.WithStack(anns.Apply(ctx, r.Client, cm, watchedBy.AddToList(name)))
// Retrieve the latest copy of the configmap we're looking to update
// before triggering the update to prevent errors with updating a resource
// without the most recent changes
currentCm := &corev1.ConfigMap{}
err := r.Get(ctx, types.NamespacedName{
Namespace: cm.Namespace,
Name: cm.Name,
}, currentCm)
if err != nil {
// If not found, the ConfigMap has been deleted
if apierrors.IsNotFound(err) {
return nil
}
return errors.Wrapf(err, "error retrieving configmap %s for watched annotation update", cm.Name)
}

return errors.WithStack(anns.Apply(ctx, r.Client, currentCm, watchedBy.AddToList(name)))
}

type watchedConfigMap struct {
Expand Down

0 comments on commit 4bfb606

Please sign in to comment.