From 3027116c2fc98f6d9ef5cd4cbbbfa01cfd1c220f Mon Sep 17 00:00:00 2001 From: kkk777-7 Date: Wed, 17 Apr 2024 16:09:20 +0900 Subject: [PATCH] add: e2e and docs for force sync options Signed-off-by: kkk777-7 --- docs/user-guide/sync-options.md | 11 +++++++++++ test/e2e/sync_options_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) 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..a9406a26b3a5d 100644 --- a/test/e2e/sync_options_test.go +++ b/test/e2e/sync_options_test.go @@ -127,3 +127,30 @@ func TestSyncWithSkipHook(t *testing.T) { Then(). Expect(SyncStatusIs(SyncStatusCodeOutOfSync)) } + +func TestSyncWithForceReplace(t *testing.T) { + Given(t). + Path(guestbookPath). + When(). + CreateApp(). + Sync(). + 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). + Sync(). + 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). + Sync(). + Then(). + Expect(SyncStatusIs(SyncStatusCodeSynced)) +}