From ddec0f2be96c359ec129110e104f60b939578401 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Thu, 20 Jul 2023 18:54:52 +0300 Subject: [PATCH 1/8] feat: support apply out of sync flag only Signed-off-by: pashakostohrys --- cmd/argocd/commands/app.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/argocd/commands/app.go b/cmd/argocd/commands/app.go index f45efb427053c..dec772b4472e7 100644 --- a/cmd/argocd/commands/app.go +++ b/cmd/argocd/commands/app.go @@ -1535,6 +1535,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co force bool replace bool serverSideApply bool + applyOutOfSyncOnly bool async bool retryLimit int64 retryBackoffDuration time.Duration @@ -1707,6 +1708,9 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co if serverSideApply { items = append(items, common.SyncOptionServerSideApply) } + if applyOutOfSyncOnly { + items = append(items, common.SyncOptionApplyOutOfSyncOnly) + } if len(items) == 0 { // for prevent send even empty array if not need From 05f2ae454f237dc740f880d0ab8388b4165d1a63 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Wed, 9 Aug 2023 18:03:46 +0300 Subject: [PATCH 2/8] update engine version Signed-off-by: pashakostohrys --- go.mod | 2 +- go.sum | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 94437d3427379..682c448d01c0d 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/TomOnTime/utfutil v0.0.0-20180511104225-09c41003ee1d github.com/alicebob/miniredis/v2 v2.30.4 github.com/antonmedv/expr v1.12.5 - github.com/argoproj/gitops-engine v0.7.1-0.20230607163028-425d65e07695 + github.com/argoproj/gitops-engine v0.7.1-0.20230809134534-ed7c77a9290b github.com/argoproj/notifications-engine v0.4.1-0.20230620204159-3446d4ae8520 github.com/argoproj/pkg v0.13.7-0.20230626144333-d56162821bd1 github.com/aws/aws-sdk-go v1.44.298 diff --git a/go.sum b/go.sum index 9c1315e2d479c..a498b0fec59a4 100644 --- a/go.sum +++ b/go.sum @@ -695,6 +695,10 @@ github.com/apache/thrift v0.16.0/go.mod h1:PHK3hniurgQaNMZYaCLEqXKsYK8upmhPbmdP2 github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc/go.mod h1:OawnOmAL4ZX3YaPdN+8HTNwBveT1jMsqP74moa9XUbE= github.com/argoproj/gitops-engine v0.7.1-0.20230607163028-425d65e07695 h1:w8OPbqHyhWxLyC4LZgs5JBUe7AOkJpNZqFa92yy7Kmc= github.com/argoproj/gitops-engine v0.7.1-0.20230607163028-425d65e07695/go.mod h1:WpA/B7tgwfz+sdNE3LqrTrb7ArEY1FOPI2pAGI0hfPc= +github.com/argoproj/gitops-engine v0.7.1-0.20230809134534-ed7c77a9290b h1:0Nttg/giUaT52BticAPRmbEMZWBDxisy+hltb1TglVM= +github.com/argoproj/gitops-engine v0.7.1-0.20230809134534-ed7c77a9290b/go.mod h1:WpA/B7tgwfz+sdNE3LqrTrb7ArEY1FOPI2pAGI0hfPc= +github.com/argoproj/gitops-engine v0.7.3 h1:0ZlRTReAJG5Y1PviQ8ZIJq/+VowxWe2uFwoXqYcbtXU= +github.com/argoproj/gitops-engine v0.7.3/go.mod h1:pRgVpLW7pZqf7n3COJ7UcDepk4cI61LAcJd64Q3Jq/c= github.com/argoproj/notifications-engine v0.4.1-0.20230620204159-3446d4ae8520 h1:ZCpg1Zk78E8QxMI52w6ZIddxkBHv27YWmfWQdxxWUkw= github.com/argoproj/notifications-engine v0.4.1-0.20230620204159-3446d4ae8520/go.mod h1:sbhf4EjAUGAqRdHIzifDIiWsjlsTfmytVJJCCiUdyVA= github.com/argoproj/pkg v0.13.7-0.20230626144333-d56162821bd1 h1:qsHwwOJ21K2Ao0xPju1sNuqphyMnMYkyB3ZLoLtxWpo= From e50bd132c980bcb83e917e42aa6a71771e176f3a Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Thu, 10 Aug 2023 12:14:37 +0300 Subject: [PATCH 3/8] update gitops engine version Signed-off-by: pashakostohrys --- go.sum | 4 ---- 1 file changed, 4 deletions(-) diff --git a/go.sum b/go.sum index 7dec9167e7cea..3a230648721ad 100644 --- a/go.sum +++ b/go.sum @@ -710,12 +710,8 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.16.0/go.mod h1:PHK3hniurgQaNMZYaCLEqXKsYK8upmhPbmdP2FXSqgU= github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc/go.mod h1:OawnOmAL4ZX3YaPdN+8HTNwBveT1jMsqP74moa9XUbE= -github.com/argoproj/gitops-engine v0.7.1-0.20230607163028-425d65e07695 h1:w8OPbqHyhWxLyC4LZgs5JBUe7AOkJpNZqFa92yy7Kmc= -github.com/argoproj/gitops-engine v0.7.1-0.20230607163028-425d65e07695/go.mod h1:WpA/B7tgwfz+sdNE3LqrTrb7ArEY1FOPI2pAGI0hfPc= github.com/argoproj/gitops-engine v0.7.1-0.20230809134534-ed7c77a9290b h1:0Nttg/giUaT52BticAPRmbEMZWBDxisy+hltb1TglVM= github.com/argoproj/gitops-engine v0.7.1-0.20230809134534-ed7c77a9290b/go.mod h1:WpA/B7tgwfz+sdNE3LqrTrb7ArEY1FOPI2pAGI0hfPc= -github.com/argoproj/gitops-engine v0.7.3 h1:0ZlRTReAJG5Y1PviQ8ZIJq/+VowxWe2uFwoXqYcbtXU= -github.com/argoproj/gitops-engine v0.7.3/go.mod h1:pRgVpLW7pZqf7n3COJ7UcDepk4cI61LAcJd64Q3Jq/c= github.com/argoproj/notifications-engine v0.4.1-0.20230620204159-3446d4ae8520 h1:ZCpg1Zk78E8QxMI52w6ZIddxkBHv27YWmfWQdxxWUkw= github.com/argoproj/notifications-engine v0.4.1-0.20230620204159-3446d4ae8520/go.mod h1:sbhf4EjAUGAqRdHIzifDIiWsjlsTfmytVJJCCiUdyVA= github.com/argoproj/pkg v0.13.7-0.20230626144333-d56162821bd1 h1:qsHwwOJ21K2Ao0xPju1sNuqphyMnMYkyB3ZLoLtxWpo= From 9681beebb99b9fc8390ff8ca68b7225b25ad075f Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Thu, 10 Aug 2023 14:28:16 +0300 Subject: [PATCH 4/8] add cli option Signed-off-by: pashakostohrys --- cmd/argocd/commands/app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/argocd/commands/app.go b/cmd/argocd/commands/app.go index d246ba6ee5952..28034fcfb284e 100644 --- a/cmd/argocd/commands/app.go +++ b/cmd/argocd/commands/app.go @@ -1817,6 +1817,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co command.Flags().BoolVar(&force, "force", false, "Use a force apply") command.Flags().BoolVar(&replace, "replace", false, "Use a kubectl create/replace instead apply") command.Flags().BoolVar(&serverSideApply, "server-side", false, "Use server-side apply while syncing the application") + command.Flags().BoolVar(&applyOutOfSyncOnly, "apply-out-of-sync-only", false, "Use out-of-sync apply that sync only out of sync resources") command.Flags().BoolVar(&async, "async", false, "Do not wait for application to sync before continuing") command.Flags().StringVar(&local, "local", "", "Path to a local directory. When this flag is present no git queries will be made") command.Flags().StringVar(&localRepoRoot, "local-repo-root", "/", "Path to the repository root. Used together with --local allows setting the repository root") From eb1c365d0cf1a2a744284c74fa701da88749f555 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Fri, 11 Aug 2023 21:42:55 +0300 Subject: [PATCH 5/8] feat: verify apply out of sync flag Signed-off-by: pashakostohrys --- test/e2e/fixture/app/actions.go | 4 ++++ test/e2e/fixture/app/context.go | 6 ++++++ test/e2e/sync_options_test.go | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/test/e2e/fixture/app/actions.go b/test/e2e/fixture/app/actions.go index 5a2ca2748885a..f4fd167db1024 100644 --- a/test/e2e/fixture/app/actions.go +++ b/test/e2e/fixture/app/actions.go @@ -366,6 +366,10 @@ func (a *Actions) Sync(args ...string) *Actions { args = append(args, "--force") } + if a.context.applyOutOfSyncOnly { + args = append(args, "--apply-out-of-sync-only") + } + if a.context.replace { args = append(args, "--replace") } diff --git a/test/e2e/fixture/app/context.go b/test/e2e/fixture/app/context.go index d653b6a0280ca..aa961f30d15fa 100644 --- a/test/e2e/fixture/app/context.go +++ b/test/e2e/fixture/app/context.go @@ -38,6 +38,7 @@ type Context struct { project string revision string force bool + applyOutOfSyncOnly bool directoryRecurse bool replace bool helmPassCredentials bool @@ -341,6 +342,11 @@ func (c *Context) Force() *Context { return c } +func (c *Context) ApplyOutOfSyncOnly() *Context { + c.applyOutOfSyncOnly = true + return c +} + func (c *Context) HelmPassCredentials() *Context { c.helmPassCredentials = true return c diff --git a/test/e2e/sync_options_test.go b/test/e2e/sync_options_test.go index 657c8b117705b..b26034e4a7327 100644 --- a/test/e2e/sync_options_test.go +++ b/test/e2e/sync_options_test.go @@ -80,6 +80,23 @@ func TestSyncWithStatusIgnored(t *testing.T) { Expect(SyncStatusIs(SyncStatusCodeSynced)) } +func TestSyncWithApplyOutOfSyncOnly(t *testing.T) { + Given(t). + Path(guestbookPath). + ApplyOutOfSyncOnly(). + When(). + CreateFromFile(func(app *Application) { + }). + Then(). + Expect(SyncStatusIs(SyncStatusCodeOutOfSync)). + // app should remain synced when app has skipped annotation even if git change detected + When(). + PatchFile("guestbook-ui-deployment.yaml", `[{ "op": "replace", "path": "/spec/replicas", "value": 1 }]`). + Sync(). + Then(). + Expect(ResourceResultIs(ResourceResult{Group: "apps", Version: "v1", Kind: "Deployment", Namespace: "guestbook", Name: "guestbook-ui", Message: "deployment.apps/guestbook-ui created", SyncPhase: SyncPhaseSync, HookPhase: OperationRunning})) +} + func TestSyncWithSkipHook(t *testing.T) { fixture.SkipOnEnv(t, "OPENSHIFT") Given(t). From a7395629742008004eddc56cebd3f60f41c877b9 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Fri, 11 Aug 2023 21:46:09 +0300 Subject: [PATCH 6/8] redundant comment Signed-off-by: pashakostohrys --- test/e2e/sync_options_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/test/e2e/sync_options_test.go b/test/e2e/sync_options_test.go index b26034e4a7327..bc5dc58a9820f 100644 --- a/test/e2e/sync_options_test.go +++ b/test/e2e/sync_options_test.go @@ -89,7 +89,6 @@ func TestSyncWithApplyOutOfSyncOnly(t *testing.T) { }). Then(). Expect(SyncStatusIs(SyncStatusCodeOutOfSync)). - // app should remain synced when app has skipped annotation even if git change detected When(). PatchFile("guestbook-ui-deployment.yaml", `[{ "op": "replace", "path": "/spec/replicas", "value": 1 }]`). Sync(). From 3ec21af704269b8a66be86fb0d9191236e2fbfaf Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Fri, 11 Aug 2023 21:59:41 +0300 Subject: [PATCH 7/8] improve test logic Signed-off-by: pashakostohrys --- test/e2e/sync_options_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/e2e/sync_options_test.go b/test/e2e/sync_options_test.go index bc5dc58a9820f..3eb7140787097 100644 --- a/test/e2e/sync_options_test.go +++ b/test/e2e/sync_options_test.go @@ -81,19 +81,26 @@ func TestSyncWithStatusIgnored(t *testing.T) { } func TestSyncWithApplyOutOfSyncOnly(t *testing.T) { + var ns string Given(t). Path(guestbookPath). ApplyOutOfSyncOnly(). When(). CreateFromFile(func(app *Application) { + ns = app.Spec.Destination.Namespace }). Then(). Expect(SyncStatusIs(SyncStatusCodeOutOfSync)). When(). + Sync(). + Then(). + When(). PatchFile("guestbook-ui-deployment.yaml", `[{ "op": "replace", "path": "/spec/replicas", "value": 1 }]`). Sync(). Then(). - Expect(ResourceResultIs(ResourceResult{Group: "apps", Version: "v1", Kind: "Deployment", Namespace: "guestbook", Name: "guestbook-ui", Message: "deployment.apps/guestbook-ui created", SyncPhase: SyncPhaseSync, HookPhase: OperationRunning})) + // Only one resource should be in sync result + Expect(ResourceResultNumbering(1)). + Expect(ResourceResultIs(ResourceResult{Group: "apps", Version: "v1", Kind: "Deployment", Namespace: ns, Name: "guestbook-ui", Message: "deployment.apps/guestbook-ui configured", SyncPhase: SyncPhaseSync, HookPhase: OperationRunning, Status: ResultCodeSynced})) } func TestSyncWithSkipHook(t *testing.T) { From d49b73273414cc1e44116778e78c66e98410c2e9 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Sat, 12 Aug 2023 00:55:42 +0300 Subject: [PATCH 8/8] change command description and do codegen Signed-off-by: pashakostohrys --- cmd/argocd/commands/app.go | 2 +- docs/user-guide/commands/argocd_app_sync.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/argocd/commands/app.go b/cmd/argocd/commands/app.go index 28034fcfb284e..9c24b255c547b 100644 --- a/cmd/argocd/commands/app.go +++ b/cmd/argocd/commands/app.go @@ -1817,7 +1817,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co command.Flags().BoolVar(&force, "force", false, "Use a force apply") command.Flags().BoolVar(&replace, "replace", false, "Use a kubectl create/replace instead apply") command.Flags().BoolVar(&serverSideApply, "server-side", false, "Use server-side apply while syncing the application") - command.Flags().BoolVar(&applyOutOfSyncOnly, "apply-out-of-sync-only", false, "Use out-of-sync apply that sync only out of sync resources") + command.Flags().BoolVar(&applyOutOfSyncOnly, "apply-out-of-sync-only", false, "Sync only out-of-sync resources") command.Flags().BoolVar(&async, "async", false, "Do not wait for application to sync before continuing") command.Flags().StringVar(&local, "local", "", "Path to a local directory. When this flag is present no git queries will be made") command.Flags().StringVar(&localRepoRoot, "local-repo-root", "/", "Path to the repository root. Used together with --local allows setting the repository root") diff --git a/docs/user-guide/commands/argocd_app_sync.md b/docs/user-guide/commands/argocd_app_sync.md index 798fcecdd8a03..716b7b81096d8 100644 --- a/docs/user-guide/commands/argocd_app_sync.md +++ b/docs/user-guide/commands/argocd_app_sync.md @@ -36,6 +36,7 @@ argocd app sync [APPNAME... | -l selector | --project project-name] [flags] ### Options ``` + --apply-out-of-sync-only Sync only out-of-sync resources --assumeYes Assume yes as answer for all user queries or prompts --async Do not wait for application to sync before continuing --dry-run Preview apply without affecting cluster