Skip to content

Commit

Permalink
start go routines after cs controller manager setup (#2333)
Browse files Browse the repository at this point in the history
* Revert "suspend go routines until operator cache is ready (#2327)"

This reverts commit 7cdb53c.

* start go routines after cs controller manager setup

Signed-off-by: Daniel Fan <[email protected]>

---------

Signed-off-by: Daniel Fan <[email protected]>
  • Loading branch information
Daniel-Fan authored Dec 11, 2024
1 parent 7cdb53c commit 6553723
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
3 changes: 1 addition & 2 deletions controllers/goroutines/cleanup_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions controllers/goroutines/operator_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions controllers/goroutines/waitToCreateCsCR.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
18 changes: 6 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand All @@ -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(),
Expand Down

0 comments on commit 6553723

Please sign in to comment.