Repository navigation
Conversation
Iterating over the node_readiness_label map produced the match expressions in random order. With two or more labels the generated affinity differed from the one in the running statefulset on every sync, so the operator kept replacing the statefulset and rolling the pods. Signed-off-by: YuMin Kim <yuminkim.dev@gmail.com>
yuminn-k
requested review from
FxKu,
Jan-M,
hughcapet,
idanovinda,
jopadi and
mikkeloscar
as code owners
November 1, 2026 00:40
This branch has not been deployed
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 description
nodeAffinity()builds the match expressions fornode_readiness_labelby ranging over the map, so the order changes from one call to the next. With two or more labels the generated affinity often differs from the one in the running statefulset.compareStatefulSetWithcompares the two withreflect.DeepEqual, reports "new statefulset's pod affinity does not match the current one" and replaces the statefulset. The pods roll and the master switches over on every sync.This change sorts the keys before building the match expressions, so the output is the same on every call. The pooler deployment and the logical backup job call the same function, so they get the fix too.
TestNodeAffinityReadinessLabelOrdercallsnodeAffinity()20 times with four readiness labels and checks the keys come out sorted every time. It fails on master and passes with this change.Linked issues
Fixes #2931
Checklist
Thanks for submitting a pull request to the Postgres Operator project.
Please, ensure your contribution matches the following items:
acid.zalan.doapi package.AI disclosure: Written with Claude Code (Claude Opus 5.5)
🤖 Generated with Claude Code