Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suspend go routines until operator cache is ready #2327

Merged
merged 6 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion controllers/goroutines/cleanup_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ func CleanupMongodbPreloadCm(bs *bootstrap.Bootstrap) {
}
}

func CleanupResources(bs *bootstrap.Bootstrap) {
func CleanupResources(ch chan *bootstrap.Bootstrap) {
bs := <-ch
go CleanupKeycloakCert(bs)
go CleanupMongodbPreloadCm(bs)
}
3 changes: 2 additions & 1 deletion controllers/goroutines/operator_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import (
var ctx = context.Background()

// UpdateCsCrStatus will update cs cr status according to each bedrock operator
func UpdateCsCrStatus(bs *bootstrap.Bootstrap) {
func UpdateCsCrStatus(ch chan *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: 2 additions & 1 deletion controllers/goroutines/waitToCreateCsCR.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import (
)

// WaitToCreateCsCR waits for the creation of the CommonService CR in the operator namespace.
func WaitToCreateCsCR(bs *bootstrap.Bootstrap) {
func WaitToCreateCsCR(ch chan *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
17 changes: 13 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,17 @@ func main() {
klog.Errorf("Cleanup Webhook Resources failed: %v", err)
os.Exit(1)
}
// Update CS CR Status
go goroutines.UpdateCsCrStatus(bs)

// 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(bs)
go goroutines.WaitToCreateCsCR(ch)
// Delete Keycloak Cert
go goroutines.CleanupResources(bs)
go goroutines.CleanupResources(ch)

klog.Infof("Setup commonservice manager")
if err = (&controllers.CommonServiceReconciler{
Bootstrap: bs,
Scheme: mgr.GetScheme(),
Expand All @@ -170,6 +174,10 @@ func main() {
os.Exit(1)
}

// start go routines
klog.Infof("Start go routines")
ch <- bs

// check if cert-manager CRD does not exist, then skip cert-manager related controllers initialization
exist, err := bs.CheckCRD(constant.CertManagerAPIGroupVersionV1, "Certificate")
if err != nil {
Expand All @@ -180,6 +188,7 @@ 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
Loading