Skip to content

Commit

Permalink
always execute sync if at least for one revision we identify if it wa…
Browse files Browse the repository at this point in the history
…s changed or no (#19828)

Signed-off-by: pashakostohrys <[email protected]>
  • Loading branch information
pasha-codefresh authored Sep 7, 2024
1 parent 71bbdcc commit aa990d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ func (m *appStateManager) GetRepoObjs(app *v1alpha1.Application, sources []v1alp

revisionUpdated := false

atLeastOneRevisionIsNotPossibleToBeUpdated := false

keyManifestGenerateAnnotationVal, keyManifestGenerateAnnotationExists := app.Annotations[v1alpha1.AnnotationKeyManifestGeneratePaths]

for i, source := range sources {
Expand Down Expand Up @@ -240,6 +242,9 @@ func (m *appStateManager) GetRepoObjs(app *v1alpha1.Application, sources []v1alp
if updateRevisionResult.Revision != "" {
revision = updateRevisionResult.Revision
}
} else {
// revisionUpdated is set to true if at least one revision is not possible to be updated,
atLeastOneRevisionIsNotPossibleToBeUpdated = true
}

log.Debugf("Generating Manifest for source %s revision %s", source, revision)
Expand Down Expand Up @@ -287,7 +292,7 @@ func (m *appStateManager) GetRepoObjs(app *v1alpha1.Application, sources []v1alp
logCtx.Info("GetRepoObjs stats")

// in case if annotation not exists, we should always execute selfheal if manifests changed
if !keyManifestGenerateAnnotationExists || keyManifestGenerateAnnotationVal == "" {
if atLeastOneRevisionIsNotPossibleToBeUpdated {
revisionUpdated = true
}

Expand Down
23 changes: 23 additions & 0 deletions controller/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1733,3 +1733,26 @@ func TestCompareAppStateDefaultRevisionUpdated(t *testing.T) {
assert.NotNil(t, compRes.syncStatus)
assert.True(t, compRes.revisionUpdated)
}

func TestCompareAppStateRevisionUpdatedWithHelmSource(t *testing.T) {
app := newFakeMultiSourceApp()
data := fakeData{
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
Namespace: test.FakeDestNamespace,
Server: test.FakeClusterURL,
Revision: "abc123",
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
sources := make([]argoappv1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
revisions = append(revisions, "")
compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false)
require.NoError(t, err)
assert.NotNil(t, compRes)
assert.NotNil(t, compRes.syncStatus)
assert.True(t, compRes.revisionUpdated)
}

0 comments on commit aa990d6

Please sign in to comment.