etcdctl: connect to the same endpoint as the target to be maintained

The client may connect to a different endpint as the target to be
maintained. When auth is enabled, the target endpoint might haven't
finished applying the authentiation request, so it might reject the
corresponding maintenance request due to permission denied.

Signed-off-by: Benjamin Wang <wachao@vmware.com>
This commit is contained in:
Benjamin Wang 2022-11-03 04:55:27 +08:00
parent 7f46da223d
commit 74085136b3
2 changed files with 12 additions and 4 deletions

View File

@ -35,10 +35,11 @@ func NewDefragCommand() *cobra.Command {
}
func defragCommandFunc(cmd *cobra.Command, args []string) {
failures := 0
c := mustClientFromCmd(cmd)
cfg := clientConfigFromCmd(cmd)
for _, ep := range endpointsFromCluster(cmd) {
cfg.Endpoints = []string{ep}
c := mustClient(cfg)
ctx, cancel := commandCtx(cmd)
start := time.Now()
_, err := c.Defragment(ctx, ep)
@ -50,6 +51,7 @@ func defragCommandFunc(cmd *cobra.Command, args []string) {
} else {
fmt.Printf("Finished defragmenting etcd member[%s]. took %s\n", ep, d.String())
}
c.Close()
}
if failures != 0 {

View File

@ -191,14 +191,17 @@ type epStatus struct {
}
func epStatusCommandFunc(cmd *cobra.Command, args []string) {
c := mustClientFromCmd(cmd)
cfg := clientConfigFromCmd(cmd)
var statusList []epStatus
var err error
for _, ep := range endpointsFromCluster(cmd) {
cfg.Endpoints = []string{ep}
c := mustClient(cfg)
ctx, cancel := commandCtx(cmd)
resp, serr := c.Status(ctx, ep)
cancel()
c.Close()
if serr != nil {
err = serr
fmt.Fprintf(os.Stderr, "Failed to get the status of endpoint %s (%v)\n", ep, serr)
@ -220,14 +223,17 @@ type epHashKV struct {
}
func epHashKVCommandFunc(cmd *cobra.Command, args []string) {
c := mustClientFromCmd(cmd)
cfg := clientConfigFromCmd(cmd)
var hashList []epHashKV
var err error
for _, ep := range endpointsFromCluster(cmd) {
cfg.Endpoints = []string{ep}
c := mustClient(cfg)
ctx, cancel := commandCtx(cmd)
resp, serr := c.HashKV(ctx, ep, epHashKVRev)
cancel()
c.Close()
if serr != nil {
err = serr
fmt.Fprintf(os.Stderr, "Failed to get the hash of endpoint %s (%v)\n", ep, serr)