# ArgoCD

{% hint style="info" %}
Cortex connects to many third-party vendors whose system interfaces frequently change. As a result, integration behavior or configuration steps may shift without notice. If you encounter unexpected issues, check with your system administrator or refer to the vendor's documentation for the most current information. Additionally, integration sync times vary and are subject to scheduling overrides and timing variance.
{% endhint %}

[ArgoCD](https://argoproj.github.io/cd/) is a declarative, GitOps continuous delivery tool for Kubernetes.

Integrating Cortex with ArgoCD allows you to:

* Send information about ArgoCD syncs into Cortex
  * This data appears on [entity detail pages](#view-argocd-data-on-entity-pages).
* Use [Cortex Workflows to automate ArgoCD syncs](#automate-argocd-events-in-workflows)
* See [deploy data for ArgoCD in Eng Intelligence](#see-argocd-data-in-eng-intelligence)

## How to configure ArgoCD with Cortex

### Step 1: Use ArgoCD notification webhooks

To send Cortex information about syncs in ArgoCD, use ArgoCD notification [Webhooks](https://argo-cd.readthedocs.io/en/stable/operator-manual/notifications/services/webhook/) to call the Cortex [deploy REST endpoint](/api/readme/deploys.md).

#### Example config map

Here is an example of what a `argocd-notifications-cm` config map may look like:

```yaml
apiVersion: v1
kind: ConfigMap
data:
  context: |
    argocdUrl: https://argo.company.com
  service.webhook.cortex-webhook: |
    url: https://api.getcortexapp.com
    headers:
    - name: Content-Type
      value: application/json
    - name: Accept
      value: application/json
    - name: Authorization
      value: Bearer $token 
    subscriptions: |
      - recipients:
        - cortex-webhook
        triggers:
        - on-sync-succeeded
  template.app-sync-succeeded: |
    webhook:
      cortex-webhook:
        method: POST
        path: /api/v1/catalog/{{.app.metadata.name}}/deploys 
        body: |
          { "customData": { "Sync Status": "{{.app.status.sync.status}}","Sync Details": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true" },
            "environment": "{{.app.spec.destination.name}}",
            "sha": "{{.app.status.operationState.operation.sync.revision}}",
            "timestamp": "{{.app.status.operationState.finishedAt}}",
            "title": "Sync by ArgoCD",
            "type": "DEPLOY"
          }
  trigger.on-sync-succeeded: |
    - send:
      - app-sync-succeeded
      when: app.status.operationState.phase in ['Succeeded']
        
```

This example assumes your ArgoCD application's name matches the `x-cortex-tag`. In this case, each application in ArgoCD can subscribe to the same trigger.

If your application name doesn't match the `x-cortex-tag`, add a value/pair to the info section of the Application manifest. Then, instead of using `.app.metadata.name` in the url, use `.app.spec.info[0].value`.

### Step 2: Subscribe application to webhooks

Next, subscribe your application to the webhook. You do this by adding a label annotation in the Application spec in the following format:

```yaml
    notifications.argoproj.io/subscribe.<trigger-name>.<webhook-name>: ""
```

For example, if we want to subscribe an application to the example webhook above, the Application YAML may look like the following example:

```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  annotations:
    notifications.argoproj.io/subscribe.on-sync-succeeded.cortex-webhook: ""
...  

```

## Using the ArgoCD integration

### View ArgoCD data on entity pages

After you configure the integration, you will see data about ArgoCD syncs in an [entity's details page](/ingesting-data-into-cortex/entities-overview/entities/details.md):

* On the entity overview, ArgoCD syncs will appear under the **Latest events** section.\\

  <figure><img src="/files/gaKZMmMs7mfhiwqJCGI8" alt="ArgoCD syncs appear in the latest events on an entity."><figcaption></figcaption></figure>
* In the entity's sidebar, click **Events** to see a full list of events for the entity, including sync events from ArgoCD.
* In the entity's sidebar, click **CI/CD > Deploys** to see data from the [Cortex deploys API](/api/readme/deploys.md), including ArgoCD syncs.\\

  <div align="left"><figure><img src="/files/k6Eu2lT2RZFjrF9G8Xau" alt="ArgoCD data shows up on an entity page&#x27;s sidebar under CI/CD > Deploys." width="563"><figcaption></figcaption></figure></div>

### Automate ArgoCD events in Workflows

You can use a Workflow to automate ArgoCD syncs. [See this docs page for more information](https://github.com/cortexapps/hippocampus/blob/master/ingesting-data-into-cortex/integrations/broken-reference/README.md).

### See ArgoCD data in Eng Intelligence

Since the ArgoCD integration uses Cortex's [deploys API endpoint](/api/readme/deploys.md), ArgoCD data is included in Eng Intelligence deploy metrics. Learn more about [Eng Intelligence in the docs](/improve/eng-intelligence.md).

## Troubleshooting and FAQ

#### What permissions does my API Key need?

The API key needs to be able to call the[ "Add deployment for entity"](https://docs.cortex.io/api/rest/deploys#post-api-v1-catalog-tagorid-deploys) API endpoint, so ensure the `Edit entities` permission is enabled.

#### Ensure the Cortex API Key is encoded correctly

Make sure the encoded Cortex API Key does not contain an extra line. Use a tool like <https://www.base64encode.org/> to ensure your encoded key does not contain an extra line.

#### Check the ArgoCD logs

The notification webhook is managed by the `argocd-notifications-controller` which will have a pod running in your ArgoCD namespace.

Assuming the ArgoCD is running in the `argocd` namepsace, run the following command to get the list of pods:

`kubectl get pods -n argocd`

This will return a list of pods similar to the ones listed below:

```
NAME                                                READY   STATUS    RESTARTS   AGE
argocd-application-controller-0                     1/1     Running   0          108d
argocd-applicationset-controller-69f96ccf5b-5jnpv   1/1     Running   0          108d
argocd-dex-server-5dff9c5998-j29zd                  1/1     Running   0          80d
argocd-notifications-controller-6cd988b564-sql55    1/1     Running   0          107d
argocd-redis-54c687db9d-kdxwj                       1/1     Running   0          80d
argocd-repo-server-6c6f8859c7-mrwll                 1/1     Running   0          108d
argocd-server-b77b48886-s2mtg                       1/1     Running   0          80d
```

In this example, the pod managing the webhook notifications is `argocd-notifications-controller-6cd988b564-sql55`. To get the logs, run the following command:

`kubectl logs argocd-notifications-controller-6cd988b564-sql55 -n argocd`

If your trigger was successful, you should seem something similar to this:

```
time="2023-07-19T02:41:13Z" level=info msg="Start processing" app=argocd/app-direct
time="2023-07-19T02:41:13Z" level=info msg="Trigger on-sync-succeeded result: []" app=argocd/app-direct
time="2023-07-19T02:41:13Z" level=info msg="Notification about condition 'on-sync-succeeded.[0].zxM90Et6k4Elb1-fHdjtDJq0xR0' already sent to ''" app=argocd/app-direct
time="2023-07-19T02:41:13Z" level=info msg="Processing completed" app=argocd/app-direct
```

## Still need help?[​](https://docs.cortex.io/docs/reference/integrations/aws#still-need-help) <a href="#still-need-help" id="still-need-help"></a>

The following options are available to get assistance from the Cortex Customer Engineering team:

* **Email**: <help@cortex.io>, or open a support ticket in the in app Resource Center
* **Slack**: Users with a connected Slack channel will have a workflow added to their account. From here, you can either @CortexTechnicalSupport or add a `:ticket:` reaction to a question in Slack, and the team will respond directly.

Don’t have a Slack channel? Talk with your Customer Success Manager.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cortex.io/ingesting-data-into-cortex/integrations/argocd.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
