From d51e4340226317d4257b7056f897b84e530739c8 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Fri, 20 Dec 2024 12:23:08 +0100 Subject: [PATCH] Test loop --- controllers/btpoperator_controller.go | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/controllers/btpoperator_controller.go b/controllers/btpoperator_controller.go index c0e727aa4..fbb8ba7fa 100644 --- a/controllers/btpoperator_controller.go +++ b/controllers/btpoperator_controller.go @@ -616,28 +616,19 @@ func (r *BtpOperatorReconciler) applyOrUpdateResources(ctx context.Context, us [ func (r *BtpOperatorReconciler) waitForResourcesReadiness(ctx context.Context, us []*unstructured.Unstructured) error { numOfResources := len(us) resourcesReadinessInformer := make(chan bool, numOfResources) - allReadyInformer := make(chan bool, 1) for _, u := range us { go r.checkResourceReadiness(ctx, u, resourcesReadinessInformer) } - go func(c chan bool) { - timeout := time.After(ReadyTimeout) - for i := 0; i < numOfResources; i++ { - select { - case <-resourcesReadinessInformer: - continue - case <-timeout: - return - } + timeout := time.After(ReadyTimeout) + for i := 0; i < numOfResources; i++ { + select { + case <-resourcesReadinessInformer: + continue + case <-timeout: + return errors.New("resources readiness timeout reached") } - allReadyInformer <- true - }(resourcesReadinessInformer) - select { - case <-allReadyInformer: - return nil - case <-time.After(ReadyTimeout): - return errors.New("resources readiness timeout reached") } + return nil } func (r *BtpOperatorReconciler) checkResourceReadiness(ctx context.Context, u *unstructured.Unstructured, c chan<- bool) {