Skip to content

Commit

Permalink
fix(cli): application cannot be refreshed on error and hangs
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Gaudreault <[email protected]>
  • Loading branch information
agaudreault committed Jan 21, 2025
1 parent 5ef4faa commit 734ad8c
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1630,29 +1630,26 @@ func (ctrl *ApplicationController) processAppRefreshQueueItem() (processNext boo
}).Info("Reconciliation completed")
}()

destCluster, err := argo.GetDestinationCluster(context.Background(), app.Spec.Destination, ctrl.db)
if err != nil {
logCtx.Errorf("Failed to get destination cluster: %v", err)
return
}

if comparisonLevel == ComparisonWithNothing {
managedResources := make([]*appv1.ResourceDiff, 0)
err := ctrl.cache.GetAppManagedResources(app.InstanceName(ctrl.namespace), &managedResources)
if err == nil {
var tree *appv1.ApplicationTree
if tree, err = ctrl.getResourceTree(destCluster, app, managedResources); err == nil {
app.Status.Summary = tree.GetSummary(app)
if err := ctrl.cache.SetAppResourcesTree(app.InstanceName(ctrl.namespace), tree); err != nil {
logCtx.Errorf("Failed to cache resources tree: %v", err)
return
// If the destination cluster is invalid, fallback to the normal reconciliation flow
if destCluster, err := argo.GetDestinationCluster(context.Background(), app.Spec.Destination, ctrl.db); err == nil {
managedResources := make([]*appv1.ResourceDiff, 0)
if err := ctrl.cache.GetAppManagedResources(app.InstanceName(ctrl.namespace), &managedResources); err == nil {
var tree *appv1.ApplicationTree
if tree, err = ctrl.getResourceTree(destCluster, app, managedResources); err == nil {
app.Status.Summary = tree.GetSummary(app)
if err := ctrl.cache.SetAppResourcesTree(app.InstanceName(ctrl.namespace), tree); err != nil {
logCtx.Errorf("Failed to cache resources tree: %v", err)
return
}
}
}

patchMs = ctrl.persistAppStatus(origApp, &app.Status)
return
patchMs = ctrl.persistAppStatus(origApp, &app.Status)
return
} else {
logCtx.Warnf("Failed to get cached managed resources for tree reconciliation, fall back to full reconciliation")
}
}
logCtx.Warnf("Failed to get cached managed resources for tree reconciliation, fall back to full reconciliation")
}
ts.AddCheckpoint("comparison_with_nothing_ms")

Expand All @@ -1675,6 +1672,13 @@ func (ctrl *ApplicationController) processAppRefreshQueueItem() (processNext boo
return
}

destCluster, err := argo.GetDestinationCluster(context.Background(), app.Spec.Destination, ctrl.db)
if err != nil {
logCtx.Errorf("Failed to get destination cluster: %v", err)
// exit the reconciliation. ctrl.refreshAppConditions should have caught the error
return
}

var localManifests []string
if opState := app.Status.OperationState; opState != nil && opState.Operation.Sync != nil {
localManifests = opState.Operation.Sync.Manifests
Expand Down Expand Up @@ -1722,6 +1726,7 @@ func (ctrl *ApplicationController) processAppRefreshQueueItem() (processNext boo

ctrl.normalizeApplication(origApp, app)
ts.AddCheckpoint("normalize_application_ms")

tree, err := ctrl.setAppManagedResources(destCluster, app, compareResult)
ts.AddCheckpoint("set_app_managed_resources_ms")
if err != nil {
Expand Down

0 comments on commit 734ad8c

Please sign in to comment.