Skip to content

Commit 25dc960

Browse files
dshmelevrumstead
andauthored
fix(applicationset_controller): requeue by ApplicationStatus changes (#23043)
Signed-off-by: Dmitry Shmelev <[email protected]> Signed-off-by: Dmitry Shmelev <[email protected]> Co-authored-by: rumstead <[email protected]>
1 parent a0a82a1 commit 25dc960

File tree

2 files changed

+92
-38
lines changed

2 files changed

+92
-38
lines changed

applicationset/controllers/applicationset_controller.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ func (r *ApplicationSetReconciler) SetupWithManager(mgr ctrl.Manager, enableProg
553553
}
554554

555555
appOwnsHandler := getApplicationOwnsHandler(enableProgressiveSyncs)
556-
appSetOwnsHandler := getApplicationSetOwnsHandler()
556+
appSetOwnsHandler := getApplicationSetOwnsHandler(enableProgressiveSyncs)
557557

558558
return ctrl.NewControllerManagedBy(mgr).WithOptions(controller.Options{
559559
MaxConcurrentReconciles: maxConcurrentReconciliations,
@@ -1550,7 +1550,7 @@ func shouldRequeueForApplication(appOld *argov1alpha1.Application, appNew *argov
15501550
return false
15511551
}
15521552

1553-
func getApplicationSetOwnsHandler() predicate.Funcs {
1553+
func getApplicationSetOwnsHandler(enableProgressiveSyncs bool) predicate.Funcs {
15541554
return predicate.Funcs{
15551555
CreateFunc: func(e event.CreateEvent) bool {
15561556
appSet, isApp := e.Object.(*argov1alpha1.ApplicationSet)
@@ -1579,7 +1579,7 @@ func getApplicationSetOwnsHandler() predicate.Funcs {
15791579
if !isAppSet {
15801580
return false
15811581
}
1582-
requeue := shouldRequeueForApplicationSet(appSetOld, appSetNew)
1582+
requeue := shouldRequeueForApplicationSet(appSetOld, appSetNew, enableProgressiveSyncs)
15831583
log.WithField("applicationset", appSetNew.QualifiedName()).
15841584
WithField("requeue", requeue).Debugln("received update event")
15851585
return requeue
@@ -1597,10 +1597,18 @@ func getApplicationSetOwnsHandler() predicate.Funcs {
15971597
}
15981598

15991599
// shouldRequeueForApplicationSet determines when we need to requeue an applicationset
1600-
func shouldRequeueForApplicationSet(appSetOld, appSetNew *argov1alpha1.ApplicationSet) bool {
1600+
func shouldRequeueForApplicationSet(appSetOld, appSetNew *argov1alpha1.ApplicationSet, enableProgressiveSyncs bool) bool {
16011601
if appSetOld == nil || appSetNew == nil {
16021602
return false
16031603
}
1604+
1605+
// Requeue if any ApplicationStatus.Status changed for Progressive sync strategy
1606+
if enableProgressiveSyncs {
1607+
if !cmp.Equal(appSetOld.Status.ApplicationStatus, appSetNew.Status.ApplicationStatus, cmpopts.EquateEmpty()) {
1608+
return true
1609+
}
1610+
}
1611+
16041612
// only compare the applicationset spec, annotations, labels and finalizers, specifically avoiding
16051613
// the status field. status is owned by the applicationset controller,
16061614
// and we do not need to requeue when it does bookkeeping

applicationset/controllers/applicationset_controller_test.go

Lines changed: 80 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6678,8 +6678,6 @@ func TestMigrateStatus(t *testing.T) {
66786678
}
66796679

66806680
func TestApplicationSetOwnsHandlerUpdate(t *testing.T) {
6681-
ownsHandler := getApplicationSetOwnsHandler()
6682-
66836681
buildAppSet := func(annotations map[string]string) *v1alpha1.ApplicationSet {
66846682
return &v1alpha1.ApplicationSet{
66856683
ObjectMeta: metav1.ObjectMeta{
@@ -6689,10 +6687,11 @@ func TestApplicationSetOwnsHandlerUpdate(t *testing.T) {
66896687
}
66906688

66916689
tests := []struct {
6692-
name string
6693-
appSetOld crtclient.Object
6694-
appSetNew crtclient.Object
6695-
want bool
6690+
name string
6691+
appSetOld crtclient.Object
6692+
appSetNew crtclient.Object
6693+
enableProgressiveSyncs bool
6694+
want bool
66966695
}{
66976696
{
66986697
name: "Different Spec",
@@ -6710,13 +6709,15 @@ func TestApplicationSetOwnsHandlerUpdate(t *testing.T) {
67106709
},
67116710
},
67126711
},
6713-
want: true,
6712+
enableProgressiveSyncs: false,
6713+
want: true,
67146714
},
67156715
{
6716-
name: "Different Annotations",
6717-
appSetOld: buildAppSet(map[string]string{"key1": "value1"}),
6718-
appSetNew: buildAppSet(map[string]string{"key1": "value2"}),
6719-
want: true,
6716+
name: "Different Annotations",
6717+
appSetOld: buildAppSet(map[string]string{"key1": "value1"}),
6718+
appSetNew: buildAppSet(map[string]string{"key1": "value2"}),
6719+
enableProgressiveSyncs: false,
6720+
want: true,
67206721
},
67216722
{
67226723
name: "Different Labels",
@@ -6730,7 +6731,8 @@ func TestApplicationSetOwnsHandlerUpdate(t *testing.T) {
67306731
Labels: map[string]string{"key1": "value2"},
67316732
},
67326733
},
6733-
want: true,
6734+
enableProgressiveSyncs: false,
6735+
want: true,
67346736
},
67356737
{
67366738
name: "Different Finalizers",
@@ -6744,7 +6746,8 @@ func TestApplicationSetOwnsHandlerUpdate(t *testing.T) {
67446746
Finalizers: []string{"finalizer2"},
67456747
},
67466748
},
6747-
want: true,
6749+
enableProgressiveSyncs: false,
6750+
want: true,
67486751
},
67496752
{
67506753
name: "No Changes",
@@ -6772,15 +6775,17 @@ func TestApplicationSetOwnsHandlerUpdate(t *testing.T) {
67726775
Finalizers: []string{"finalizer1"},
67736776
},
67746777
},
6775-
want: false,
6778+
enableProgressiveSyncs: false,
6779+
want: false,
67766780
},
67776781
{
67786782
name: "annotation removed",
67796783
appSetOld: buildAppSet(map[string]string{
67806784
argocommon.AnnotationApplicationSetRefresh: "true",
67816785
}),
6782-
appSetNew: buildAppSet(map[string]string{}),
6783-
want: false,
6786+
appSetNew: buildAppSet(map[string]string{}),
6787+
enableProgressiveSyncs: false,
6788+
want: false,
67846789
},
67856790
{
67866791
name: "annotation not removed",
@@ -6790,43 +6795,48 @@ func TestApplicationSetOwnsHandlerUpdate(t *testing.T) {
67906795
appSetNew: buildAppSet(map[string]string{
67916796
argocommon.AnnotationApplicationSetRefresh: "true",
67926797
}),
6793-
want: false,
6798+
enableProgressiveSyncs: false,
6799+
want: false,
67946800
},
67956801
{
67966802
name: "annotation added",
67976803
appSetOld: buildAppSet(map[string]string{}),
67986804
appSetNew: buildAppSet(map[string]string{
67996805
argocommon.AnnotationApplicationSetRefresh: "true",
68006806
}),
6801-
want: true,
6807+
enableProgressiveSyncs: false,
6808+
want: true,
68026809
},
68036810
{
6804-
name: "old object is not an appset",
6805-
appSetOld: &v1alpha1.Application{},
6806-
appSetNew: buildAppSet(map[string]string{}),
6807-
want: false,
6811+
name: "old object is not an appset",
6812+
appSetOld: &v1alpha1.Application{},
6813+
appSetNew: buildAppSet(map[string]string{}),
6814+
enableProgressiveSyncs: false,
6815+
want: false,
68086816
},
68096817
{
6810-
name: "new object is not an appset",
6811-
appSetOld: buildAppSet(map[string]string{}),
6812-
appSetNew: &v1alpha1.Application{},
6813-
want: false,
6818+
name: "new object is not an appset",
6819+
appSetOld: buildAppSet(map[string]string{}),
6820+
appSetNew: &v1alpha1.Application{},
6821+
enableProgressiveSyncs: false,
6822+
want: false,
68146823
},
68156824
}
68166825

68176826
for _, tt := range tests {
68186827
t.Run(tt.name, func(t *testing.T) {
6828+
ownsHandler := getApplicationSetOwnsHandler(tt.enableProgressiveSyncs)
68196829
requeue := ownsHandler.UpdateFunc(event.UpdateEvent{
68206830
ObjectOld: tt.appSetOld,
68216831
ObjectNew: tt.appSetNew,
68226832
})
6823-
assert.Equalf(t, tt.want, requeue, "ownsHandler.UpdateFunc(%v, %v)", tt.appSetOld, tt.appSetNew)
6833+
assert.Equalf(t, tt.want, requeue, "ownsHandler.UpdateFunc(%v, %v, %t)", tt.appSetOld, tt.appSetNew, tt.enableProgressiveSyncs)
68246834
})
68256835
}
68266836
}
68276837

68286838
func TestApplicationSetOwnsHandlerGeneric(t *testing.T) {
6829-
ownsHandler := getApplicationSetOwnsHandler()
6839+
ownsHandler := getApplicationSetOwnsHandler(false)
68306840
tests := []struct {
68316841
name string
68326842
obj crtclient.Object
@@ -6855,7 +6865,7 @@ func TestApplicationSetOwnsHandlerGeneric(t *testing.T) {
68556865
}
68566866

68576867
func TestApplicationSetOwnsHandlerCreate(t *testing.T) {
6858-
ownsHandler := getApplicationSetOwnsHandler()
6868+
ownsHandler := getApplicationSetOwnsHandler(false)
68596869
tests := []struct {
68606870
name string
68616871
obj crtclient.Object
@@ -6884,7 +6894,7 @@ func TestApplicationSetOwnsHandlerCreate(t *testing.T) {
68846894
}
68856895

68866896
func TestApplicationSetOwnsHandlerDelete(t *testing.T) {
6887-
ownsHandler := getApplicationSetOwnsHandler()
6897+
ownsHandler := getApplicationSetOwnsHandler(false)
68886898
tests := []struct {
68896899
name string
68906900
obj crtclient.Object
@@ -6914,19 +6924,55 @@ func TestApplicationSetOwnsHandlerDelete(t *testing.T) {
69146924

69156925
func TestShouldRequeueForApplicationSet(t *testing.T) {
69166926
type args struct {
6917-
appSetOld *v1alpha1.ApplicationSet
6918-
appSetNew *v1alpha1.ApplicationSet
6927+
appSetOld *v1alpha1.ApplicationSet
6928+
appSetNew *v1alpha1.ApplicationSet
6929+
enableProgressiveSyncs bool
69196930
}
69206931
tests := []struct {
69216932
name string
69226933
args args
69236934
want bool
69246935
}{
6925-
{name: "NilAppSet", args: args{appSetNew: &v1alpha1.ApplicationSet{}, appSetOld: nil}, want: false},
6936+
{
6937+
name: "NilAppSet",
6938+
args: args{
6939+
appSetNew: &v1alpha1.ApplicationSet{},
6940+
appSetOld: nil,
6941+
enableProgressiveSyncs: false,
6942+
},
6943+
want: false,
6944+
},
6945+
{
6946+
name: "ApplicationSetApplicationStatusChanged",
6947+
args: args{
6948+
appSetOld: &v1alpha1.ApplicationSet{
6949+
Status: v1alpha1.ApplicationSetStatus{
6950+
ApplicationStatus: []v1alpha1.ApplicationSetApplicationStatus{
6951+
{
6952+
Application: "app1",
6953+
Status: "Healthy",
6954+
},
6955+
},
6956+
},
6957+
},
6958+
appSetNew: &v1alpha1.ApplicationSet{
6959+
Status: v1alpha1.ApplicationSetStatus{
6960+
ApplicationStatus: []v1alpha1.ApplicationSetApplicationStatus{
6961+
{
6962+
Application: "app1",
6963+
Status: "Waiting",
6964+
},
6965+
},
6966+
},
6967+
},
6968+
enableProgressiveSyncs: true,
6969+
},
6970+
want: true,
6971+
},
69266972
}
69276973
for _, tt := range tests {
69286974
t.Run(tt.name, func(t *testing.T) {
6929-
assert.Equalf(t, tt.want, shouldRequeueForApplicationSet(tt.args.appSetOld, tt.args.appSetNew), "shouldRequeueForApplicationSet(%v, %v)", tt.args.appSetOld, tt.args.appSetNew)
6975+
assert.Equalf(t, tt.want, shouldRequeueForApplicationSet(tt.args.appSetOld, tt.args.appSetNew, tt.args.enableProgressiveSyncs), "shouldRequeueForApplicationSet(%v, %v)", tt.args.appSetOld, tt.args.appSetNew)
69306976
})
69316977
}
69326978
}

0 commit comments

Comments
 (0)