diff --git a/cmd/helm-operator/main.go b/cmd/helm-operator/main.go index 79e863f17..ab8ba2183 100644 --- a/cmd/helm-operator/main.go +++ b/cmd/helm-operator/main.go @@ -133,12 +133,6 @@ func main() { errc <- fmt.Errorf("%s", <-c) }() - defer func() { - logger.Log("exiting...", <-errc) - close(shutdown) - shutdownWg.Wait() - }() - mainLogger := log.With(logger, "component", "helm-operator") cfg, err := clientcmd.BuildConfigFromFlags(*master, *kubeconfig) @@ -198,9 +192,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() }