From aa990d6696a04fcf6a62f40af10c6c9991e17092 Mon Sep 17 00:00:00 2001 From: pasha-codefresh Date: Sat, 7 Sep 2024 19:12:33 +0300 Subject: [PATCH] always execute sync if at least for one revision we identify if it was changed or no (#19828) Signed-off-by: pashakostohrys --- controller/state.go | 7 ++++++- controller/state_test.go | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/controller/state.go b/controller/state.go index 3009c07008be4..bcac67961781c 100644 --- a/controller/state.go +++ b/controller/state.go @@ -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 { @@ -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) @@ -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 } diff --git a/controller/state_test.go b/controller/state_test.go index 141d32a46ba3d..a3b7cb195a94e 100644 --- a/controller/state_test.go +++ b/controller/state_test.go @@ -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) +}