Skip to content

[fix] ensure consistent hook sorting by name#753

Merged
ipaqsa merged 1 commit intomainfrom
fix/synchronization-hooks-order
Apr 24, 2026
Merged

[fix] ensure consistent hook sorting by name#753
ipaqsa merged 1 commit intomainfrom
fix/synchronization-hooks-order

Conversation

@fuldaxxx
Copy link
Copy Markdown
Contributor

@fuldaxxx fuldaxxx commented Apr 23, 2026

Overview

Improve hook sorting by adding a secondary sort criterion based on hook names when orders are equal. This ensures consistent ordering of hooks with the same order value.

What this PR does / why we need it

Hooks with the same Order value were executed in a non-deterministic order. This matters because an earlier hook can perform a check and set a value, allowing subsequent hooks to skip the check and simply read that value — but this pattern breaks when execution order is unpredictable.
The fix adds a secondary sort by hook name when Order values are equal, so hooks with the same priority are now always executed in alphabetical order.

Before:

~ kubectl logs -n d8-system deploy/deckhouse | grep 'kubernetesSynchronization' |   grep '"module":"r-g-test"' | jq -r '.hook'

hooks/batchhooks:batch/c-test:2
hooks/batchhooks:batch/e-test:4
hooks/batchhooks:batch/f-test:5
hooks/batchhooks:batch/g-test:6
hooks/batchhooks:batch/h-test:7
hooks/batchhooks:batch/a-test:0
hooks/batchhooks:batch/d-test:3
hooks/batchhooks:batch/b-test:1

After:

~ kubectl logs -n d8-system deploy/deckhouse | grep 'kubernetesSynchronization' |   grep '"module":"r-g-test"' | jq -r '.hook'

hooks/batchhooks:batch/a-test:0
hooks/batchhooks:batch/b-test:1
hooks/batchhooks:batch/c-test:2
hooks/batchhooks:batch/d-test:3
hooks/batchhooks:batch/e-test:4
hooks/batchhooks:batch/f-test:5
hooks/batchhooks:batch/g-test:6
hooks/batchhooks:batch/h-test:7

Improve hook sorting by adding a secondary sort criterion based on
hook names when orders are equal. This ensures consistent ordering
of hooks with the same order value.
@fuldaxxx fuldaxxx requested a review from ipaqsa April 23, 2026 13:06
@fuldaxxx fuldaxxx self-assigned this Apr 23, 2026
@fuldaxxx fuldaxxx requested a review from ldmonster April 23, 2026 13:14
@ipaqsa ipaqsa added bug Something isn't working go Pull requests that update Go code release-note/bug Something isn't working labels Apr 23, 2026
@fuldaxxx fuldaxxx marked this pull request as ready for review April 23, 2026 15:37
@ipaqsa ipaqsa changed the title [addon-operator] fix: ensure consistent hook sorting by name [fix] ensure consistent hook sorting by name Apr 24, 2026
@ipaqsa ipaqsa merged commit 4af4ce1 into main Apr 24, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update Go code release-note/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants