Skip to content

Commit b088681

Browse files
fix monorepo selfheal support and add logs
1 parent 6865168 commit b088681

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

controller/appcontroller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,10 +1961,14 @@ func alreadyAttemptedSync(app *appv1.Application, commitSHA string, commitSHAsMS
19611961
}
19621962
} else {
19631963
manifestsChangedMap := app.Status.Sync.ManifestsChanged
1964-
if os.Getenv("PERSIST_CHANGE_REVISIONS") != "1" || manifestsChangedMap[commitSHA] {
1964+
manifestChanged, ok := manifestsChangedMap[commitSHA]
1965+
// If record not exists, we need to do sync
1966+
if os.Getenv("PERSIST_CHANGE_REVISIONS") != "1" || !ok || manifestChanged {
19651967
if app.Status.OperationState.SyncResult.Revision != commitSHA {
19661968
return false, ""
19671969
}
1970+
} else {
1971+
log.Debugf("Skipping auto-sync: commitSHA %s has no changes", commitSHA)
19681972
}
19691973
}
19701974

controller/appcontroller_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,4 +1980,12 @@ func TestAlreadyAttemptSync(t *testing.T) {
19801980
attempted, _ := alreadyAttemptedSync(app, "sha", []string{}, false)
19811981
assert.False(t, attempted)
19821982
})
1983+
1984+
t.Run("different manifest with sync result, with enabled flag", func(t *testing.T) {
1985+
1986+
_ = os.Setenv("PERSIST_CHANGE_REVISIONS", "1")
1987+
1988+
attempted, _ := alreadyAttemptedSync(app, "sha", []string{}, false)
1989+
assert.False(t, attempted)
1990+
})
19831991
}

controller/state.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ func (m *appStateManager) GetRepoObjs(app *v1alpha1.Application, sources []v1alp
231231
// not need to change, if we already found at least one cached revision that has no changes
232232
if updateRevisionResponse != nil && os.Getenv("PERSIST_CHANGE_REVISIONS") == "1" {
233233
manifestsChanges[syncedRevision] = updateRevisionResponse.Changes
234+
log.WithField("application", app.Name).Debugf("Persisting revision %s with changes exists %t", syncedRevision, updateRevisionResponse.Changes)
234235
}
235236
if err != nil {
236237
return nil, nil, nil, fmt.Errorf("failed to compare revisions for source %d of %d: %w", i+1, len(sources), err)

0 commit comments

Comments
 (0)