diff --git a/cmd/argocd/commands/app.go b/cmd/argocd/commands/app.go index ea0dbbfab86dd..e7d07fcbedc7e 100644 --- a/cmd/argocd/commands/app.go +++ b/cmd/argocd/commands/app.go @@ -1295,6 +1295,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co strategy string force bool replace bool + serverSide bool async bool retryLimit int64 retryBackoffDuration time.Duration @@ -1411,6 +1412,9 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co if replace { items = append(items, common.SyncOptionReplace) } + if serverSide { + items = append(items, common.SyncOptionServerSide) + } if len(items) == 0 { // for prevent send even empty array if not need @@ -1488,6 +1492,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co command.Flags().StringVar(&strategy, "strategy", "", "Sync strategy (one of: apply|hook)") 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(&serverSide, "server-side", false, "Use a kubectl server-side instead of client-side") 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/sync-options.md b/docs/user-guide/sync-options.md index 11cc42336000e..09010f3f70a05 100644 --- a/docs/user-guide/sync-options.md +++ b/docs/user-guide/sync-options.md @@ -134,6 +134,30 @@ metadata: argocd.argoproj.io/sync-options: Replace=true ``` +## Server-side apply + +By default, ArgoCD executes `kubectl apply` operation to apply the configuration stored in Git. In some cases +`kubectl apply --server-side` is needed instead. For example, resource spec might be too big and won't fit into +`kubectl.kubernetes.io/last-applied-configuration` annotation that is added by `kubectl apply`. In such cases you +might use `ServerSideApply=true` sync option: + +```yaml +syncOptions: +- ServerSideApply=true +``` + +If the `ServerSideApply=true` sync option is set the ArgoCD will use `kubectl apply --server-side` command to apply changes. + +This can also be configured at individual resource level. +```yaml +metadata: + annotations: + argocd.argoproj.io/sync-options: ServerSideApply=true +``` + +Note: [`Replace=true`](#replace-resource-instead-of-applying-changes) takes +precedence over `ServerSideApply=true`. + ## Fail the sync if a shared resource is found By default, ArgoCD will apply all manifests found in the git path configured in the Application regardless if the resources diff --git a/go.mod b/go.mod index 8ae9681251303..eb8713822ee2c 100644 --- a/go.mod +++ b/go.mod @@ -94,6 +94,8 @@ require ( ) replace ( + github.com/argoproj/gitops-engine => github.com/sathieu/gitops-engine v0.4.1-0.20220108164648-711967650f3c + // https://github.com/golang/go/issues/33546#issuecomment-519656923 github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127 diff --git a/go.sum b/go.sum index 5563bf6324d50..feea22a6e1bfa 100644 --- a/go.sum +++ b/go.sum @@ -117,8 +117,6 @@ github.com/antonmedv/expr v1.8.9/go.mod h1:5qsM3oLGDND7sDmQGDXHkYfkjYMUX14qsgqmH github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/appscode/go v0.0.0-20190808133642-1d4ef1f1c1e0/go.mod h1:iy07dV61Z7QQdCKJCIvUoDL21u6AIceRhZzyleh2ymc= -github.com/argoproj/gitops-engine v0.5.1-0.20211222191605-f6495020a330 h1:jCWvj9G6m+ayVIYX6pkaMaymCwEWHZIjKWgCyJz07SY= -github.com/argoproj/gitops-engine v0.5.1-0.20211222191605-f6495020a330/go.mod h1:K2RYpGXh11VdFwDksS23SyFTOJaPcsF+MVJ/FHlqEOE= github.com/argoproj/notifications-engine v0.3.0 h1:1KMVYwXlg7SGzX00eg/bU0YupXDVdfpm8FlpNbrkUxM= github.com/argoproj/notifications-engine v0.3.0/go.mod h1:0TEB4QbOsNN8URcsUJpAFuuG6aw8KS8ZY/YCzsss9JQ= github.com/argoproj/pkg v0.11.1-0.20211203175135-36c59d8fafe0 h1:Cfp7rO/HpVxnwlRqJe0jHiBbZ77ZgXhB6HWlYD02Xdc= @@ -867,6 +865,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/sanity-io/litter v1.2.0/go.mod h1:JF6pZUFgu2Q0sBZ+HSV35P8TVPI1TTzEwyu9FXAw2W4= +github.com/sathieu/gitops-engine v0.4.1-0.20220108164648-711967650f3c h1:IGdvVR3cJeIBr2FLdc3ZkYWu3FfGEI/yICreBiPpkN8= +github.com/sathieu/gitops-engine v0.4.1-0.20220108164648-711967650f3c/go.mod h1:K2RYpGXh11VdFwDksS23SyFTOJaPcsF+MVJ/FHlqEOE= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=