From 92a3c3d727df3c15491a9202c4b6da85ed7a02cd Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Sun, 23 Feb 2025 22:51:30 +0530 Subject: [PATCH] fix: correctly set compareWith when requesting app refresh with delay (fixes #18998) (cherry-pick #21298) (#21952) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Xiaonan Shen Co-authored-by: Xiaonan Shen Co-authored-by: 沈啸楠 --- controller/appcontroller.go | 2 +- controller/appcontroller_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/controller/appcontroller.go b/controller/appcontroller.go index f9d9614d73b43..44d1a49398cf1 100644 --- a/controller/appcontroller.go +++ b/controller/appcontroller.go @@ -940,7 +940,7 @@ func (ctrl *ApplicationController) requestAppRefresh(appName string, compareWith key := ctrl.toAppKey(appName) if compareWith != nil && after != nil { - ctrl.appComparisonTypeRefreshQueue.AddAfter(fmt.Sprintf("%s/%d", key, compareWith), *after) + ctrl.appComparisonTypeRefreshQueue.AddAfter(fmt.Sprintf("%s/%d", key, *compareWith), *after) } else { if compareWith != nil { ctrl.refreshRequestedAppsMutex.Lock() diff --git a/controller/appcontroller_test.go b/controller/appcontroller_test.go index 90d7c2ee2e359..e627f37bd82a8 100644 --- a/controller/appcontroller_test.go +++ b/controller/appcontroller_test.go @@ -1409,6 +1409,25 @@ func TestNeedRefreshAppStatus(t *testing.T) { assert.Equal(t, CompareWithRecent, compareWith) }) + t.Run("requesting refresh with delay gives correct compression level", func(t *testing.T) { + needRefresh, _, _ := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour) + assert.False(t, needRefresh) + + // use a one-off controller so other tests don't have a manual refresh request + ctrl := newFakeController(&fakeData{apps: []runtime.Object{}}, nil) + + // refresh app with a non-nil delay + // use zero-second delay to test the add later logic without waiting in the test + delay := time.Duration(0) + ctrl.requestAppRefresh(app.Name, CompareWithRecent.Pointer(), &delay) + + ctrl.processAppComparisonTypeQueueItem() + needRefresh, refreshType, compareWith := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour) + assert.True(t, needRefresh) + assert.Equal(t, v1alpha1.RefreshTypeNormal, refreshType) + assert.Equal(t, CompareWithRecent, compareWith) + }) + t.Run("refresh application which status is not reconciled using latest commit", func(t *testing.T) { app := app.DeepCopy() needRefresh, _, _ := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour)