-
Notifications
You must be signed in to change notification settings - Fork 92
OADP-7541: fix non-deterministic matchExpressions ordering causing node-agent restarts #2234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: oadp-dev
Are you sure you want to change the base?
Changes from all commits
98be8e3
987bfb2
7c88cb6
516587c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "cmp" | ||
| "fmt" | ||
| "regexp" | ||
| "slices" | ||
| "sort" | ||
| "strings" | ||
|
|
||
|
|
@@ -374,3 +376,18 @@ func UpdateBackupStorageLocation(bsl *velerov1.BackupStorageLocation, bslSpec ve | |
|
|
||
| return nil | ||
| } | ||
|
|
||
| // SortNodeSelectorTerms sorts MatchExpressions and MatchFields by key | ||
| // within each NodeSelectorTerm to ensure deterministic ordering. Without | ||
| // this, Go map iteration randomness in upstream kube.ToSystemAffinity | ||
| // produces non-deterministic ordering, which Kubernetes treats as a spec | ||
| // change and triggers unnecessary DaemonSet rollouts. | ||
| func SortNodeSelectorTerms(terms []corev1.NodeSelectorTerm) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SortNodeSelectorTerms only sorts MatchExpressions but the name suggests it handles the full NodeSelectorTerm. Two options:
I'd lean toward option 1 since it's trivial and future-proofs us if MatchFields ever comes into play.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call — added Note Responses generated with Claude |
||
| cmpKey := func(a, b corev1.NodeSelectorRequirement) int { | ||
| return cmp.Compare(a.Key, b.Key) | ||
| } | ||
| for i := range terms { | ||
| slices.SortFunc(terms[i].MatchExpressions, cmpKey) | ||
| slices.SortFunc(terms[i].MatchFields, cmpKey) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered filing an upstream Velero issue (or PR) to sort there? That would fix it for all consumers, not just OADP. This workaround is fine to merge now, but an upstream fix would let us eventually drop it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.