How to run application E2E test after argocd deployment?

Viewed 1849

I would like to know how can we run application E2E(UI or API) test after successful deployment of any micro services using ArgoCD.

Current Setup: I have CI pipeline setup with github-actions. Upon completion on CI build for any microservices, it updates the docker image version in helm values which resides in one of the github repo. This repo is than polled by ArgoCD for any change, and deploys in Kubernestes cluster if there is change exists.

Intent: I want to run the application E2E( UI & API ) test once argocd synced any micro-services deployment object defined in the Helm charts. But I am unsure what should be the trigger point in github actions for that. How E2E test github actions workflow will know argocd has deployed the microservices without any issue and service is ready to be consumed by the automated test.

2 Answers

ArgoCD provides a feature called resource hooks. Hooks are ways to run scripts before, during, and after a sync operation. A use case for hooks from the official documentation:

Using a PostSync hook to run integration and health checks after a deployment.

Hooks can be any type of Kubernetes resource kind, but tend to be Pod, Job, or Argo Workflows.

Per the GitHub actions documentation, you can send a POST request to the Github API in PostSync hooks template to run the workflow run.

Here is the full solution to the problem statement.

apiVersion: batch/v1
kind: Job
metadata:
  name: api-test-trigger
  annotations:
    argocd.argoproj.io/hook: PostSync
    argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
  template:
    metadata:
      labels:
        name: api-test
    spec:
      containers:
      - name: api-test
        args:
            - /bin/sh
            - -ec
            - "curl -X POST -H \"Accept: application/vnd.github.v3+json\" -H \"Authorization: token ${GITHUB_TOKEN}\" ${GITHUB_URL} -d '{\"ref\":\"main\"}'"
        env:
          - name: GITHUB_URL
            value: "https://api.github.com/repos/<your org>/<your repo>/actions/workflows/<workflow id>/dispatches"
          - name: GITHUB_TOKEN
            value: <your PAT>
        image: curlimages/curl

You can create the PAT from github settings and provide the PAT as a secret.

Related