From 721ed6ba2b5a265f063e2485c8b6a49697d78367 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Wed, 13 Apr 2016 11:31:47 -0700 Subject: [PATCH] etcdctl: return non-zero exit code if defrag fails on any endpoint --- etcdctl/ctlv3/command/defrag_command.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/etcdctl/ctlv3/command/defrag_command.go b/etcdctl/ctlv3/command/defrag_command.go index 3a8e40df8..c84a65acb 100644 --- a/etcdctl/ctlv3/command/defrag_command.go +++ b/etcdctl/ctlv3/command/defrag_command.go @@ -31,6 +31,7 @@ func NewDefragCommand() *cobra.Command { } func defragCommandFunc(cmd *cobra.Command, args []string) { + failures := 0 c := mustClientFromCmd(cmd) for _, ep := range c.Endpoints() { ctx, cancel := commandCtx(cmd) @@ -38,8 +39,13 @@ func defragCommandFunc(cmd *cobra.Command, args []string) { cancel() if err != nil { fmt.Fprintf(os.Stderr, "Failed to defragment etcd member[%s] (%v)\n", ep, err) + failures++ } else { fmt.Printf("Finished defragmenting etcd member[%s]\n", ep) } } + + if failures != 0 { + os.Exit(ExitError) + } }