Skip to content

Commit c7ce749

Browse files
committed
feat(auto-sync): Ignore refresh on explicit sync
Signed-off-by: Oliver Gondža <[email protected]>
1 parent dd2e7ca commit c7ce749

File tree

3 files changed

+71
-16
lines changed

3 files changed

+71
-16
lines changed

controller/appcontroller.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,10 +1424,15 @@ func (ctrl *ApplicationController) processRequestedAppOperation(app *appv1.Appli
14241424
return
14251425
}
14261426

1427+
logCtx.Warnf("Operation: %s, %v", app.Operation.InitiatedBy.Username, app.Operation.InitiatedBy.Automated)
14271428
if state.Operation.Retry.Refresh {
1428-
logCtx.Infof("Refreshing the retry")
1429-
state.Operation.Sync.Revision = ""
1430-
state.Operation.Sync.Revisions = nil
1429+
if app.Operation != nil && app.Operation.InitiatedBy.Automated {
1430+
logCtx.Infof("Refreshing the retry")
1431+
state.Operation.Sync.Revision = ""
1432+
state.Operation.Sync.Revisions = nil
1433+
} else {
1434+
logCtx.Infof("Not refreshing the retry during manual sync")
1435+
}
14311436
}
14321437

14331438
// Get rid of sync results and null out previous operation completion time

test/e2e/app_autosync_test.go

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ func TestAutoSyncSelfHealEnabled(t *testing.T) {
9494
})
9595
}
9696

97+
// TestAutoSyncRetryAndRefreshEnabled verifies that auto-sync+refresh picks up fixed commits automatically
9798
func TestAutoSyncRetryAndRefreshEnabled(t *testing.T) {
9899
limits := []int64{
99-
100, // Repeat enough times to see we move on to 3rd commit without reaching the limit
100+
100, // Repeat enough times to see we move on to the 3rd commit without reaching the limit
100101
-1, // Repeat forever
101102
}
102103

103104
for _, limit := range limits {
104105
Given(t).
105106
Path(guestbookPath).
106-
When().
107-
// Correctly configured app should be auto-synced once created
107+
When(). // I create an app with auto-sync and Refresh
108108
CreateFromFile(func(app *Application) {
109109
app.Spec.SyncPolicy = &SyncPolicy{
110110
Automated: &SyncPolicyAutomated{},
@@ -114,15 +114,14 @@ func TestAutoSyncRetryAndRefreshEnabled(t *testing.T) {
114114
},
115115
}
116116
}).
117-
Then().
117+
Then(). // It should auto-sync correctly
118118
Expect(OperationPhaseIs(OperationSucceeded)).
119119
Expect(SyncStatusIs(SyncStatusCodeSynced)).
120120
Expect(NoConditions()).
121-
// Broken commit should make the app stuck retrying indefinitely
122-
When().
121+
When(). // Auto-sync encounters broken commit
123122
PatchFile("guestbook-ui-deployment.yaml", `[{"op": "replace", "path": "/spec/revisionHistoryLimit", "value": "badValue"}]`).
124123
Refresh(RefreshTypeNormal).
125-
Then().
124+
Then(). // It should keep on trying to sync it
126125
Expect(OperationPhaseIs(OperationRunning)).
127126
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
128127
Expect(OperationRetriedTimes(1)).
@@ -133,13 +132,11 @@ func TestAutoSyncRetryAndRefreshEnabled(t *testing.T) {
133132
Expect(OperationPhaseIs(OperationRunning)).
134133
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
135134
Expect(OperationRetriedTimes(2)).
136-
// Push fix commit and see the app pick it up
137-
When().
138-
// Fix declaration
135+
When(). // I push a fixed commit (while auto-sync in progress)
139136
PatchFile("guestbook-ui-deployment.yaml", `[{"op": "replace", "path": "/spec/revisionHistoryLimit", "value": 42}]`).
140137
Refresh(RefreshTypeNormal).
141-
Then().
142-
// Wait for the sync retry to pick up new commit
138+
Then(). // Argo CD should pick it up and sync it successfully
139+
// Wait for the sync retry to pick up a new commit
143140
And(func(_ *Application) {
144141
time.Sleep(10 * time.Second)
145142
}).
@@ -148,3 +145,56 @@ func TestAutoSyncRetryAndRefreshEnabled(t *testing.T) {
148145
Expect(OperationPhaseIs(OperationSucceeded))
149146
}
150147
}
148+
149+
// TestAutoSyncRetryAndRefreshManualSync verifies that auto-sync+refresh do not pick new commits on manual sync
150+
func TestAutoSyncRetryAndRefreshManualSync(t *testing.T) {
151+
Given(t).
152+
Path(guestbookPath).
153+
When(). // I create an app with auto-sync and Refresh
154+
CreateFromFile(func(app *Application) {
155+
app.Spec.SyncPolicy = &SyncPolicy{
156+
Automated: &SyncPolicyAutomated{},
157+
Retry: &RetryStrategy{
158+
Limit: -1,
159+
Refresh: true,
160+
},
161+
}
162+
}).
163+
Then(). // It should auto-sync correctly
164+
Expect(OperationPhaseIs(OperationSucceeded)).
165+
Expect(SyncStatusIs(SyncStatusCodeSynced)).
166+
Expect(NoConditions()).
167+
When(). // I manually sync the app on a broken commit
168+
PatchFile("guestbook-ui-deployment.yaml", `[{"op": "replace", "path": "/spec/revisionHistoryLimit", "value": "badValue"}]`).
169+
Sync("--async").
170+
Then(). // Argo should keep on retrying
171+
Expect(OperationPhaseIs(OperationRunning)).
172+
//Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
173+
Expect(OperationRetriedTimes(1)).
174+
And(func(_ *Application) {
175+
// Wait to make sure the condition is consistent
176+
time.Sleep(10 * time.Second)
177+
}).
178+
Expect(OperationPhaseIs(OperationRunning)).
179+
//Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
180+
Expect(OperationRetriedTimes(2)).
181+
When(). // I push a fixed commit (during manual sync)
182+
PatchFile("guestbook-ui-deployment.yaml", `[{"op": "replace", "path": "/spec/revisionHistoryLimit", "value": 42}]`).
183+
Then(). // Argo CD should keep on retrying the one from the tyme of the sync start
184+
And(func(_ *Application) {
185+
// Wait to make sure the condition is consistent
186+
time.Sleep(10 * time.Second)
187+
}).
188+
Expect(OperationRetriedTimes(3)).
189+
When(). // I terminate the stuck sync and start a new manual one (when ref points to fixed commit)
190+
TerminateOp().
191+
And(func() {
192+
// Wait for the operation to terminate before starting new sync
193+
time.Sleep(1 * time.Second)
194+
}).
195+
Sync("--async").
196+
Then(). // Argo CD syncs successfully
197+
Expect(NoConditions()).
198+
Expect(SyncStatusIs(SyncStatusCodeSynced)).
199+
Expect(OperationPhaseIs(OperationSucceeded))
200+
}

test/e2e/fixture/app/expectation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func OperationRetriedTimes(expected int64) Expectation {
5757
return func(c *Consequences) (state, string) {
5858
operationState := c.app().Status.OperationState
5959
actual := operationState.RetryCount
60-
message := fmt.Sprintf("operation state retry cound should be %s, is %s, message: '%s'", expected, actual, operationState.Message)
60+
message := fmt.Sprintf("operation state retry cound should be %d, is %d, message: '%s'", expected, actual, operationState.Message)
6161
return simple(actual == expected, message)
6262
}
6363
}

0 commit comments

Comments
 (0)