Using Actions to sync in ArgoCD
Once you've integrated Cortex with ArgoCD, you can use Actions to help you streamline and automate daily tasks. Rather than manually performing a sync through the ArgoCD UI, you can automate syncs by leveraging the ArgoCD API in Actions.
Automating syncs with Actions
The first step is creating an API token through ArgoCD. Navigate to your Account settings in ArgoCD and select Generate New under Tokens to generate and copy the token.
Once you have the token, go the Secret page in Authentication and access settings in Cortex. Select Create Secret and fill out the fields in the modal.
Once the secret is created, go to Actions in the main nav and click Create Action.
Under Action inputs, you'll define inputs that map to the JSON
body of your action. These inputs should be the same sync options shown under Sync in the ArgoCD UI.
For example, to map REVISION
, DRY RUN
, and PRUNE
from the JSON to your Action, you would create three inputs:
- For Revision, you'd select Input as the Input type. The Default value and Placeholder are both HEAD to correspond with what's in ArgoCD.
- For Dry Run, the Input type is Toggle because this is a boolean operation.
- For Prune, the Input type is also Toggle.
Under the Action definition section, you'll establish the parameters for making the API call. From ArgoCD's API documentation, we can find the HTTP method and payload URL.
The inputs referenced in the Payload are mapped to fields in the JSON payload. We'll enter the context inputs and the key for each input here.
You can use the Response Template with Mustache templating allows you to create optional messages depending on what the user entered in each field.
For example, you may want to configure a response to confirm whether a sync was successful when the Action is run. In the above example, Cortex is checking the sync.status
field — when a status is present, the sync is successful.
The last step is to map the Action to entities in the Filters section.
Once the Action is saved, users will be able to run it from the Actions page or directly from an entity's page, if it applies under the filters.