Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Move the shutdown wait to the end of helm-op main
Browse files Browse the repository at this point in the history
The general scheme in main.go is to start a bunch of goroutines,
giving them a shutdown channel; then wait until there's a reason to
exit, close the shutdown channel, and wait until the goroutines exit.

This wasn't working, because the last stanza in main.go was _not_ run
in a goroutine. This commit fixes that, and moves the graceful
shutdown bit to the end, for clarity.
  • Loading branch information
squaremo committed Feb 13, 2019
1 parent a7e4dfc commit 6bcfd3d
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions cmd/helm-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ func main() {
errc <- fmt.Errorf("%s", <-c)
}()

go func() {
logger.Log("exiting...", <-errc)
close(shutdown)
shutdownWg.Wait()
}()

mainLogger := log.With(logger, "component", "helm-operator")

cfg, err := clientcmd.BuildConfigFromFlags(*master, *kubeconfig)
Expand Down Expand Up @@ -195,9 +189,14 @@ func main() {
go daemonhttp.ListenAndServe(*listenAddr, log.With(logger, "component", "daemonhttp"), shutdown)

// start operator
if err = opr.Run(1, shutdown, shutdownWg); err != nil {
msg := fmt.Sprintf("Failure to run controller: %s", err.Error())
logger.Log("error", msg)
errc <- fmt.Errorf(ErrOperatorFailure, err)
}
go func() {
if err = opr.Run(1, shutdown, shutdownWg); err != nil {
errc <- fmt.Errorf(ErrOperatorFailure, err)
}
}()

shutdownErr := <-errc
logger.Log("exiting...", shutdownErr)
close(shutdown)
shutdownWg.Wait()
}

0 comments on commit 6bcfd3d

Please sign in to comment.