Skip to content

Commit

Permalink
Merge branch 'release-2.12' of github.com:codefresh-io/argo-cd into C…
Browse files Browse the repository at this point in the history
…R-23842-revisions-info-reporting

# Conflicts:
#	changelog/CHANGELOG.md
  • Loading branch information
oleksandr-codefresh committed Oct 1, 2024
2 parents 09fddac + 288e7d3 commit ea8cdce
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.12-2024.9.30-a87492b22
2.12-2024.9.30-995854136
12 changes: 7 additions & 5 deletions acr_controller/service/acr_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"context"
"encoding/json"
"errors"
"sync"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -41,11 +42,12 @@ func getChangeRevisionFromRevisions(revisions []string) string {
}

func getChangeRevision(app *application.Application) string {
if changeRevision := getChangeRevisionFromRevisions(app.Operation.Sync.ChangeRevisions); changeRevision != "" {
return changeRevision
}
if app.Status.OperationState != nil && app.Status.OperationState.Operation.Sync != nil {
if changeRevision := getChangeRevisionFromRevisions(app.Status.OperationState.Operation.Sync.ChangeRevisions); changeRevision != "" {
changeRevision := app.Status.OperationState.Operation.Sync.ChangeRevision
if changeRevision != "" {
return changeRevision
}
if changeRevision = getChangeRevisionFromRevisions(app.Status.OperationState.Operation.Sync.ChangeRevisions); changeRevision != "" {
return changeRevision
}
}
Expand All @@ -67,7 +69,7 @@ func (c *acrService) ChangeRevision(ctx context.Context, a *application.Applicat

if getChangeRevision(app) != "" {
log.Infof("Change revision already calculated for application %s", app.Name)
return nil
return errors.New("change revision already calculated")
}

revision, err := c.calculateRevision(ctx, app)
Expand Down
20 changes: 20 additions & 0 deletions acr_controller/service/acr_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,24 @@ func Test_ChangeRevision(r *testing.T) {

assert.Equal(t, "new-revision", app.Status.OperationState.Operation.Sync.ChangeRevision)
})

r.Run("Change revision already exists", func(t *testing.T) {
client := &mocks.ApplicationClient{}
client.On("GetChangeRevision", mock.Anything, mock.Anything).Return(&appclient.ChangeRevisionResponse{
Revision: pointer.String("new-revision"),
}, nil)
acrService := newTestACRService(client)
app := createTestApp(syncedAppWithHistory)

err := acrService.ChangeRevision(context.TODO(), app)
require.NoError(t, err)

app, err = acrService.applicationClientset.ArgoprojV1alpha1().Applications(app.Namespace).Get(context.TODO(), app.Name, metav1.GetOptions{})
require.NoError(t, err)

assert.Equal(t, "new-revision", app.Status.OperationState.Operation.Sync.ChangeRevision)

err = acrService.ChangeRevision(context.TODO(), app)
require.Error(t, err, "change revision already calculated")
})
}
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12-2024.9.30-995854136.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- fix: change revision controller should verify that revision already exists

0 comments on commit ea8cdce

Please sign in to comment.