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

start go routines after cs controller manager setup #2333

Merged
merged 2 commits into from
Dec 11, 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: 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
Loading