Using a Workflow to sync in ArgoCD
Last updated
Last updated
After integrating Cortex with ArgoCD, you can use Workflows to 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 a Workflow.
This guide walks through a Workflow that will sync the ArgoCD application to the same cluster that ArgoCD is running, but to a different namespace, and will allow the user to choose options for the sync.
Before getting started:
Create an API token in ArgoCD.
In ArgoCD, navigate to your account settings then click Tokens > Generate New. Copy the token and store it in a secure location, as you will need it in the next steps.
Create a secret in Cortex.
Give the secret the name argocd
.
For the secret value, enter the value of your ArgoCD API token.
In the main nav of Cortex, click Workflows.
Follow the steps of the Workflows documentation to start creating a Workflow from scratch and configure its settings.
Give the Workflow a descriptive name such as "Create and sync application."
In the Response template field you can pass a blank response body or use Mustache templating to create messages depending on what the user enters in each field.
For example, you may want to configure a response to confirm whether a sync was successful when the workflow is run. You could add the following to check the sync.status
field. This example assumes you add an HTTP request action with the slug http-request
in your Workflow:
In your Workflow, you will add an HTTP request block to call the ArgoCD sync via the ArgoCD API, and a user input block where you define inputs that map to the JSON body of the block. The inputs should be the same sync options shown under Sync in your ArgoCD instance. The instructions below map REVISION
, DRY RUN
, and PRUNE
as the sync options.
See the Workflows documentation for more information on configuring blocks.
In the Workflow, click + to add a block. Select User input. Configure the block:
Block name: Enter a name for the block (e.g., User input
).
Slug: The slug field is automatically populated based on the block name.
Under "User input fields," click Add input. Configure the input:
Type: Select Text
.
Name: Enter Revision
.
Placeholder: Enter HEAD
.
At the bottom of the modal, click Add input field.
Under "User input fields," click Add input. Configure another input:
Type: Select Toggle
.
Name: Enter Dry run
.
At the bottom of the modal, click Add input field.
Under "User input fields," click Add input. Configure another input:
Type: Select Toggle
.
Name: Enter Prune
.
At the bottom of the modal, click Add input field.
Click Save.
In the Workflow, click + to add another block. Select HTTP request. Configure the block:
Block name: Enter a name for the block (e.g., HTTP request
).
Slug: The slug field is automatically populated based on the block name.
HTTP method: Select POST
.
URL: Enter the target URL.
Headers: Enter the following key/value pairs:
Header Key: Authorization
, Header Value: Bearer {{{context.secrets.argocd}}}
If you used a different name for your secret, replace argocd
with your secret's name.
Payload: Enter the payload referencing the output of the "User input" block. The payload that you supply can be templated and can reference an entity that the Workflow is being run with.
In this example, you could enter:
Click Save.
Click Save Workflow.