diff --git a/pkg/controller/main-controller.go b/pkg/controller/main-controller.go index f06f76bd35c..b88cc35d244 100644 --- a/pkg/controller/main-controller.go +++ b/pkg/controller/main-controller.go @@ -592,19 +592,22 @@ func (c *Controller) Start(threadiness int, stopCh <-chan struct{}) error { Err: nil, } }() - - for oerr := range notificationChannel { - switch oerr.Type { - case STSServerNotification: - if !errors.Is(oerr.Err, http.ErrServerClosed) { - klog.Errorf("STS API Server stopped: %v, going to restart", oerr.Err) - go c.startSTSAPIServer(ctx, notificationChannel) + for { + select { + case oerr := <-notificationChannel: + switch oerr.Type { + case STSServerNotification: + if !errors.Is(oerr.Err, http.ErrServerClosed) { + klog.Errorf("STS API Server stopped: %v, going to restart", oerr.Err) + go c.startSTSAPIServer(ctx, notificationChannel) + } + case LeaderElection: + return nil } - case LeaderElection: + case <-stopCh: return nil } } - return nil } // Stop is called to shutdown the controller