feat(util): add LeaderGate runtime fence for Active/Standby HA mode#378
Open
Priyanshubhartistm wants to merge 1 commit into
Open
feat(util): add LeaderGate runtime fence for Active/Standby HA mode#378Priyanshubhartistm wants to merge 1 commit into
Priyanshubhartistm wants to merge 1 commit into
Conversation
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
First scaffolding PR for the Active/Standby HA project (#305, #294). No behaviour change in the default mode-that's the point.
what i did
Added a LeaderGate interface in util/leader_gate.go. Every mutating helper in util/reconciliation_utility.go and util/cleanup_utility.go now calls requireLeader(ctx) before touching the API. Covers CreateResource, UpdateResource, UpdateStatus, DeleteResource, AddFinalizer, RemoveFinalizer, plus the three cleanup variants.
Two implementations
new flag
--ha-mode={disabled,active,standby}
default: disabled
If --ha-mode != disabled without --leader-elect=true, the process exits at startup. Felt safer than silently allowing a split-brain.
why funnel-level fencing instead of per-call-site
I chose to gate inside the util helpers, not at the call sites. Two reasons:
This is the defence-in-depth idea @Elvand-Lie raised in the #305 thread - manager-level fence AND service-level fence.
tests
util/leader_gate_test.go
Run:
go build ./...
go test -race -count=1 ./util/...
Covers:
edge cases I handled
what i deliberately did NOT do here
what's next
Follow-up PRs will land the ControllerLease CRD plus a resourcelock.Interface adapter (so two controller clusters can compete for the lease via a witness worker), the state mirror controller for the six controller CRDs, and the promotion controller with pre-promotion sanity checks. This PR is the foundation those sit on.