github.com/argoproj/argo-cd/v3@v3.2.1/docs/user-guide/auto_sync.md (about)

     1  # Automated Sync Policy
     2  
     3  Argo CD has the ability to automatically sync an application when it detects differences between
     4  the desired manifests in Git, and the live state in the cluster. A benefit of automatic sync is that
     5  CI/CD pipelines no longer need direct access to the Argo CD API server to perform the deployment.
     6  Instead, the pipeline makes a commit and push to the Git repository with the changes to the
     7  manifests in the tracking Git repo.
     8  
     9  To configure automated sync run:
    10  ```bash
    11  argocd app set <APPNAME> --sync-policy automated
    12  ```
    13  
    14  Alternatively, if creating the application an application manifest, specify a syncPolicy with an
    15  `automated` policy.
    16  ```yaml
    17  spec:
    18    syncPolicy:
    19      automated: {}
    20  ```
    21  Application CRD now also support explicitly setting automated sync to be turned on or off by using `spec.syncPolicy.automated.enabled` flag to true or false. When `enable` field is set to true, Automated Sync is active and when set to false controller will skip automated sync even if `prune`, `self-heal` and `allowEmpty` are set.
    22  ```yaml
    23  spec:
    24    syncPolicy:
    25      automated:
    26        enabled: true
    27  ```
    28  
    29  !!!note 
    30      Setting the `spec.syncPolicy.automated.enabled` flag to null will be treated as if automated sync is enabled. When the `enabled` field is set to false, fields like `prune`, `selfHeal` and `allowEmpty` can be set without enabling them.
    31  
    32  ## Temporarily toggling auto-sync for applications managed by ApplicationSets
    33  
    34  For a standalone application, toggling auto-sync is performed by changing the application's `spec.syncPolicy.automated` field. For an ApplicationSet managed application, changing the application's `spec.syncPolicy.automated` field will, however, have no effect.
    35  Read more details about how to perform the toggling for applications managed by ApplicationSets [here](../operator-manual/applicationset/Controlling-Resource-Modification.md).
    36  
    37  
    38  ## Automatic Pruning
    39  
    40  By default (and as a safety mechanism), automated sync will not delete resources when Argo CD detects
    41  the resource is no longer defined in Git. To prune the resources, a manual sync can always be
    42  performed (with pruning checked). Pruning can also be enabled to happen automatically as part of the
    43  automated sync by running:
    44  
    45  ```bash
    46  argocd app set <APPNAME> --auto-prune
    47  ```
    48  
    49  Or by setting the prune option to true in the automated sync policy:
    50  
    51  ```yaml
    52  spec:
    53    syncPolicy:
    54      automated:
    55        prune: true
    56  ```
    57  
    58  ## Automatic Pruning with Allow-Empty (v1.8)
    59  
    60  By default (and as a safety mechanism), automated sync with prune have a protection from any automation/human errors 
    61  when there are no target resources. It prevents application from having empty resources. To allow applications have empty resources, run:
    62  
    63  ```bash
    64  argocd app set <APPNAME> --allow-empty
    65  ```
    66  
    67  Or by setting the allow empty option to true in the automated sync policy:
    68  
    69  ```yaml
    70  spec:
    71    syncPolicy:
    72      automated:
    73        prune: true
    74        allowEmpty: true
    75  ```
    76  
    77  ## Automatic Self-Healing
    78  By default, changes that are made to the live cluster will not trigger automated sync. To enable automatic sync 
    79  when the live cluster's state deviates from the state defined in Git, run:
    80  
    81  ```bash
    82  argocd app set <APPNAME> --self-heal
    83  ```
    84  
    85  Or by setting the self-heal option to true in the automated sync policy:
    86  
    87  ```yaml
    88  spec:
    89    syncPolicy:
    90      automated:
    91        selfHeal: true
    92  ```
    93  
    94  !!!note 
    95      Disabling self-heal does not guarantee that live cluster changes in multi-source applications will persist. Although one of the resource's sources remains unchanged, changes in another can trigger `autosync`. To handle such cases, consider disabling `autosync`.
    96  
    97  ## Automatic Retry Refresh on new revisions
    98  
    99  This feature allows users to configure their applications to refresh on new revisions when the current sync is retrying. To enable automatic refresh during sync retries, run:
   100  
   101  ```bash
   102  argocd app set <APPNAME> --sync-retry-refresh
   103  ```
   104  
   105  Or by setting the `retry.refresh` option to `true` in the sync policy:
   106  
   107  ```yaml
   108  spec:
   109    syncPolicy:
   110      retry:
   111        refresh: true
   112  ```
   113  
   114  ## Automated Sync Semantics
   115  
   116  * An automated sync will only be performed if the application is OutOfSync. Applications in a
   117    Synced or error state will not attempt automated sync.
   118  * Automated sync will only attempt one synchronization per unique combination of commit SHA1 and
   119    application parameters. If the most recent successful sync in the history was already performed
   120    against the same commit-SHA and parameters, a second sync will not be attempted, unless `selfHeal` flag is set to true.
   121  * If the `selfHeal` flag is set to true, then the sync will be attempted again after self-heal timeout (5 seconds by default)
   122  which is controlled by `--self-heal-timeout-seconds` flag of `argocd-application-controller` deployment.
   123  * Automatic sync will not reattempt a sync if the previous sync attempt against the same commit-SHA
   124    and parameters had failed.
   125  
   126  * Rollback cannot be performed against an application with automated sync enabled.
   127  * The automatic sync interval is determined by [the `timeout.reconciliation` value in the `argocd-cm` ConfigMap](../faq.md#how-often-does-argo-cd-check-for-changes-to-my-git-or-helm-repository), which defaults to `120s` with added jitter of `60s` for a maximum period of 3 minutes.