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

ctlv3: exit non-zero on unhealthy ep command #8342

Merged
merged 1 commit into from
Jul 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions etcdctl/ctlv3/command/ep_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ func epHealthCommandFunc(cmd *cobra.Command, args []string) {
}

var wg sync.WaitGroup

errc := make(chan error, len(cfgs))
for _, cfg := range cfgs {
wg.Add(1)
go func(cfg *v3.Config) {
defer wg.Done()
ep := cfg.Endpoints[0]
cli, err := v3.New(*cfg)
if err != nil {
fmt.Printf("%s is unhealthy: failed to connect: %v\n", ep, err)
errc <- fmt.Errorf("%s is unhealthy: failed to connect: %v", ep, err)
return
}
st := time.Now()
Expand All @@ -102,12 +102,24 @@ func epHealthCommandFunc(cmd *cobra.Command, args []string) {
if err == nil || err == rpctypes.ErrPermissionDenied {
fmt.Printf("%s is healthy: successfully committed proposal: took = %v\n", ep, time.Since(st))
} else {
fmt.Printf("%s is unhealthy: failed to commit proposal: %v\n", ep, err)
errc <- fmt.Errorf("%s is unhealthy: failed to commit proposal: %v", ep, err)
}
}(cfg)
}

wg.Wait()
close(errc)

errs := false
for err := range errc {
if err != nil {
errs = true
fmt.Fprintln(os.Stderr, err)
}
}
if errs {
ExitWithError(ExitError, fmt.Errorf("unhealthy cluster"))
}
}

type epStatus struct {
Expand Down