Skip to content

Commit d0b2a6c

Browse files
argo-cd-cherry-pick-bot[bot]dudineatodaywasawesomereggie-k
authored
fix: Fix excessive ls-remote requests on monorepos with Auto Sync enabled apps (26277) (cherry-pick #26278 for 3.3) (#26372)
Signed-off-by: Eugene Doudine <eugene.doudine@octopus.com> Co-authored-by: dudinea <eugene.doudine@octopus.com> Co-authored-by: Dan Garfield <dan.garfield@octopus.com> Co-authored-by: Regina Voloshin <regina.voloshin@codefresh.io>
1 parent e464f6a commit d0b2a6c

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

controller/appcontroller.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,18 @@ func (ctrl *ApplicationController) processRequestedAppOperation(app *appv1.Appli
15591559
// if we just completed an operation, force a refresh so that UI will report up-to-date
15601560
// sync/health information
15611561
if _, err := cache.MetaNamespaceKeyFunc(app); err == nil {
1562-
// force app refresh with using CompareWithLatest comparison type and trigger app reconciliation loop
1563-
ctrl.requestAppRefresh(app.QualifiedName(), CompareWithLatestForceResolve.Pointer(), nil)
1562+
var compareWith CompareWith
1563+
if state.Operation.InitiatedBy.Automated {
1564+
// Do not force revision resolution on automated operations because
1565+
// this would cause excessive Ls-Remote requests on monorepo commits
1566+
compareWith = CompareWithLatest
1567+
} else {
1568+
// Force app refresh with using most recent resolved revision after sync,
1569+
// so UI won't show a just synced application being out of sync if it was
1570+
// synced after commit but before app. refresh (see #18153)
1571+
compareWith = CompareWithLatestForceResolve
1572+
}
1573+
ctrl.requestAppRefresh(app.QualifiedName(), compareWith.Pointer(), nil)
15641574
} else {
15651575
logCtx.WithError(err).Warn("Fails to requeue application")
15661576
}

controller/appcontroller_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,6 +2633,41 @@ func TestProcessRequestedAppOperation_Successful(t *testing.T) {
26332633
assert.Equal(t, CompareWithLatestForceResolve, level)
26342634
}
26352635

2636+
func TestProcessRequestedAppAutomatedOperation_Successful(t *testing.T) {
2637+
app := newFakeApp()
2638+
app.Spec.Project = "default"
2639+
app.Operation = &v1alpha1.Operation{
2640+
Sync: &v1alpha1.SyncOperation{},
2641+
InitiatedBy: v1alpha1.OperationInitiator{
2642+
Automated: true,
2643+
},
2644+
}
2645+
ctrl := newFakeController(t.Context(), &fakeData{
2646+
apps: []runtime.Object{app, &defaultProj},
2647+
manifestResponses: []*apiclient.ManifestResponse{{
2648+
Manifests: []string{},
2649+
}},
2650+
}, nil)
2651+
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
2652+
receivedPatch := map[string]any{}
2653+
fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) {
2654+
if patchAction, ok := action.(kubetesting.PatchAction); ok {
2655+
require.NoError(t, json.Unmarshal(patchAction.GetPatch(), &receivedPatch))
2656+
}
2657+
return true, &v1alpha1.Application{}, nil
2658+
})
2659+
2660+
ctrl.processRequestedAppOperation(app)
2661+
2662+
phase, _, _ := unstructured.NestedString(receivedPatch, "status", "operationState", "phase")
2663+
message, _, _ := unstructured.NestedString(receivedPatch, "status", "operationState", "message")
2664+
assert.Equal(t, string(synccommon.OperationSucceeded), phase)
2665+
assert.Equal(t, "successfully synced (no more tasks)", message)
2666+
ok, level := ctrl.isRefreshRequested(ctrl.toAppKey(app.Name))
2667+
assert.True(t, ok)
2668+
assert.Equal(t, CompareWithLatest, level)
2669+
}
2670+
26362671
func TestProcessRequestedAppOperation_SyncTimeout(t *testing.T) {
26372672
testCases := []struct {
26382673
name string

0 commit comments

Comments
 (0)