Skip to content

Commit d59276a

Browse files
authored
fix: Clear ApplicationSet applicationStatus when ProgressiveSync is disabled (argoproj#24587)
Signed-off-by: Atif Ali <atali@redhat.com>
1 parent 983f47e commit d59276a

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

applicationset/controllers/applicationset_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,16 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque
248248
return ctrl.Result{}, fmt.Errorf("failed to perform progressive sync reconciliation for application set: %w", err)
249249
}
250250
}
251+
} else {
252+
// Progressive Sync is disabled, clear any existing applicationStatus to prevent stale data
253+
if len(applicationSetInfo.Status.ApplicationStatus) > 0 {
254+
logCtx.Infof("Progressive Sync disabled, removing %v AppStatus entries from ApplicationSet %v", len(applicationSetInfo.Status.ApplicationStatus), applicationSetInfo.Name)
255+
256+
err := r.setAppSetApplicationStatus(ctx, logCtx, &applicationSetInfo, []argov1alpha1.ApplicationSetApplicationStatus{})
257+
if err != nil {
258+
return ctrl.Result{}, fmt.Errorf("failed to clear AppSet application statuses when Progressive Sync is disabled for %v: %w", applicationSetInfo.Name, err)
259+
}
260+
}
251261
}
252262

253263
if len(validateErrors) > 0 {

applicationset/controllers/applicationset_controller_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7276,3 +7276,82 @@ func TestIsRollingSyncDeletionReversed(t *testing.T) {
72767276
})
72777277
}
72787278
}
7279+
7280+
func TestReconcileProgressiveSyncDisabled(t *testing.T) {
7281+
scheme := runtime.NewScheme()
7282+
err := v1alpha1.AddToScheme(scheme)
7283+
require.NoError(t, err)
7284+
7285+
kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
7286+
7287+
for _, cc := range []struct {
7288+
name string
7289+
appSet v1alpha1.ApplicationSet
7290+
enableProgressiveSyncs bool
7291+
expectedAppStatuses []v1alpha1.ApplicationSetApplicationStatus
7292+
}{
7293+
{
7294+
name: "clears applicationStatus when Progressive Sync is disabled",
7295+
appSet: v1alpha1.ApplicationSet{
7296+
ObjectMeta: metav1.ObjectMeta{
7297+
Name: "test-appset",
7298+
Namespace: "argocd",
7299+
},
7300+
Spec: v1alpha1.ApplicationSetSpec{
7301+
Generators: []v1alpha1.ApplicationSetGenerator{},
7302+
Template: v1alpha1.ApplicationSetTemplate{},
7303+
},
7304+
Status: v1alpha1.ApplicationSetStatus{
7305+
ApplicationStatus: []v1alpha1.ApplicationSetApplicationStatus{
7306+
{
7307+
Application: "test-appset-guestbook",
7308+
Message: "Application resource became Healthy, updating status from Progressing to Healthy.",
7309+
Status: "Healthy",
7310+
Step: "1",
7311+
},
7312+
},
7313+
},
7314+
},
7315+
enableProgressiveSyncs: false,
7316+
expectedAppStatuses: nil,
7317+
},
7318+
} {
7319+
t.Run(cc.name, func(t *testing.T) {
7320+
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&cc.appSet).WithStatusSubresource(&cc.appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
7321+
metrics := appsetmetrics.NewFakeAppsetMetrics()
7322+
7323+
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
7324+
7325+
r := ApplicationSetReconciler{
7326+
Client: client,
7327+
Scheme: scheme,
7328+
Renderer: &utils.Render{},
7329+
Recorder: record.NewFakeRecorder(1),
7330+
Generators: map[string]generators.Generator{},
7331+
ArgoDB: argodb,
7332+
KubeClientset: kubeclientset,
7333+
Metrics: metrics,
7334+
EnableProgressiveSyncs: cc.enableProgressiveSyncs,
7335+
}
7336+
7337+
req := ctrl.Request{
7338+
NamespacedName: types.NamespacedName{
7339+
Namespace: cc.appSet.Namespace,
7340+
Name: cc.appSet.Name,
7341+
},
7342+
}
7343+
7344+
// Run reconciliation
7345+
_, err = r.Reconcile(t.Context(), req)
7346+
require.NoError(t, err)
7347+
7348+
// Fetch the updated ApplicationSet
7349+
var updatedAppSet v1alpha1.ApplicationSet
7350+
err = r.Get(t.Context(), req.NamespacedName, &updatedAppSet)
7351+
require.NoError(t, err)
7352+
7353+
// Verify the applicationStatus field
7354+
assert.Equal(t, cc.expectedAppStatuses, updatedAppSet.Status.ApplicationStatus, "applicationStatus should match expected value")
7355+
})
7356+
}
7357+
}

0 commit comments

Comments
 (0)