Skip to content

Commit 243b7a1

Browse files
committed
etcdctl: fix move-leader for multiple endpoints
Due to a duplicate call of clientConfigFromCmd, the move-leader command would fail with "conflicting environment variable is shadowed by corresponding command-line flag". Also in scenarios where no command-line flag was supplied. Signed-off-by: Thomas Jungblut <[email protected]>
1 parent 204c031 commit 243b7a1

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

etcdctl/ctlv3/command/move_leader_command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ func transferLeadershipCommandFunc(cmd *cobra.Command, args []string) {
4343
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
4444
}
4545

46-
c := mustClientFromCmd(cmd)
46+
cfg := clientConfigFromCmd(cmd)
47+
c := cfg.mustClient()
4748
eps := c.Endpoints()
4849
c.Close()
4950

@@ -53,7 +54,6 @@ func transferLeadershipCommandFunc(cmd *cobra.Command, args []string) {
5354
var leaderCli *clientv3.Client
5455
var leaderID uint64
5556
for _, ep := range eps {
56-
cfg := clientConfigFromCmd(cmd)
5757
cfg.endpoints = []string{ep}
5858
cli := cfg.mustClient()
5959
resp, serr := cli.Status(ctx, ep)

tests/e2e/ctl_v3_move_leader_test.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,31 @@ import (
2727
"go.etcd.io/etcd/client/v3"
2828
)
2929

30-
func TestCtlV3MoveLeaderSecure(t *testing.T) {
31-
testCtlV3MoveLeader(t, *newConfigTLS())
32-
}
30+
func TestCtlV3MoveLeaderScenarios(t *testing.T) {
31+
securityParent := map[string]struct {
32+
cfg etcdProcessClusterConfig
33+
}{
34+
"Secure": {cfg: *newConfigTLS()},
35+
"Insecure": {cfg: *newConfigNoTLS()},
36+
}
3337

34-
func TestCtlV3MoveLeaderInsecure(t *testing.T) {
35-
testCtlV3MoveLeader(t, *newConfigNoTLS())
38+
tests := map[string]struct {
39+
env map[string]string
40+
}{
41+
"happy path": {env: map[string]string{}},
42+
"with env": {env: map[string]string{"ETCDCTL_ENDPOINTS": "something-else-is-set"}},
43+
}
44+
45+
for testName, tc := range securityParent {
46+
for subTestName, tx := range tests {
47+
t.Run(testName+" "+subTestName, func(t *testing.T) {
48+
testCtlV3MoveLeader(t, tc.cfg, tx.env)
49+
})
50+
}
51+
}
3652
}
3753

38-
func testCtlV3MoveLeader(t *testing.T, cfg etcdProcessClusterConfig) {
54+
func testCtlV3MoveLeader(t *testing.T, cfg etcdProcessClusterConfig, envVars map[string]string) {
3955
BeforeTest(t)
4056

4157
epc := setupEtcdctlTest(t, &cfg, true)
@@ -94,6 +110,7 @@ func testCtlV3MoveLeader(t *testing.T, cfg etcdProcessClusterConfig) {
94110
cfg: *newConfigNoTLS(),
95111
dialTimeout: 7 * time.Second,
96112
epc: epc,
113+
envMap: envVars,
97114
}
98115

99116
tests := []struct {
@@ -108,6 +125,10 @@ func testCtlV3MoveLeader(t *testing.T, cfg etcdProcessClusterConfig) {
108125
[]string{cx.epc.EndpointsV3()[leadIdx]},
109126
fmt.Sprintf("Leadership transferred from %s to %s", types.ID(leaderID), types.ID(transferee)),
110127
},
128+
{ // request to all endpoints
129+
cx.epc.EndpointsV3(),
130+
fmt.Sprintf("Leadership transferred"),
131+
},
111132
}
112133
for i, tc := range tests {
113134
prefix := cx.prefixArgs(tc.eps)

0 commit comments

Comments
 (0)