fix(pt): prepend CLUSTER_NAME for restart/reinit/switchover/failover (fixes #29)#30
Open
CrzMarvin wants to merge 1 commit into
Open
fix(pt): prepend CLUSTER_NAME for restart/reinit/switchover/failover (fixes #29)#30CrzMarvin wants to merge 1 commit into
CrzMarvin wants to merge 1 commit into
Conversation
`patronictl restart|reinit|switchover|failover` all require CLUSTER_NAME
as the first positional argument. Unlike `pause/resume/list`, the
`-c <config>` flag does NOT supply scope to these four subcommands —
without the cluster name they error with either:
- "Missing argument 'CLUSTER_NAME'"
- patronictl interpreting a member name as the cluster scope and
erroring out at the etcd permission boundary
- silently restarting the wrong member set when the pig wrapper drops
trailing positional args
The four Restart/Reinit/Switchover/Failover functions in
cli/patroni/patroni.go built `patronictl` args without prepending the
cluster scope. The misleading comment in `Restart` claimed `-c config`
auto-detects the cluster name — true for pause/resume/list, not for
these subcommands.
Fix:
- Add exported `GetClusterName(dbsu)` reading `scope:` from
/etc/patroni/patroni.yml with a DBSU fallback for the typical Pigsty
layout where the file is postgres:postgres 0640.
- Extract pure `buildRestartArgs / buildReinitArgs / buildSwitchoverArgs
/ buildFailoverArgs` helpers (testable without exec'ing patronictl).
- Have Restart/Reinit/Switchover/Failover resolve cluster name once at
the top, then delegate to the args builder + runPatronictl.
Tests:
- TestBuildRestartArgs (table-driven: nil opts / pending+force /
member+force / role filter) — verifies cluster appears at args[1] and
flag/positional layout matches patronictl's CLI contract.
- TestBuildReinitArgs / TestBuildSwitchoverArgs / TestBuildFailoverArgs
for the same shape.
- TestPatronictlPositionalContract is a regression guard documenting
the constraint: if a future refactor drops the prepend, this fails.
Fixes pgsty#29.
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
Fixes #29 —
pig pt restart,pig pt reinit,pig pt switchover, andpig pt failoverall fail because the underlyingpatronictlinvocation omits the requiredCLUSTER_NAMEpositional argument.Unlike
patronictl pause/resume/list, those four subcommands do not accept-c <config>as a substitute for scope — they requireCLUSTER_NAMEas the first positional argument.Reproduction (from #29)
Fix shape
GetClusterName(dbsu)incli/patroni/patroni.go— readsscope:from/etc/patroni/patroni.yml, falls back toutils.DBSUCommandOutput(dbsu, [\"cat\", DefaultConfigPath])for the typical Pigsty layout where the file ispostgres:postgres 0640.buildRestartArgs / buildReinitArgs / buildSwitchoverArgs / buildFailoverArgs— testable without exec'ing patronictl. Each prepends `cluster` immediately after the verb.Restart / Reinit / Switchover / Failovernow resolve the cluster name once at the top, then call their respective builder +runPatronictl.`cli/context/context.go` has a similar helper (`getPatroniClusterName`) — left untouched to keep this PR focused; happy to follow up with a refactor to reuse `GetClusterName` if you'd like.
Tests
`cli/patroni/patroni_test.go` extended:
Validation
Out of scope (kept minimal)