diff --git a/pkg/operator/ceph/cr_manager.go b/pkg/operator/ceph/cr_manager.go index bd17bcb48..4b796637f 100644 --- a/pkg/operator/ceph/cr_manager.go +++ b/pkg/operator/ceph/cr_manager.go @@ -17,6 +17,7 @@ limitations under the License. package operator import ( + "github.com/pkg/errors" "github.com/rook/rook/pkg/operator/ceph/cluster" "github.com/rook/rook/pkg/operator/ceph/disruption/controllerconfig" @@ -24,7 +25,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" ) -func (o *Operator) startManager(namespaceToWatch string, stopCh <-chan struct{}) { +func (o *Operator) startManager(namespaceToWatch string, stopCh <-chan struct{}, + mgrErrorCh chan error) { // Set up a manager mgrOpts := manager.Options{ LeaderElection: false, @@ -34,13 +36,13 @@ func (o *Operator) startManager(namespaceToWatch string, stopCh <-chan struct{}) logger.Info("setting up the controller-runtime manager") kubeConfig, err := config.GetConfig() if err != nil { - logger.Errorf("failed to get client config for controller-runtime manager. %v", err) + mgrErrorCh <- errors.Wrap(err, "failed to get client config for controller-runtime manager") return } mgr, err := manager.New(kubeConfig, mgrOpts) if err != nil { - logger.Errorf("failed to set up overall controller-runtime manager. %v", err) + mgrErrorCh <- errors.Wrap(err, "failed to set up overall controller-runtime manager") return } @@ -54,12 +56,13 @@ func (o *Operator) startManager(namespaceToWatch string, stopCh <-chan struct{}) // Add the registered controllers to the manager (entrypoint for controllers) err = cluster.AddToManager(mgr, controllerOpts, o.clusterController) if err != nil { - logger.Errorf("failed to add controllers to controller-runtime manager. %v", err) + mgrErrorCh <- errors.Wrap(err, "failed to add controllers to controller-runtime manager") + return } logger.Info("starting the controller-runtime manager") if err := mgr.Start(stopCh); err != nil { - logger.Errorf("unable to run the controller-runtime manager. %v", err) + mgrErrorCh <- errors.Wrap(err, "unable to run the controller-runtime manager") return } } diff --git a/pkg/operator/ceph/operator.go b/pkg/operator/ceph/operator.go index 2a9a4b4c8..cf95ee55e 100644 --- a/pkg/operator/ceph/operator.go +++ b/pkg/operator/ceph/operator.go @@ -100,6 +100,11 @@ func New(context *clusterd.Context, volumeAttachmentWrapper attachment.Attachmen return o } +func (o *Operator) cleanup(stopCh chan struct{}) { + close(stopCh) + o.clusterController.StopWatch() +} + // Run the operator instance func (o *Operator) Run() error { @@ -149,7 +154,8 @@ func (o *Operator) Run() error { } // Start the controller-runtime Manager. - go o.startManager(namespaceToWatch, stopChan) + mgrErrorChan := make(chan error) + go o.startManager(namespaceToWatch, stopChan, mgrErrorChan) // Start the operator setting watcher go o.clusterController.StartOperatorSettingsWatch(namespaceToWatch, stopChan) @@ -159,9 +165,12 @@ func (o *Operator) Run() error { select { case <-signalChan: logger.Info("shutdown signal received, exiting...") - close(stopChan) - o.clusterController.StopWatch() + o.cleanup(stopChan) return nil + case err := <-mgrErrorChan: + logger.Errorf("gave up to run the operator. %v", err) + o.cleanup(stopChan) + return err } } }