From 162b12cbccab9ec23456efb03060626c8daaee58 Mon Sep 17 00:00:00 2001 From: Roman Hros Date: Fri, 16 Feb 2024 13:08:03 +0100 Subject: [PATCH] Create a GitHub client before mutex Signed-off-by: Roman Hros --- .../openstackclusterstackrelease_controller.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/controller/openstackclusterstackrelease_controller.go b/internal/controller/openstackclusterstackrelease_controller.go index 9c32e7b8..9b9b76bd 100644 --- a/internal/controller/openstackclusterstackrelease_controller.go +++ b/internal/controller/openstackclusterstackrelease_controller.go @@ -123,12 +123,6 @@ func (r *OpenStackClusterStackReleaseReconciler) Reconcile(ctx context.Context, if download { conditions.MarkFalse(openstackclusterstackrelease, apiv1alpha1.ClusterStackReleaseAssetsReadyCondition, apiv1alpha1.ReleaseAssetsNotDownloadedYetReason, clusterv1beta1.ConditionSeverityInfo, "assets not downloaded yet") - // this is the point where we download the release from github - // acquire lock so that only one reconcile loop can download the release - r.openStackClusterStackRelDownloadDirectoryMutex.Lock() - - defer r.openStackClusterStackRelDownloadDirectoryMutex.Unlock() - gc, err := r.GitHubClientFactory.NewClient(ctx) if err != nil { conditions.MarkFalse(openstackclusterstackrelease, @@ -144,6 +138,12 @@ func (r *OpenStackClusterStackReleaseReconciler) Reconcile(ctx context.Context, conditions.MarkTrue(openstackclusterstackrelease, apiv1alpha1.GitAPIAvailableCondition) + // this is the point where we download the release from github + // acquire lock so that only one reconcile loop can download the release + r.openStackClusterStackRelDownloadDirectoryMutex.Lock() + + defer r.openStackClusterStackRelDownloadDirectoryMutex.Unlock() + if err := downloadReleaseAssets(ctx, releaseTag, releaseAssets.LocalDownloadPath, gc); err != nil { logger.Error(err, "failed to download release assets") return ctrl.Result{RequeueAfter: 1 * time.Minute}, nil