fix: resolve reviewer feedback (nil check, mock alias, and context)

Signed-off-by: liketosweep <liketosweep@gmail.com>
This commit is contained in:
liketosweep 2026-04-20 20:36:43 +00:00 committed by Liketosweep
parent ff35c941ed
commit b47cceb722
3 changed files with 25 additions and 19 deletions

View file

@ -1475,23 +1475,23 @@ func (ctrl *ApplicationController) processRequestedAppOperation(app *appv1.Appli
logCtx.Debug("Finished processing requested app operation")
}()
//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
}
//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(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
}
terminatingCause := ""
if isOperationInProgress(app) {

View file

@ -76,8 +76,8 @@ 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
// 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

View file

@ -627,3 +627,9 @@ func (_c *Dependencies_RequestAppRefresh_Call) RunAndReturn(run func(appName str
_c.Call.Return(run)
return _c
}
// RollbackApp provides a mock function for the type Dependencies
func (_mock *Dependencies) RollbackApp(ctx context.Context, app *v1alpha1.Application, hydratedRevision string) error {
args := _mock.Called(ctx, app, hydratedRevision)
return args.Error(0)
}