fix: watch Postgres CRs to resolve active-engine race condition#679
Merged
Conversation
When a new Postgres CR is created, both pgrator and naiserator reconcile simultaneously. If naiserator reads the Postgres CR before pgrator has set the active-engine annotation, naiserator enters a 30-minute retry loop (FailedPrepare). This adds a metadata-only watch on Postgres CRs that maps annotation changes back to the owning Application/Naisjob, triggering an immediate re-reconcile. The hash-based skip in the synchronizer ensures this is a no-op for apps that are already successfully synced. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Only react to Postgres CR updates where annotations actually changed. This avoids triggering namespace-wide app lists on status-only updates, which matters as the number of Postgres CRs grows across namespaces. Create/Delete events still pass through (correct behavior). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
mortenlj
reviewed
May 22, 2026
…data No need for a constructor function — it's only used at startup and controller-runtime doesn't mutate it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a new Postgres CR is created, both pgrator and naiserator reconcile simultaneously. If naiserator reads the Postgres CR before pgrator has set the
active-engineannotation, naiserator enters a 30-minute retry loop (FailedPrepare):Solution
Add a metadata-only Watch on
data.nais.io/v1 PostgresCRs in both the Application and Naisjob controllers. When pgrator persists theactive-engineannotation, the watch triggers a re-reconcile of any app/job in the same namespace whosespec.postgres.clusterNamematches.Safety
WatchesMetadata— no full Postgres spec is fetched, only annotations/labelsget;list;watchondata.nais.io/postgresCompanion PR
Closes #674