fix: address reviewer feedback (nil check, interface update, and context)

Signed-off-by: liketosweep <liketosweep@gmail.com>
This commit is contained in:
liketosweep 2026-04-20 20:18:27 +00:00 committed by Liketosweep
parent e0dface68b
commit ff35c941ed
2 changed files with 20 additions and 16 deletions

View file

@ -1475,22 +1475,23 @@ func (ctrl *ApplicationController) processRequestedAppOperation(app *appv1.Appli
logCtx.Debug("Finished processing requested app operation")
}()
if app.Spec.SourceHydrator != nil && app.Operation != nil && app.Operation.Sync != nil {
revision := app.Operation.Sync.Revision
err := ctrl.hydrator.RollbackApp(context.Background(), app, revision)
if err != nil {
ctrl.setOperationState(app, &appv1.OperationState{
Phase: synccommon.OperationFailed,
Message: err.Error(),
})
return
}
ctrl.setOperationState(app, &appv1.OperationState{
Phase: synccommon.OperationSucceeded,
Message: fmt.Sprintf("rolled back to %s", revision),
})
return
}
//added the 'ctrl.hydrator != nil' check and changed Background() to 'ctx'
if ctrl.hydrator != nil && app.Spec.SourceHydrator != nil && app.Operation != nil && app.Operation.Sync != nil {
revision := app.Operation.Sync.Revision
err := ctrl.hydrator.RollbackApp(ctx, app, revision)
if err != nil {
ctrl.setOperationState(app, &appv1.OperationState{
Phase: synccommon.OperationFailed,
Message: err.Error(),
})
return
}
ctrl.setOperationState(app, &appv1.OperationState{
Phase: synccommon.OperationSucceeded,
Message: fmt.Sprintf("rolled back to %s", revision),
})
return
}
terminatingCause := ""
if isOperationInProgress(app) {

View file

@ -75,6 +75,9 @@ type Dependencies interface {
// GetCommitAuthorEmail gets the configured commit author email from argocd-cm ConfigMap.
GetCommitAuthorEmail() (string, error)
// RollbackApp performs a rollback for a Source Hydrator enabled application by committing historical manifests to the sync branch.
RollbackApp(ctx context.Context, app *appv1.Application, hydratedRevision string) error
}
// Hydrator is the main struct that implements the hydration logic. It uses the Dependencies interface to access the