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

Prefactor: extract status collection to dedicated function in fleetshard central reconciler #1052

Merged
Merged
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
26 changes: 19 additions & 7 deletions fleetshard/pkg/central/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,23 +363,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) {
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