5

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.

Nitin Singh
  • 231
  • 3
  • 9

3 Answers3

5

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.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
5

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.

Nitin Singh
  • 231
  • 3
  • 9
  • 1
  • 1
    @gauravagnihotri, try curl command as mentioned in following: https://docs.github.com/en/rest/actions/workflows#list-repository-workflows – Nitin Singh Sep 23 '22 at 01:44
  • I am using GitHub and able to create a webhook, but that webhook is not triggering the buildkit pipeline after argcd syncup . – gaurav agnihotri Sep 24 '22 at 18:58
  • @gauravagnihotri, correct me if I have got the wrong understanding here. You have ArgoCD post sync job, as mentioned in my solution, which runs another GitHub action workflow that contains buildkit pipeline. If this is the case than first check your PAT if that has the right access or not. Second, check if you are using right workflow Id or not. Lastly, check the body content as mentioned -d parameter, if your branch doesn’t contain the right action workflow than post sync trigger won’t work. I hope I can be any help here. – Nitin Singh Sep 26 '22 at 02:44
  • I am assuming you have a GitHub webhook already in place? if yes can you share with me what scope you selected there? What this means for -d '{\"ref\":\"main\"} – gaurav agnihotri Sep 26 '22 at 09:06
  • Does the answer only work with git actions? I am using just GitHub – gaurav agnihotri Sep 26 '22 at 09:23
  • This answer is specific for GitHub action pipeline or workflow only. However, if your build kit exposes any api, solution should work with that too. You mentioned that you have GitHub only setup, I am not sure what’s the intent of GitHub as a Argo post sync but what you can try is that calling the GitHub api, not the GitHub action api. I think even if you have webhook setup in your argocd you still need the GitHub Personal Access Token to access GitHub api. https://docs.github.com/en/rest/guides/getting-started-with-the-rest-api – Nitin Singh Sep 27 '22 at 02:47
  • To be honest, I'm not sure how this is going to help in the long run. Arn't these notifications completely generic? It's going to trigger this workflow when ANY application is synced? – wesleywh Sep 01 '23 at 19:05
1

If you are using ArgoCD to deploy I would recommend you to take advantage of Argo environment which provides tools like Argo Rollouts (https://argo-rollouts.readthedocs.io/en/stable/)

Argo Rollouts is a Kubernetes controller and set of CRDs which provide advanced deployment capabilities such as blue-green, canary, canary analysis, experimentation, and progressive delivery features to Kubernetes.

With this great tool you can check the status of you new version app (using Analysis Template CRD https://argo-rollouts.readthedocs.io/en/stable/features/analysis/) before deploy the new version of your application which is very important to ensure reliability. You can use in your Analysis Template the job which provides @NitinSingh.

This is how it would look in ArgoCD UI: img

  • Rollout deploys both version the new app and the old one.
  • Analysis Template create an Analysis Run and then the Job which executes any check that you specify to ensure that your new app is correctly deploy.
  • If the check of the Analysis Run has finished correctly the new app version be deployed automatically and the old one will be removed.

You can do a lot of things with Argo Rollouts check the documentation, I hope this example help you :)

HK boy
  • 1,398
  • 11
  • 17
  • 25