Skip to content

Commit

Permalink
fix(promotions): only check revision match sync result if found (#1923)
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
  • Loading branch information
hiddeco committed May 1, 2024
1 parent a6ced29 commit 7940c70
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 1 addition & 6 deletions internal/controller/promotion/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,12 @@ func (a *argoCDMechanism) mustPerformUpdate(

// The operation has completed. Check if the desired revision was applied.
desiredRevision := libargocd.GetDesiredRevision(app, newFreight)
if desiredRevision == "" {
// We cannot determine the desired revision. Performing an update in this
// case wouldn't change anything. Instead, we should error out.
return "", false, errors.New("unable to determine desired revision")
}
if status.SyncResult == nil {
// We do not have a sync result, so we cannot determine if the operation
// was successful. The best recourse is to retry the operation.
return "", true, errors.New("operation completed without a sync result")
}
if status.SyncResult.Revision != desiredRevision {
if desiredRevision != "" && status.SyncResult.Revision != desiredRevision {
// The operation did not result in the desired revision being applied.
// We should attempt to retry the operation.
return "", true, fmt.Errorf(
Expand Down
5 changes: 3 additions & 2 deletions internal/controller/promotion/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,12 @@ func TestArgoCDMustPerformUpdate(t *testing.T) {
Username: applicationOperationInitiator,
},
},
SyncResult: &argocd.SyncOperationResult{},
}
},
assertions: func(t *testing.T, phase argocd.OperationPhase, mustUpdate bool, err error) {
require.ErrorContains(t, err, "unable to determine desired revision")
require.Empty(t, phase)
require.NoError(t, err)
require.Equal(t, argocd.OperationSucceeded, phase)
require.False(t, mustUpdate)
},
},
Expand Down

0 comments on commit 7940c70

Please sign in to comment.