Skip to content

Commit f26b7cd

Browse files
fix(ApplicationSet): Check strategy type to verify it's a progressive sync (#22563)
Signed-off-by: Fernando Crespo Gravalos <[email protected]> Signed-off-by: Fernando Crespo Grávalos <[email protected]> Co-authored-by: rumstead <[email protected]>
1 parent 0be041a commit f26b7cd

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

applicationset/controllers/applicationset_controller.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,16 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque
210210
appSyncMap := map[string]bool{}
211211

212212
if r.EnableProgressiveSyncs {
213-
if applicationSetInfo.Spec.Strategy == nil && len(applicationSetInfo.Status.ApplicationStatus) > 0 {
214-
// If appset used progressive sync but stopped, clean up the progressive sync application statuses
213+
if !isRollingSyncStrategy(&applicationSetInfo) && len(applicationSetInfo.Status.ApplicationStatus) > 0 {
214+
// If an appset was previously syncing with a `RollingSync` strategy but it has switched to the default strategy, clean up the progressive sync application statuses
215215
logCtx.Infof("Removing %v unnecessary AppStatus entries from ApplicationSet %v", len(applicationSetInfo.Status.ApplicationStatus), applicationSetInfo.Name)
216216

217217
err := r.setAppSetApplicationStatus(ctx, logCtx, &applicationSetInfo, []argov1alpha1.ApplicationSetApplicationStatus{})
218218
if err != nil {
219219
return ctrl.Result{}, fmt.Errorf("failed to clear previous AppSet application statuses for %v: %w", applicationSetInfo.Name, err)
220220
}
221-
} else if applicationSetInfo.Spec.Strategy != nil {
222-
// appset uses progressive sync
221+
} else if isRollingSyncStrategy(&applicationSetInfo) {
222+
// The appset uses progressive sync with `RollingSync` strategy
223223
for _, app := range currentApplications {
224224
appMap[app.Name] = app
225225
}
@@ -1000,8 +1000,14 @@ func appSyncEnabledForNextStep(appset *argov1alpha1.ApplicationSet, app argov1al
10001000
return true
10011001
}
10021002

1003+
func isRollingSyncStrategy(appset *argov1alpha1.ApplicationSet) bool {
1004+
// It's only RollingSync if the type specifically sets it
1005+
return appset.Spec.Strategy != nil && appset.Spec.Strategy.Type == "RollingSync" && appset.Spec.Strategy.RollingSync != nil
1006+
}
1007+
10031008
func progressiveSyncsRollingSyncStrategyEnabled(appset *argov1alpha1.ApplicationSet) bool {
1004-
return appset.Spec.Strategy != nil && appset.Spec.Strategy.RollingSync != nil && appset.Spec.Strategy.Type == "RollingSync" && len(appset.Spec.Strategy.RollingSync.Steps) > 0
1009+
// ProgressiveSync is enabled if the strategy is set to `RollingSync` + steps slice is not empty
1010+
return isRollingSyncStrategy(appset) && len(appset.Spec.Strategy.RollingSync.Steps) > 0
10051011
}
10061012

10071013
func isApplicationHealthy(app argov1alpha1.Application) bool {

applicationset/controllers/applicationset_controller_test.go

+59
Original file line numberDiff line numberDiff line change
@@ -7013,3 +7013,62 @@ func TestIgnoreNotAllowedNamespaces(t *testing.T) {
70137013
})
70147014
}
70157015
}
7016+
7017+
func TestIsRollingSyncStrategy(t *testing.T) {
7018+
tests := []struct {
7019+
name string
7020+
appset *v1alpha1.ApplicationSet
7021+
expected bool
7022+
}{
7023+
{
7024+
name: "RollingSync strategy is explicitly set",
7025+
appset: &v1alpha1.ApplicationSet{
7026+
Spec: v1alpha1.ApplicationSetSpec{
7027+
Strategy: &v1alpha1.ApplicationSetStrategy{
7028+
Type: "RollingSync",
7029+
RollingSync: &v1alpha1.ApplicationSetRolloutStrategy{
7030+
Steps: []v1alpha1.ApplicationSetRolloutStep{},
7031+
},
7032+
},
7033+
},
7034+
},
7035+
expected: true,
7036+
},
7037+
{
7038+
name: "AllAtOnce strategy is explicitly set",
7039+
appset: &v1alpha1.ApplicationSet{
7040+
Spec: v1alpha1.ApplicationSetSpec{
7041+
Strategy: &v1alpha1.ApplicationSetStrategy{
7042+
Type: "AllAtOnce",
7043+
},
7044+
},
7045+
},
7046+
expected: false,
7047+
},
7048+
{
7049+
name: "Strategy is empty",
7050+
appset: &v1alpha1.ApplicationSet{
7051+
Spec: v1alpha1.ApplicationSetSpec{
7052+
Strategy: &v1alpha1.ApplicationSetStrategy{},
7053+
},
7054+
},
7055+
expected: false,
7056+
},
7057+
{
7058+
name: "Strategy is nil",
7059+
appset: &v1alpha1.ApplicationSet{
7060+
Spec: v1alpha1.ApplicationSetSpec{
7061+
Strategy: nil,
7062+
},
7063+
},
7064+
expected: false,
7065+
},
7066+
}
7067+
7068+
for _, tt := range tests {
7069+
t.Run(tt.name, func(t *testing.T) {
7070+
result := isRollingSyncStrategy(tt.appset)
7071+
assert.Equal(t, tt.expected, result)
7072+
})
7073+
}
7074+
}

0 commit comments

Comments
 (0)