@@ -7613,109 +7613,81 @@ func TestSyncApplication(t *testing.T) {
76137613 }
76147614}
76157615
7616- func TestIsRollingSyncDeletionReversed (t * testing.T ) {
7617- tests := []struct {
7618- name string
7619- appset * v1alpha1.ApplicationSet
7620- expected bool
7616+ func TestReconcileProgressiveSyncDisabled (t * testing.T ) {
7617+ scheme := runtime .NewScheme ()
7618+ err := v1alpha1 .AddToScheme (scheme )
7619+ require .NoError (t , err )
7620+
7621+ kubeclientset := kubefake .NewSimpleClientset ([]runtime.Object {}... )
7622+
7623+ for _ , cc := range []struct {
7624+ name string
7625+ appSet v1alpha1.ApplicationSet
7626+ enableProgressiveSyncs bool
7627+ expectedAppStatuses []v1alpha1.ApplicationSetApplicationStatus
76217628 }{
76227629 {
7623- name : "Deletion Order on strategy is set as Reverse" ,
7624- appset : & v1alpha1.ApplicationSet {
7625- Spec : v1alpha1.ApplicationSetSpec {
7626- Strategy : & v1alpha1.ApplicationSetStrategy {
7627- Type : "RollingSync" ,
7628- RollingSync : & v1alpha1.ApplicationSetRolloutStrategy {
7629- Steps : []v1alpha1.ApplicationSetRolloutStep {
7630- {
7631- MatchExpressions : []v1alpha1.ApplicationMatchExpression {
7632- {
7633- Key : "environment" ,
7634- Operator : "In" ,
7635- Values : []string {
7636- "dev" ,
7637- },
7638- },
7639- },
7640- },
7641- {
7642- MatchExpressions : []v1alpha1.ApplicationMatchExpression {
7643- {
7644- Key : "environment" ,
7645- Operator : "In" ,
7646- Values : []string {
7647- "staging" ,
7648- },
7649- },
7650- },
7651- },
7652- },
7653- },
7654- DeletionOrder : ReverseDeletionOrder ,
7655- },
7630+ name : "clears applicationStatus when Progressive Sync is disabled" ,
7631+ appSet : v1alpha1.ApplicationSet {
7632+ ObjectMeta : metav1.ObjectMeta {
7633+ Name : "test-appset" ,
7634+ Namespace : "argocd" ,
76567635 },
7657- },
7658- expected : true ,
7659- },
7660- {
7661- name : "Deletion Order on strategy is set as AllAtOnce" ,
7662- appset : & v1alpha1.ApplicationSet {
76637636 Spec : v1alpha1.ApplicationSetSpec {
7664- Strategy : & v1alpha1.ApplicationSetStrategy {
7665- Type : "RollingSync" ,
7666- RollingSync : & v1alpha1.ApplicationSetRolloutStrategy {
7667- Steps : []v1alpha1.ApplicationSetRolloutStep {},
7668- },
7669- DeletionOrder : AllAtOnceDeletionOrder ,
7670- },
7637+ Generators : []v1alpha1.ApplicationSetGenerator {},
7638+ Template : v1alpha1.ApplicationSetTemplate {},
76717639 },
7672- },
7673- expected : false ,
7674- },
7675- {
7676- name : "Deletion Order on strategy is set as Reverse but no steps in RollingSync" ,
7677- appset : & v1alpha1.ApplicationSet {
7678- Spec : v1alpha1.ApplicationSetSpec {
7679- Strategy : & v1alpha1.ApplicationSetStrategy {
7680- Type : "RollingSync" ,
7681- RollingSync : & v1alpha1.ApplicationSetRolloutStrategy {
7682- Steps : []v1alpha1.ApplicationSetRolloutStep {},
7683- },
7684- DeletionOrder : ReverseDeletionOrder ,
7685- },
7686- },
7687- },
7688- expected : false ,
7689- },
7690- {
7691- name : "Deletion Order on strategy is set as Reverse, but AllAtOnce is explicitly set" ,
7692- appset : & v1alpha1.ApplicationSet {
7693- Spec : v1alpha1.ApplicationSetSpec {
7694- Strategy : & v1alpha1.ApplicationSetStrategy {
7695- Type : "AllAtOnce" ,
7696- RollingSync : & v1alpha1.ApplicationSetRolloutStrategy {
7697- Steps : []v1alpha1.ApplicationSetRolloutStep {},
7640+ Status : v1alpha1.ApplicationSetStatus {
7641+ ApplicationStatus : []v1alpha1.ApplicationSetApplicationStatus {
7642+ {
7643+ Application : "test-appset-guestbook" ,
7644+ Message : "Application resource became Healthy, updating status from Progressing to Healthy." ,
7645+ Status : "Healthy" ,
7646+ Step : "1" ,
76987647 },
7699- DeletionOrder : ReverseDeletionOrder ,
77007648 },
77017649 },
77027650 },
7703- expected : false ,
7651+ enableProgressiveSyncs : false ,
7652+ expectedAppStatuses : nil ,
77047653 },
7705- {
7706- name : "Strategy is Nil" ,
7707- appset : & v1alpha1.ApplicationSet {
7708- Spec : v1alpha1.ApplicationSetSpec {
7709- Strategy : & v1alpha1.ApplicationSetStrategy {},
7654+ } {
7655+ t .Run (cc .name , func (t * testing.T ) {
7656+ client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& cc .appSet ).WithStatusSubresource (& cc .appSet ).WithIndex (& v1alpha1.Application {}, ".metadata.controller" , appControllerIndexer ).Build ()
7657+ metrics := appsetmetrics .NewFakeAppsetMetrics ()
7658+
7659+ argodb := db .NewDB ("argocd" , settings .NewSettingsManager (t .Context (), kubeclientset , "argocd" ), kubeclientset )
7660+
7661+ r := ApplicationSetReconciler {
7662+ Client : client ,
7663+ Scheme : scheme ,
7664+ Renderer : & utils.Render {},
7665+ Recorder : record .NewFakeRecorder (1 ),
7666+ Generators : map [string ]generators.Generator {},
7667+ ArgoDB : argodb ,
7668+ KubeClientset : kubeclientset ,
7669+ Metrics : metrics ,
7670+ EnableProgressiveSyncs : cc .enableProgressiveSyncs ,
7671+ }
7672+
7673+ req := ctrl.Request {
7674+ NamespacedName : types.NamespacedName {
7675+ Namespace : cc .appSet .Namespace ,
7676+ Name : cc .appSet .Name ,
77107677 },
7711- },
7712- expected : false ,
7713- },
7714- }
7715- for _ , tt := range tests {
7716- t .Run (tt .name , func (t * testing.T ) {
7717- result := isProgressiveSyncDeletionOrderReversed (tt .appset )
7718- assert .Equal (t , tt .expected , result )
7678+ }
7679+
7680+ // Run reconciliation
7681+ _ , err = r .Reconcile (t .Context (), req )
7682+ require .NoError (t , err )
7683+
7684+ // Fetch the updated ApplicationSet
7685+ var updatedAppSet v1alpha1.ApplicationSet
7686+ err = r .Get (t .Context (), req .NamespacedName , & updatedAppSet )
7687+ require .NoError (t , err )
7688+
7689+ // Verify the applicationStatus field
7690+ assert .Equal (t , cc .expectedAppStatuses , updatedAppSet .Status .ApplicationStatus , "applicationStatus should match expected value" )
77197691 })
77207692 }
77217693}
0 commit comments