tm1701
tm1701

Reputation: 7601

ArgoCd does not trigger on GitOps repo update?

After pushing a new Docker image to Docker hub and committing on a GitOps repo, I expected ArgoCD to refresh either after 3 minutes or a manual trigger. It does not. Only after deleting a deployment in the ArgoCD user interface, ArgoCD fetches a new Docker image. I can easily track when the Docker image is (not) pulled from Docker hub.

Of course, this is only valuable during development. For production you need a solid tag for each Docker image version.

After updating the GitOps repo and manually refresh ArgoCD, I can see that the Sync status correctly mentioning the HEAD, but the lastSync is from a prior commit.

enter image description here

Performing a manual Sync gives also an updated last sync status, BUT the image is not pulled from the Docker hub. enter image description here

As far as I know, the deployment config "imagePullPolicy: Always" should to the update.

How can I trigger ArgoCD to refresh / resync on any update of the GitOps repo?

This is my Application:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: argocd-systeemtester-app
  namespace: argocd
spec:
  destination:
    namespace: default
    server: "https://kubernetes.default.svc"
  project: default
  source:
    path: systemtester
    repoURL: "https://github.com/abcdef/argocd-demo.git"
    targetRevision: HEAD
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

The repo consists of a helm chart. I can see that the specific repo and deployment file is commited / pushed.

An example of a Deployment file is:

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: {{.Values.systemtester.name}}
  name: {{.Values.systemtester.name}}
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: {{.Values.systemtester.name}}
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.network/devhome-default: "true"
        io.kompose.service: {{.Values.systemtester.name}}
    spec:
      containers:
        - env:
            - name: a
              value: "b"
          image: {{.Values.systemtester.image.name -}}:{{- .Values.systemtester.image.version}}
          imagePullPolicy: Always
          name: {{.Values.systemtester.name}}
          ports:
            - containerPort: {{.Values.systemtester.service.internalPort}}
          resources: {}
      restartPolicy: Always

Refreshing manually does not help. Syncing manually does not help. Only after removing a Deployment in the ArgoCD app I see that the image is pulled from Docker hub.

Upvotes: 3

Views: 621

Answers (2)

tm1701
tm1701

Reputation: 7601

Another nice and good working solution is:

  • After any docker push retrieve the sha256 digest;
  • Change in your GitOps repo the image name so it uses a sha256 digest;
  • Commit and push the GitOps deploy repo.

I made a simple bat file that maven builds, docker builds/pushes and updates the GitOps image with the sha256. Just push the 'Refresh' button in the ArgoCD dashboard, and the image is deployed. Works very well.

When working in a Windows environment you could use the following tools:

  • First push the docker image to docker hub
  • Get the sha digest via:

call docker inspect --format="{{index .RepoDigests 0}}" docker.io/abc/xyz:v1 > dockerimagesha.txt

  • Edit the GitOps main Helm Chart file via e.g.

call c:\cygwin64\bin\sed.exe -i "s#fulldigest3: [a-z].*#fulldigest3: %dockerimage%#" values.yaml

So, just refresh ArgoCD and everything runs updated!

Upvotes: 0

GBlodgett
GBlodgett

Reputation: 12819

It sounds like your use case is that you have a snapshot image that you are pushing updates to during development to the same image tag. You would like this image to be automatically pulled whenever a new SHA is available. Because there is no change to the manifests, ArgoCD will not automatically do this for you.

You can explore their auto image updater, which seems to be what you are after:

The Argo CD Image Updater can check for new versions of the container images that are deployed with your Kubernetes workloads and automatically update them to their latest allowed version using Argo CD.

Ref: https://argocd-image-updater.readthedocs.io/en/stable/

If you would not like to go down that route you can either use a kubectl rollout on the deployment (Or do a rollout from the ArgoCD UI) which will restart every pod. With the image pull policy set to Always this will always pull the latest image with that tag.

If you want to just roll the pods with every deploy, you could add something like rollme: {{ randAlphaNum 5 | quote }} to the annotations, which will replace the deployment every time helm apply is run.

Ref: https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments

Upvotes: 2

Related Questions