From 1030c85ba6b596c772ee70015654c5e0cfc952fd Mon Sep 17 00:00:00 2001 From: Yann Brillouet Date: Fri, 19 May 2023 21:24:30 +0200 Subject: [PATCH] Prefactor: extract status collection to dedicated function in fleetshard central reconciler --- .../pkg/central/reconciler/reconciler.go | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/fleetshard/pkg/central/reconciler/reconciler.go b/fleetshard/pkg/central/reconciler/reconciler.go index 486472ea86..742b11cfe4 100644 --- a/fleetshard/pkg/central/reconciler/reconciler.go +++ b/fleetshard/pkg/central/reconciler/reconciler.go @@ -360,23 +360,35 @@ func (r *CentralReconciler) Reconcile(ctx context.Context, remoteCentral private r.hasAuthProvider = true } + status, err := r.collectReconciliationStatus(ctx, remoteCentral) + if err != nil { + return nil, err + } + + // Setting the last central hash must always be executed as the last step. + // defer can't be used for this call because it is also executed after the reconcile failed. + if err := r.setLastCentralHash(remoteCentral); err != nil { + return nil, errors.Wrapf(err, "setting central reconcilation cache") + } + + return status, nil +} + +func (r *CentralReconciler) collectReconciliationStatus(ctx context.Context, remoteCentral private.ManagedCentral) (*private.DataPlaneCentralStatus, error) { + remoteCentralNamespace := remoteCentral.Metadata.Namespace + status := readyStatus() // Do not report routes statuses if: // 1. Routes are not used on the cluster // 2. Central request is in status "Ready" - assuming that routes are already reported and saved if r.useRoutes && !isRemoteCentralReady(remoteCentral) { + var err error status.Routes, err = r.getRoutesStatuses(ctx, remoteCentralNamespace) if err != nil { return nil, err } } - // Setting the last central hash must always be executed as the last step. - // defer can't be used for this call because it is also executed after the reconcile failed. - if err := r.setLastCentralHash(remoteCentral); err != nil { - return nil, errors.Wrapf(err, "setting central reconcilation cache") - } - return status, nil }