argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
17.72k stars 5.4k forks source link

Image set in an Application has no effect when using Kustomize image transformers #14631

Open BillyMorgan opened 1 year ago

BillyMorgan commented 1 year ago

My Argo application has the following image set:

Source:
    Kustomize:
      Images:
        busybox:1.24.0

Kustomization:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
  - name: container-image
    newName: busybox
    newTag: ubuntu
resources:
  - base-deployment.yaml

base-deployment.yaml looks like:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      role: deployment
  template:
    metadata:
      labels:
        role: deployment
    spec:
      containers:
        - name: test-pod
          image: container-image
          command: ["tail", "-f", "/dev/null"]

As a result I get the busybox:ubuntu image, where I would expect to get the busybox:1.24.0 image from the Argo application.

argocd: v2.6.7+5bcd846
  BuildDate: 2023-03-23T15:24:49Z
  GitCommit: 5bcd846fa16e4b19d8f477de7da50ec0aef320e5
  GitTreeState: clean
  GoVersion: go1.18.10
  Compiler: gc
  Platform: linux/amd64
argocd-server: v2.6.7+5bcd846
  BuildDate: 2023-03-23T14:57:27Z
  GitCommit: 5bcd846fa16e4b19d8f477de7da50ec0aef320e5
  GitTreeState: clean
  GoVersion: go1.18.10
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v4.5.7 2022-08-02T16:35:54Z
  Helm Version: v3.10.3+g835b733
  Kubectl Version: v0.24.2
  Jsonnet Version: v0.19.1
David3310273 commented 1 year ago

Hi @BillyMorgan, I wonder what's your output yaml script of kustomize build command, would you like to show me that?

BillyMorgan commented 1 year ago

@David3310273 Sure thing, here you go, it's as you'd expect tho:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      role: deployment
  template:
    metadata:
      labels:
        role: deployment
    spec:
      containers:
      - command:
        - tail
        - -f
        - /dev/null
        image: busybox:ubuntu
        imagePullPolicy: Always
        name: test-pod
joebowbeer commented 10 months ago

The current behavior is caused because kustomize edit set image is prepended rather than appended.

The Application images are added using kustomize edit set image here:

https://github.com/argoproj/argo-cd/blob/master/util/kustomize/kustomize.go#L141

and then kustomize build is run.

Unfortunately, after calling kustomize edit set image busybox:1.24.0, the kustomization.yaml file is effectively:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- base-deployment.yaml
images:
- name: busybox
  newTag: 1.24.0
- name: container-image
  newName: busybox
  newTag: ubuntu

If kustomize edit set image appended instead, then it would work as the OP expected.

As a workaround, remove the image transforms from the top-level kustomization.

Another workaround might be to move the image transforms to .argocd-source.yaml

https://argo-cd.readthedocs.io/en/stable/user-guide/parameters/#store-overrides-in-git