diff --git a/controllers/goroutines/cleanup_resources.go b/controllers/goroutines/cleanup_resources.go index 1446c2766..dc0e87104 100644 --- a/controllers/goroutines/cleanup_resources.go +++ b/controllers/goroutines/cleanup_resources.go @@ -137,8 +137,7 @@ func CleanupMongodbPreloadCm(bs *bootstrap.Bootstrap) { } } -func CleanupResources(ch chan *bootstrap.Bootstrap) { - bs := <-ch +func CleanupResources(bs *bootstrap.Bootstrap) { go CleanupKeycloakCert(bs) go CleanupMongodbPreloadCm(bs) } diff --git a/controllers/goroutines/operator_status.go b/controllers/goroutines/operator_status.go index 06e195eff..7d57fc1b1 100644 --- a/controllers/goroutines/operator_status.go +++ b/controllers/goroutines/operator_status.go @@ -35,9 +35,8 @@ import ( var ctx = context.Background() // UpdateCsCrStatus will update cs cr status according to each bedrock operator -func UpdateCsCrStatus(ch chan *bootstrap.Bootstrap) { +func UpdateCsCrStatus(bs *bootstrap.Bootstrap) { for { - bs := <-ch instance := &apiv3.CommonService{} if err := bs.Reader.Get(ctx, types.NamespacedName{Name: "common-service", Namespace: bs.CSData.OperatorNs}, instance); err != nil { if !errors.IsNotFound(err) { diff --git a/controllers/goroutines/waitToCreateCsCR.go b/controllers/goroutines/waitToCreateCsCR.go index 3771673b9..2a75336dd 100644 --- a/controllers/goroutines/waitToCreateCsCR.go +++ b/controllers/goroutines/waitToCreateCsCR.go @@ -28,9 +28,8 @@ import ( ) // WaitToCreateCsCR waits for the creation of the CommonService CR in the operator namespace. -func WaitToCreateCsCR(ch chan *bootstrap.Bootstrap) { +func WaitToCreateCsCR(bs *bootstrap.Bootstrap) { for { - bs := <-ch klog.Infof("Start to Create CommonService CR in the namespace %s", bs.CSData.OperatorNs) if err := bs.CreateCsCR(); err != nil { if strings.Contains(fmt.Sprint(err), "failed to call webhook") { diff --git a/main.go b/main.go index d3b017d75..1196550d7 100644 --- a/main.go +++ b/main.go @@ -155,15 +155,6 @@ func main() { os.Exit(1) } - // Setup a channel to suspend go routines - ch := make(chan *bootstrap.Bootstrap) - // Update CS CR Status, wait for signal from channel - go goroutines.UpdateCsCrStatus(ch) - // Create CS CR - go goroutines.WaitToCreateCsCR(ch) - // Delete Keycloak Cert - go goroutines.CleanupResources(ch) - klog.Infof("Setup commonservice manager") if err = (&controllers.CommonServiceReconciler{ Bootstrap: bs, @@ -174,9 +165,13 @@ func main() { os.Exit(1) } - // start go routines klog.Infof("Start go routines") - ch <- bs + // Update CS CR Status + go goroutines.UpdateCsCrStatus(bs) + // Create CS CR + go goroutines.WaitToCreateCsCR(bs) + // Delete Keycloak Cert + go goroutines.CleanupResources(bs) // check if cert-manager CRD does not exist, then skip cert-manager related controllers initialization exist, err := bs.CheckCRD(constant.CertManagerAPIGroupVersionV1, "Certificate") @@ -188,7 +183,6 @@ func main() { klog.Infof("cert-manager CRD does not exist, skip cert-manager related controllers initialization") } else if exist && err == nil { - klog.Infof("Set up certmanager Manager") if err = (&certmanagerv1controllers.CertificateRefreshReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(),