diff --git a/etcdctl/ctlv3/command/defrag_command.go b/etcdctl/ctlv3/command/defrag_command.go index 5ebf4483d..dfccafb74 100644 --- a/etcdctl/ctlv3/command/defrag_command.go +++ b/etcdctl/ctlv3/command/defrag_command.go @@ -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 { diff --git a/etcdctl/ctlv3/command/ep_command.go b/etcdctl/ctlv3/command/ep_command.go index 6abfef397..0964f564c 100644 --- a/etcdctl/ctlv3/command/ep_command.go +++ b/etcdctl/ctlv3/command/ep_command.go @@ -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)