Skip to content

Commit f7ad2ad

Browse files
gcp-cherry-pick-bot[bot]fcrespofastlyrumstead
authored
fix(ApplicationSet): Check strategy type to verify it's a progressive sync (cherry-pick #22563) (#22833)
Signed-off-by: Fernando Crespo Gravalos <[email protected]> Signed-off-by: Fernando Crespo Grávalos <[email protected]> Co-authored-by: Fernando Crespo Grávalos <[email protected]> Co-authored-by: rumstead <[email protected]>
1 parent b163de0 commit f7ad2ad

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
}
@@ -1008,8 +1008,14 @@ func appSyncEnabledForNextStep(appset *argov1alpha1.ApplicationSet, app argov1al
10081008
return true
10091009
}
10101010

1011+
func isRollingSyncStrategy(appset *argov1alpha1.ApplicationSet) bool {
1012+
// It's only RollingSync if the type specifically sets it
1013+
return appset.Spec.Strategy != nil && appset.Spec.Strategy.Type == "RollingSync" && appset.Spec.Strategy.RollingSync != nil
1014+
}
1015+
10111016
func progressiveSyncsRollingSyncStrategyEnabled(appset *argov1alpha1.ApplicationSet) bool {
1012-
return appset.Spec.Strategy != nil && appset.Spec.Strategy.RollingSync != nil && appset.Spec.Strategy.Type == "RollingSync" && len(appset.Spec.Strategy.RollingSync.Steps) > 0
1017+
// ProgressiveSync is enabled if the strategy is set to `RollingSync` + steps slice is not empty
1018+
return isRollingSyncStrategy(appset) && len(appset.Spec.Strategy.RollingSync.Steps) > 0
10131019
}
10141020

10151021
func isApplicationHealthy(app argov1alpha1.Application) bool {

applicationset/controllers/applicationset_controller_test.go

+59
Original file line numberDiff line numberDiff line change
@@ -6736,3 +6736,62 @@ func TestIgnoreNotAllowedNamespaces(t *testing.T) {
67366736
})
67376737
}
67386738
}
6739+
6740+
func TestIsRollingSyncStrategy(t *testing.T) {
6741+
tests := []struct {
6742+
name string
6743+
appset *v1alpha1.ApplicationSet
6744+
expected bool
6745+
}{
6746+
{
6747+
name: "RollingSync strategy is explicitly set",
6748+
appset: &v1alpha1.ApplicationSet{
6749+
Spec: v1alpha1.ApplicationSetSpec{
6750+
Strategy: &v1alpha1.ApplicationSetStrategy{
6751+
Type: "RollingSync",
6752+
RollingSync: &v1alpha1.ApplicationSetRolloutStrategy{
6753+
Steps: []v1alpha1.ApplicationSetRolloutStep{},
6754+
},
6755+
},
6756+
},
6757+
},
6758+
expected: true,
6759+
},
6760+
{
6761+
name: "AllAtOnce strategy is explicitly set",
6762+
appset: &v1alpha1.ApplicationSet{
6763+
Spec: v1alpha1.ApplicationSetSpec{
6764+
Strategy: &v1alpha1.ApplicationSetStrategy{
6765+
Type: "AllAtOnce",
6766+
},
6767+
},
6768+
},
6769+
expected: false,
6770+
},
6771+
{
6772+
name: "Strategy is empty",
6773+
appset: &v1alpha1.ApplicationSet{
6774+
Spec: v1alpha1.ApplicationSetSpec{
6775+
Strategy: &v1alpha1.ApplicationSetStrategy{},
6776+
},
6777+
},
6778+
expected: false,
6779+
},
6780+
{
6781+
name: "Strategy is nil",
6782+
appset: &v1alpha1.ApplicationSet{
6783+
Spec: v1alpha1.ApplicationSetSpec{
6784+
Strategy: nil,
6785+
},
6786+
},
6787+
expected: false,
6788+
},
6789+
}
6790+
6791+
for _, tt := range tests {
6792+
t.Run(tt.name, func(t *testing.T) {
6793+
result := isRollingSyncStrategy(tt.appset)
6794+
assert.Equal(t, tt.expected, result)
6795+
})
6796+
}
6797+
}

0 commit comments

Comments
 (0)