Skip to content
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

[release-3.5]etcdctl: allow move-leader to connect to multiple endpoints #14434

Merged
merged 1 commit into from Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions etcdctl/ctlv3/command/move_leader_command.go
Expand Up @@ -43,7 +43,8 @@ func transferLeadershipCommandFunc(cmd *cobra.Command, args []string) {
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
}

c := mustClientFromCmd(cmd)
cfg := clientConfigFromCmd(cmd)
c := cfg.mustClient()
eps := c.Endpoints()
c.Close()

Expand All @@ -53,7 +54,6 @@ func transferLeadershipCommandFunc(cmd *cobra.Command, args []string) {
var leaderCli *clientv3.Client
var leaderID uint64
for _, ep := range eps {
cfg := clientConfigFromCmd(cmd)
cfg.endpoints = []string{ep}
cli := cfg.mustClient()
resp, serr := cli.Status(ctx, ep)
Expand Down
33 changes: 27 additions & 6 deletions tests/e2e/ctl_v3_move_leader_test.go
Expand Up @@ -27,15 +27,31 @@ import (
"go.etcd.io/etcd/client/v3"
)

func TestCtlV3MoveLeaderSecure(t *testing.T) {
testCtlV3MoveLeader(t, *newConfigTLS())
}
func TestCtlV3MoveLeaderScenarios(t *testing.T) {
securityParent := map[string]struct {
cfg etcdProcessClusterConfig
}{
"Secure": {cfg: *newConfigTLS()},
"Insecure": {cfg: *newConfigNoTLS()},
}

func TestCtlV3MoveLeaderInsecure(t *testing.T) {
testCtlV3MoveLeader(t, *newConfigNoTLS())
tests := map[string]struct {
env map[string]string
}{
"happy path": {env: map[string]string{}},
"with env": {env: map[string]string{"ETCDCTL_ENDPOINTS": "something-else-is-set"}},
}

for testName, tc := range securityParent {
for subTestName, tx := range tests {
t.Run(testName+" "+subTestName, func(t *testing.T) {
testCtlV3MoveLeader(t, tc.cfg, tx.env)
})
}
}
}

func testCtlV3MoveLeader(t *testing.T, cfg etcdProcessClusterConfig) {
func testCtlV3MoveLeader(t *testing.T, cfg etcdProcessClusterConfig, envVars map[string]string) {
BeforeTest(t)

epc := setupEtcdctlTest(t, &cfg, true)
Expand Down Expand Up @@ -94,6 +110,7 @@ func testCtlV3MoveLeader(t *testing.T, cfg etcdProcessClusterConfig) {
cfg: *newConfigNoTLS(),
dialTimeout: 7 * time.Second,
epc: epc,
envMap: envVars,
}

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