Skip to content

Commit

Permalink
feat: selective sync (argoproj#3877) (argoproj#5347)
Browse files Browse the repository at this point in the history
* selective sync

Signed-off-by: kshamajain99 <[email protected]>
  • Loading branch information
kshamajain99 authored Jan 29, 2021
1 parent 2167082 commit baa0f2e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
4 changes: 3 additions & 1 deletion controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ type comparisonResult struct {
diffNormalizer diff.Normalizer
appSourceType v1alpha1.ApplicationSourceType
// timings maps phases of comparison to the duration it took to complete (for statistical purposes)
timings map[string]time.Duration
timings map[string]time.Duration
diffResultList *diff.DiffResultList
}

func (res *comparisonResult) GetSyncStatus() *v1alpha1.SyncStatus {
Expand Down Expand Up @@ -632,6 +633,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *ap
managedResources: managedResources,
reconciliationResult: reconciliation,
diffNormalizer: diffNormalizer,
diffResultList: diffResults,
}
if manifestInfo != nil {
compRes.appSourceType = v1alpha1.ApplicationSourceType(manifestInfo.SourceType)
Expand Down
2 changes: 2 additions & 0 deletions controller/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (m *appStateManager) SyncAppState(app *v1alpha1.Application, state *v1alpha
Order: i + 1,
})
}

syncCtx, err := sync.NewSyncContext(
compareResult.syncStatus.Revision,
compareResult.reconciliationResult,
Expand Down Expand Up @@ -168,6 +169,7 @@ func (m *appStateManager) SyncAppState(app *v1alpha1.Application, state *v1alpha
}),
sync.WithSyncWaveHook(delayBetweenSyncWaves),
sync.WithPruneLast(syncOp.SyncOptions.HasOption("PruneLast=true")),
sync.WithResourceModificationChecker(syncOp.SyncOptions.HasOption("ApplyOutOfSyncOnly=true"), compareResult.diffResultList),
)

if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion docs/user-guide/selective_sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ A *selective sync* is one where only some resources are sync'd. You can choose w
When doing so, bear in mind:

* Your sync is not recorded in the history, and so rollback is not possible.
* Hooks are not run.
* Hooks are not run.

## Selective Sync Option

>v1.8
Turning on selective sync option which will sync only out-of-sync resources.
See [sync options](sync-options.md#selective-sync) documentation for more details.
28 changes: 28 additions & 0 deletions docs/user-guide/sync-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,31 @@ metadata:
```

The dry run will still be executed if the CRD is already present in the cluster.

## Selective Sync

>v1.8

Currently when syncing using auto sync ArgoCD applies every object in the application.
For applications containing thousands of objects this takes quite a long time and puts undue pressure on the api server.
Turning on selective sync option which will sync only out-of-sync resources.

You can add this option by following ways

1) Add `ApplyOutOfSync=true` in manifest

Example:

```yaml
syncPolicy:
syncOptions:
- ApplyOutOfSyncOnly=true
```

2) Set sync option via argocd cli

Example:

```bash
$ argocd app set guestbook --sync-option ApplyOutOfSyncOnly=true
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/TomOnTime/utfutil v0.0.0-20180511104225-09c41003ee1d
github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6 // indirect
github.com/alicebob/miniredis v2.5.0+incompatible
github.com/argoproj/gitops-engine v0.2.1-0.20210112204306-814d79df4954
github.com/argoproj/gitops-engine v0.2.1-0.20210129183711-c5b7114c501f
github.com/argoproj/pkg v0.2.0
github.com/bombsimon/logrusr v1.0.0
github.com/casbin/casbin v1.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/argoproj/gitops-engine v0.2.1-0.20210112204306-814d79df4954 h1:IJSkAuhE4DrLDJmGPa0eGCK20gjCQokkjk2Il7Pd/Sw=
github.com/argoproj/gitops-engine v0.2.1-0.20210112204306-814d79df4954/go.mod h1:dmGvluybnmaSzsJA7PnrgCoSYQ5stFUNqS46F3gma+M=
github.com/argoproj/gitops-engine v0.2.1-0.20210129183711-c5b7114c501f h1:QAf9m8jTw9TqRRNSBtygvZrrxWWUtF1F0qtVPrFogF8=
github.com/argoproj/gitops-engine v0.2.1-0.20210129183711-c5b7114c501f/go.mod h1:dmGvluybnmaSzsJA7PnrgCoSYQ5stFUNqS46F3gma+M=
github.com/argoproj/pkg v0.2.0 h1:ETgC600kr8WcAi3MEVY5sA1H7H/u1/IysYOobwsZ8No=
github.com/argoproj/pkg v0.2.0/go.mod h1:F4TZgInLUEjzsWFB/BTJBsewoEy0ucnKSq6vmQiD/yc=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
Expand Down

0 comments on commit baa0f2e

Please sign in to comment.