Skip to content

Commit

Permalink
fix(promo): record failure msg for Argo CD App
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
  • Loading branch information
hiddeco committed Jun 19, 2024
1 parent f211d9e commit 8369945
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/controller/promotion/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (a *argoCDMechanism) Promote(
logger.Debug("executing Argo CD-based promotion mechanisms")

var updateResults = make([]argocd.OperationPhase, 0, len(updates))
var newStatus = promo.Status.DeepCopy()
for _, update := range updates {
// Retrieve the Argo CD Application.
app, err := a.getAuthorizedApplicationFn(ctx, update.AppNamespace, update.AppName, stage.ObjectMeta)
Expand Down Expand Up @@ -156,6 +157,16 @@ func (a *argoCDMechanism) Promote(
logger.Info(err.Error())
}
if phase.Failed() {
// Record the reason for the failure if available.
if app.Status.OperationState != nil {
newStatus.Message = fmt.Sprintf(
"Argo CD Application %q in namespace %q failed with: %s",
app.Name,
app.Namespace,
app.Status.OperationState.Message,
)

Check warning on line 167 in internal/controller/promotion/argocd.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotion/argocd.go#L162-L167

Added lines #L162 - L167 were not covered by tests
}

// If the update failed, we can short-circuit. This is
// effectively "fail fast" behavior.
break
Expand All @@ -181,7 +192,8 @@ func (a *argoCDMechanism) Promote(
}

logger.Debug("done executing Argo CD-based promotion mechanisms")
return promo.Status.WithPhase(aggregatedPhase), newFreight, nil
newStatus.Phase = aggregatedPhase
return newStatus, newFreight, nil
}

// buildDesiredSources returns the desired source(s) for an Argo CD Application,
Expand Down

0 comments on commit 8369945

Please sign in to comment.