argocd-image-updater icon indicating copy to clipboard operation
argocd-image-updater copied to clipboard

Git write-back-target helmvalues Got panic: runtime error: invalid memory address or nil pointer dereference

Open minkbear opened this issue 1 year ago • 2 comments

Describe the bug

got error

time="2024-08-21T16:26:00Z" level=info msg=Trace args="[git fetch origin --tags --force --prune]" dir=/tmp/git-workload-in-cluster-app-podinfo-test1868138268 operation_name="exec git" time_ms=1916.5610530000001
time="2024-08-21T16:26:00Z" level=info msg="git config user.name argocd-image-updater" dir=/tmp/git-workload-in-cluster-app-podinfo-test1868138268 execID=29dd2
time="2024-08-21T16:26:00Z" level=info msg=Trace args="[git config user.name argocd-image-updater]" dir=/tmp/git-workload-in-cluster-app-podinfo-test1868138268 operation_name="exec git" time_ms=10.841928000000001
time="2024-08-21T16:26:00Z" level=info msg="git config user.email [email protected]" dir=/tmp/git-workload-in-cluster-app-podinfo-test1868138268 execID=da41d
time="2024-08-21T16:26:00Z" level=info msg=Trace args="[git config user.email [email protected]]" dir=/tmp/git-workload-in-cluster-app-podinfo-test1868138268 operation_name="exec git" time_ms=2.3861109999999996
time="2024-08-21T16:26:00Z" level=info msg="git checkout --force develop" dir=/tmp/git-workload-in-cluster-app-podinfo-test1868138268 execID=cd67d
time="2024-08-21T16:26:00Z" level=info msg=Trace args="[git checkout --force develop]" dir=/tmp/git-workload-in-cluster-app-podinfo-test1868138268 operation_name="exec git" time_ms=36.427568
time="2024-08-21T16:26:00Z" level=info msg="git clean -ffdx" dir=/tmp/git-workload-in-cluster-app-podinfo-test1868138268 execID=4d9e3
time="2024-08-21T16:26:00Z" level=info msg=Trace args="[git clean -ffdx]" dir=/tmp/git-workload-in-cluster-app-podinfo-test1868138268 operation_name="exec git" time_ms=5.22551
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1f565e8]

goroutine 131 [running]:
github.com/argoproj-labs/argocd-image-updater/pkg/argocd.mergeKustomizeOverride(0xc000117098, 0xb29?)
	/src/argocd-image-updater/pkg/argocd/update.go:528 +0x48
github.com/argoproj-labs/argocd-image-updater/pkg/argocd.marshalParamsOverride(0xc0006ee408, {0xc000824c00, 0xb29, 0xb2a})
	/src/argocd-image-updater/pkg/argocd/update.go:428 +0x4a5
github.com/argoproj-labs/argocd-image-updater/pkg/argocd.writeOverrides(0xc0006ee408, 0xc0007065a0, {0x2904318, 0xc0002768c0})
	/src/argocd-image-updater/pkg/argocd/git.go:279 +0x249
github.com/argoproj-labs/argocd-image-updater/pkg/argocd.commitChangesGit(0xc0006ee408, 0xc0007065a0, {0xc000981890, 0x1, 0x1}, 0x2694540)
	/src/argocd-image-updater/pkg/argocd/git.go:214 +0x746
github.com/argoproj-labs/argocd-image-updater/pkg/argocd.commitChanges(0xc000958ff0?, 0xc0006c02a0?, {0xc000981890?, 0xc000505648?, 0xcff4f1?})
	/src/argocd-image-updater/pkg/argocd/update.go:704 +0x4e
github.com/argoproj-labs/argocd-image-updater/pkg/argocd.commitChangesLocked(0xc0006ee408?, 0xc0007065a0?, 0x34?, {0xc000981890?, 0x1?, 0x1?})
	/src/argocd-image-updater/pkg/argocd/update.go:683 +0xfe
github.com/argoproj-labs/argocd-image-updater/pkg/argocd.UpdateApplication(0xc00098bb18, 0xc000958ff0)
	/src/argocd-image-updater/pkg/argocd/update.go:350 +0x1fcd
main.runImageUpdater.func1({_, _}, {{{{0xc00031ecc0, 0xb}, {0xc000209878, 0x14}}, {{0xc0006c0210, 0x24}, {0x0, 0x0}, ...}, ...}, ...})
	/src/argocd-image-updater/cmd/run.go:339 +0x2ef
created by main.runImageUpdater in goroutine 1
	/src/argocd-image-updater/cmd/run.go:321 +0x9d8
time="2024-08-21T16:26:27Z" level=info msg="argocd-image-updater v0.14.0+af844fe starting [loglevel:INFO, interval:2m0s, healthport:8080]"
time="2024-08-21T16:26:27Z" level=warning msg="commit message template at /app/config/commit.template does not exist, using default"
time="2024-08-21T16:26:27Z" level=info msg="Loaded 1 registry configurations from /app/config/registries.conf"

To Reproduce Steps to reproduce the behavior:

