From e2b0094398681c11192763c8d4581734d5e5f534 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Wed, 15 Nov 2023 01:39:10 +0800 Subject: [PATCH] fix: stopCh can't work for start operator (#1857) --- pkg/controller/main-controller.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) 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