feat(operator): gate Service traffic on operator-set ready label#58
Merged
Conversation
The per-replica postgres Service used to route to any pod matching just `pgro.bes.au/restore=<active-name>`, which meant a new restore became reachable to external clients the moment its pod went Ready — including during the operator's Switching phase, before schema migration completes. External workloads that connect at that point can grab locks on the very schemas the operator is about to drop and rewrite, wedging the migration. Add a second label `pgro.bes.au/ready-for-traffic=true` to the Service selector, and have the operator only patch that label onto a restore's pod once it's safe for external traffic — after schema migration completes, immediately before the Service selector is pointed at the new restore. Until then, the new restore is unreachable via the Service even though its pod is healthy, so DDL prep runs without external interference. Also re-apply the label every Active reconcile pass so it's restored if a pod restart drops it, and so existing pre-upgrade Active pods get the label on the first reconcile after deploy.
e234c51 to
71bfb91
Compare
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.
🤖
Summary
Adds a second label `pgro.bes.au/ready-for-traffic=true` to the per-replica postgres Service's selector, and has the operator only patch that label onto a restore's pod once it's safe for external traffic. Until the operator sets the label, the new restore is unreachable via the Service even though its postgres pod is healthy — so DDL prep (DROP SCHEMA, schema-migration Job, etc.) runs without external clients racing to grab locks.
Why
Today the Service routes to any pod matching `pgro.bes.au/restore=`, which means a new restore becomes reachable the moment its pod goes Ready — including during the operator's `Switching` phase, before schema migration completes. External workloads (dbt sync, application connectors, etc.) that hit the Service during that window can start work on the very schemas the operator is about to drop and rewrite. Locks pile up, migration wedges, and only a pod restart clears the mess.
This change closes that hole structurally instead of relying on session-cleanup (which is the companion #57 belt-and-braces fix).
Shape
Test coverage
`tests/switchover.rs` already exercises the Service-selector rewrite during switchover. Added assertions that:
No new test file, so no integration matrix entry needed.
Caveats