Add annotations for ApplicationSet

      annotations:
        argocd-image-updater.argoproj.io/image-list: "myimage=myecrrepo/app-podinfo:test"
        argocd-image-updater.argoproj.io/myimage.update-strategy: digest
        argocd-image-updater.argoproj.io/myimage.force-update: "true"
        argocd-image-updater.argoproj.io/myimage.helm.image-name: image.repository
        argocd-image-updater.argoproj.io/myimage.helm.image-tag: image.tag
        argocd-image-updater.argoproj.io/write-back-method: git
        argocd-image-updater.argoproj.io/write-back-target: "helmvalues:./../values.yaml"

and my values.yaml is

skipDeploy: "false"

containerPort: 9898

image:
  repository: myecrrepo/app-podinfo
  tag: test

container:
  command:

Expected behavior

change image.tag

Version

argocd-image-updater v0.14.0+af844fe

minkbear avatar Aug 21 '24 16:08 minkbear

around https://github.com/argoproj-labs/argocd-image-updater/blob/v0.14.0/pkg/argocd/update.go#L428 , the updater thinks its a kustomize type app instead of a helm type, and proceeds to write back as a kustomize app and failed. I'm wondering if there is anything in your app that makes it looks like a kustomize app?

chengfang avatar Aug 21 '24 17:08 chengfang

around https://github.com/argoproj-labs/argocd-image-updater/blob/v0.14.0/pkg/argocd/update.go#L428 , the updater thinks its a kustomize type app instead of a helm type, and proceeds to write back as a kustomize app and failed. I'm wondering if there is anything in your app that makes it looks like a kustomize app?

@chengfang Oh, I used helm and kustomize in the same folder look like below

├── app-podinfo
│   ├── test
│   │   ├── configs
│   │   │   ├── app-podinfos-configs-test.env
│   │   │   ├── kustomization.yaml
│   │   └── values.yaml

and my Application show below

spec:
      project: default
      sources:
      - repoURL: myecrrepo
        targetRevision: main
        path: 'apps/app-podinfo/test/configs'
        kustomize:
          commonAnnotationsEnvsubst: true
      - repoURL: 'https://chart.onechart.dev'
        chart: onechart
        targetRevision: 0.69.0
        helm:
          releaseName: app-podinfo
          ignoreMissingValueFiles: true
          valueFiles:
            - $values/gitops/workloads/configs/global-onechart-values.yaml
            - $values/apps/app-podinfo/test/values.yaml
          valuesObject:
            appName: app-podinfo
            podAnnotations:
              secret.reloader.stakater.com/reload: 'app-podinfo-secret'
              configmap.reloader.stakater.com/reload: 'app-podinfo-config'
            existingSecrets:
              - name: 'app-podinfo-secret'
            existingConfigMaps:
              - name: 'app-podinfo-config'
      - repoURL: myecrrepo
        targetRevision: main
        ref: values

minkbear avatar Aug 22 '24 02:08 minkbear

@minkbear Not sure if you solved this or if this is just useful for posterity, but I ran into the same error. Took me some time but I had to adjust my Application file by adding argocd-image-updater.argoproj.io/git-repository: [email protected]:org/test.git for the repository of where the values.yaml lived. It seems the go code does not just take helmvalues as the final answer for the ApplicationSourceType and instead goes through a checklist that can result in it thinking it's a Kustomization type instead. My final Application file looks like so:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: test
  namespace: argocd
  annotations:
    argocd-image-updater.argoproj.io/git-repository: [email protected]:org/test.git
    # use git write-back method 
    argocd-image-updater.argoproj.io/write-back-method: git
    argocd-image-updater.argoproj.io/write-back-target: helmvalues:/path/to/the/values.yaml
    # filter images to check for updates
    argocd-image-updater.argoproj.io/image-list: test-frontend=1234.ecr.us-east-1.amazonaws.com/test/frontend, test-worker=1234.dkr.ecr.us-east-1.amazonaws.com/test/worker
    # frontend
    argocd-image-updater.argoproj.io/test-frontend.update-strategy: newest-build
    argocd-image-updater.argoproj.io/test-frontend.helm.image-spec: main.image
    # # worker
    argocd-image-updater.argoproj.io/test-worker.update-strategy: newest-build
    argocd-image-updater.argoproj.io/test-worker.helm.image-spec: worker.image
spec:
  destination:
    namespace: 'test'
    name: 'test'
  sources:
    - repoURL: https://domain.github.io/chart
      targetRevision: 1.0
      chart: chart-name
      helm:
        releaseName: chart-name
        valueFiles:
          - $values/path/to/the/values.yaml
    - repoURL: '[email protected]:org/test.git'
      targetRevision: test
      ref: values
  project: test
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

I eventually ran into issues with not having the helm chart URL added to ArgoCD as a repository source but once that was added it worked.

loyal2thesea avatar Apr 09 '25 17:04 loyal2thesea

@loyal2thesea yes add argocd-image-updater.argoproj.io/git-repository that solved the problem. Thanks.

minkbear avatar Apr 10 '25 01:04 minkbear