From 4a538e28c30364d2081bf99129fb2e67a36568b3 Mon Sep 17 00:00:00 2001 From: Homulvas Date: Fri, 17 Jan 2025 16:55:25 +0100 Subject: [PATCH] fix: check if application has prune only changes and automated prune is disabled when doing progressive sync Signed-off-by: Homulvas --- .../controllers/applicationset_controller.go | 15 +++- .../applicationset_controller_test.go | 83 +++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/applicationset/controllers/applicationset_controller.go b/applicationset/controllers/applicationset_controller.go index 287c599f7fe12..6926e91a24a45 100644 --- a/applicationset/controllers/applicationset_controller.go +++ b/applicationset/controllers/applicationset_controller.go @@ -1095,7 +1095,20 @@ func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatus(ctx con appOutdated := false if progressiveSyncsRollingSyncStrategyEnabled(applicationSet) { - appOutdated = syncStatusString == "OutOfSync" + appOutdated = syncStatusString == string(argov1alpha1.SyncStatusCodeOutOfSync) + pruneEnabled := app.Spec.SyncPolicy != nil && app.Spec.SyncPolicy.Automated != nil && app.Spec.SyncPolicy.Automated.Prune + if !pruneEnabled { + requirePruneOnly := true + for _, r := range app.Status.Resources { + if r.Status != argov1alpha1.SyncStatusCodeSynced && !r.RequiresPruning { + requirePruneOnly = false + break + } + } + if requirePruneOnly { + appOutdated = false + } + } } if appOutdated && currentAppStatus.Status != "Waiting" && currentAppStatus.Status != "Pending" { diff --git a/applicationset/controllers/applicationset_controller_test.go b/applicationset/controllers/applicationset_controller_test.go index 254fea1c2e240..8135839e3cc10 100644 --- a/applicationset/controllers/applicationset_controller_test.go +++ b/applicationset/controllers/applicationset_controller_test.go @@ -4642,6 +4642,11 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) { Status: v1alpha1.SyncStatusCodeOutOfSync, Revision: "Next", }, + Resources: []v1alpha1.ResourceStatus{ + { + RequiresPruning: false, + }, + }, }, }, { @@ -4653,6 +4658,11 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) { Status: v1alpha1.SyncStatusCodeOutOfSync, Revisions: []string{"Next", "OtherNext"}, }, + Resources: []v1alpha1.ResourceStatus{ + { + RequiresPruning: false, + }, + }, }, }, }, @@ -4677,6 +4687,79 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) { }, }, }, + { + name: "doesn't move an OutOfSync RollingSync application to waiting if only prune changes are needed and prune is disabled", + appSet: v1alpha1.ApplicationSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + Namespace: "argocd", + }, + Spec: v1alpha1.ApplicationSetSpec{ + Strategy: &v1alpha1.ApplicationSetStrategy{ + Type: "RollingSync", + RollingSync: &v1alpha1.ApplicationSetRolloutStrategy{ + Steps: []v1alpha1.ApplicationSetRolloutStep{ + { + MatchExpressions: []v1alpha1.ApplicationMatchExpression{}, + }, + { + MatchExpressions: []v1alpha1.ApplicationMatchExpression{}, + }, + }, + }, + }, + }, + Status: v1alpha1.ApplicationSetStatus{ + ApplicationStatus: []v1alpha1.ApplicationSetApplicationStatus{ + { + Application: "app1", + Message: "", + Status: "Healthy", + Step: "1", + TargetRevisions: []string{"Previous"}, + }, + }, + }, + }, + apps: []v1alpha1.Application{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "app1", + }, + Status: v1alpha1.ApplicationStatus{ + Sync: v1alpha1.SyncStatus{ + Status: v1alpha1.SyncStatusCodeOutOfSync, + Revision: "Next", + }, + Resources: []v1alpha1.ResourceStatus{ + { + Status: v1alpha1.SyncStatusCodeOutOfSync, + RequiresPruning: true, + }, + }, + }, + Spec: v1alpha1.ApplicationSpec{ + SyncPolicy: &v1alpha1.SyncPolicy{ + Automated: &v1alpha1.SyncPolicyAutomated{ + Prune: false, + }, + }, + }, + }, + }, + appStepMap: map[string]int{ + "app1": 0, + }, + expectedAppStatus: []v1alpha1.ApplicationSetApplicationStatus{ + { + Application: "app1", + Message: "", + Status: "Healthy", + Step: "1", + TargetRevisions: []string{"Previous"}, + }, + }, + }, { name: "progresses a pending progressing application to progressing", appSet: v1alpha1.ApplicationSet{