Skip to content

Commit

Permalink
Prefactor: extract status collection to dedicated function in fleetsh…
Browse files Browse the repository at this point in the history
…ard central reconciler
  • Loading branch information
rhybrillou committed May 25, 2023
1 parent fa26250 commit 1030c85
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions fleetshard/pkg/central/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 1030c85

Please sign in to comment.