argoproj-labs / argocd-image-updater

Automatic container image update for Argo CD
https://argocd-image-updater.readthedocs.io/en/stable/
Apache License 2.0
1.27k stars 261 forks source link

Image updater unable to update image tags of application with multiple images #623

Open naiame-neltheri opened 1 year ago

naiame-neltheri commented 1 year ago

Describe the bug Image updater is unable to image tags of application with multiple image defined To Reproduce Steps to reproduce the behavior: Add application with multiple images defined like in following yaml:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: ***
  namespace: argocd
  annotations:
    argocd-image-updater.argoproj.io/image-list: web=***-web,api=***-api,alert=***-alert,core=***-core,fin=***-fin,backend=***-backend,app=***-app,admin=***-admin
    argocd-image-updater.argoproj.io/pull-secret: pullsecret:argocd/***
    argocd-image-updater.argoproj.io/update-strategy: latest
    argocd-image-updater.argoproj.io/allow-tags: regexp:^[a-fA-F0-9]+-(?P<ts>.*)
    argocd-image-updater.argoproj.io/write-back-method: git:secret:argocd/git-deploy-token
    argocd-image-updater.argoproj.io/write-back-target: kustomization:.
    argocd-image-updater.argoproj.io/git-branch: main
    argocd-image-updater.argoproj.io/force-update: "true"
spec:
  syncPolicy:
    automated:
      prune: true
  destination:
    namespace: ***
    server: "https://kubernetes.default.svc"
  source:
    path: overlays/test
    repoURL: "***"
    targetRevision: main
  project: apps

Expected behavior Image updater should update image tags in kustomization with new tag

Additional context

Version 0.12.2 Logs

time="2023-09-20T02:16:25Z" level=info msg="Initializing https://***/***/***/***/gitops.git to /tmp/git-***191464592"
time="2023-09-20T02:16:25Z" level=info msg="rm -rf /tmp/git-***191464592" dir= execID=4d15e
time="2023-09-20T02:16:25Z" level=info msg=Trace args="[rm -rf /tmp/git-***191464592]" dir= operation_name="exec rm" time_ms=1.349425
time="2023-09-20T02:16:25Z" level=info msg="git fetch origin --tags --force" dir=/tmp/git-***191464592 execID=70bbd
time="2023-09-20T02:16:25Z" level=info msg=Trace args="[git fetch origin --tags --force]" dir=/tmp/git-***191464592 operation_name="exec git" time_ms=408.14843499999995
time="2023-09-20T02:16:25Z" level=info msg="git config user.name argocd-image-updater" dir=/tmp/git-***191464592 execID=95b9b
time="2023-09-20T02:16:25Z" level=info msg=Trace args="[git config user.name argocd-image-updater]" dir=/tmp/git-***191464592 operation_name="exec git" time_ms=1.606798
time="2023-09-20T02:16:25Z" level=info msg="git config user.email noreply@argoproj.io" dir=/tmp/git-***191464592 execID=fb813
time="2023-09-20T02:16:25Z" level=info msg=Trace args="[git config user.email noreply@argoproj.io]" dir=/tmp/git-***191464592 operation_name="exec git" time_ms=3.714858
time="2023-09-20T02:16:25Z" level=info msg="git checkout --force main" dir=/tmp/git-***191464592 execID=52879
time="2023-09-20T02:16:25Z" level=info msg=Trace args="[git checkout --force main]" dir=/tmp/git-***191464592 operation_name="exec git" time_ms=13.567592
time="2023-09-20T02:16:25Z" level=info msg="git clean -fdx" dir=/tmp/git-***191464592 execID=ffc69
time="2023-09-20T02:16:25Z" level=info msg=Trace args="[git clean -fdx]" dir=/tmp/git-***191464592 operation_name="exec git" time_ms=3.663246
time="2023-09-20T02:16:25Z" level=info msg="updating base /tmp/git-***191464592/overlays/test" application=***
time="2023-09-20T02:16:25Z" level=info msg="git commit -a -F /tmp/image-updater-commit-msg3768429297" dir=/tmp/git-***191464592 execID=2fa5b
time="2023-09-20T02:16:25Z" level=error msg="`git commit -a -F /tmp/image-updater-commit-msg3768429297` failed exit status 1" execID=2fa5b
time="2023-09-20T02:16:25Z" level=info msg=Trace args="[git commit -a -F /tmp/image-updater-commit-msg3768429297]" dir=/tmp/git-***191464592 operation_name="exec git" time_ms=9.748606
time="2023-09-20T02:16:25Z" level=error msg="On branch main\nYour branch is up to date with 'origin/main'.\n\nnothing to commit, working tree clean"
time="2023-09-20T02:16:25Z" level=error msg="Could not update application spec: `git commit -a -F /tmp/image-updater-commit-msg3768429297` failed exit status 1" application=***
time="2023-09-20T02:16:25Z" level=info msg="Processing results: applications=19 images_considered=29 images_skipped=0 images_updated=0 errors=10"
frittenlab commented 1 year ago

I have not tried to upgrade multiple images using kustomize but this should work too. I am currently using the image updater to update multiple images with helm. Which works nicely. Here is a working example for the cert-manager helm chart:

annotations:
    argocd-image-updater.argoproj.io/image-list: cert-manager=quay.io/jetstack/cert-manager-controller:v1.13.x, webhook=quay.io/jetstack/cert-manager-webhook:v1.13.x, cainjector=quay.io/jetstack/cert-manager-cainjector:v1.13.x
    argocd-image-updater.argoproj.io/write-back-method: git
    argocd-image-updater.argoproj.io/cert-manager.helm.image-name: cert-manager.image.repository
    argocd-image-updater.argoproj.io/cert-manager.helm.image-tag: cert-manager.image.tag
    argocd-image-updater.argoproj.io/webhook.helm.image-name: webhook.image.repository
    argocd-image-updater.argoproj.io/webhook.helm.image-tag: webhook.image.tag
    argocd-image-updater.argoproj.io/webhook.helm.image-name: cainjector.image.repository
    argocd-image-updater.argoproj.io/webhook.helm.image-tag: cainjector.image.tag
naiame-neltheri commented 9 months ago

Sorry for late response @frittenlab . I can't see how your annotation is different from my annotation, also I believe this is related to multiple updates on same application causes it. Because it might be deleting the commit file before image updater can commit it due to another image update in progress. For example if image A is being updated and B is also starting the first thing argocd-image-updater does is to clean the directory hence uncommitted files deleted. Can this be the case?