diff --git a/docs/user-guide/sync-options.md b/docs/user-guide/sync-options.md index a563821967d04..74a694ceadb8d 100644 --- a/docs/user-guide/sync-options.md +++ b/docs/user-guide/sync-options.md @@ -165,6 +165,17 @@ metadata: argocd.argoproj.io/sync-options: Replace=true ``` +## Force Sync + +For certain resources you might want to delete and recreate. e.g. job resources that should run every time when syncing. +In such cases you might use `Force=true` sync option in target resources annotation: + +```yaml +metadata: + annotations: + argocd.argoproj.io/sync-options: Force=true,Replace=true +``` + ## Server-Side Apply This option enables Kubernetes diff --git a/test/e2e/sync_options_test.go b/test/e2e/sync_options_test.go index 3eb7140787097..2e50119f68395 100644 --- a/test/e2e/sync_options_test.go +++ b/test/e2e/sync_options_test.go @@ -127,3 +127,29 @@ func TestSyncWithSkipHook(t *testing.T) { Then(). Expect(SyncStatusIs(SyncStatusCodeOutOfSync)) } + +func TestSyncWithForceReplace(t *testing.T) { + Given(t). + Path(guestbookPath). + When(). + CreateFromFile(func(app *Application) { + app.Spec.SyncPolicy = &SyncPolicy{Automated: &SyncPolicyAutomated{SelfHeal: true}} + }). + Then(). + Expect(SyncStatusIs(SyncStatusCodeSynced)). + // app only having `Replace=true` annotation should not sync if change in immutable field + When(). + PatchFile("guestbook-ui-deployment.yaml", `[{ "op": "add", "path": "/metadata/annotations", "value": { "argocd.argoproj.io/sync-options": "Replace=true" }}]`). + PatchFile("guestbook-ui-deployment.yaml", `[{ "op": "add", "path": "/spec/selector/matchLabels/env", "value": "e2e" }, { "op": "add", "path": "/spec/template/metadata/labels/env", "value": "e2e" }]`). + PatchFile("guestbook-ui-deployment.yaml", `[{ "op": "replace", "path": "/spec/replicas", "value": 1 }]`). + Refresh(RefreshTypeNormal). + Then(). + Expect(SyncStatusIs(SyncStatusCodeOutOfSync)). + // app having `Replace=true` and `Force=true` annotation should sync if change in immutable field + When(). + TerminateOp(). + PatchFile("guestbook-ui-deployment.yaml", `[{ "op": "replace", "path": "/metadata/annotations", "value": { "argocd.argoproj.io/sync-options": "Force=true,Replace=true" }}]`). + Refresh(RefreshTypeNormal). + Then(). + Expect(SyncStatusIs(SyncStatusCodeSynced)) +}