argoproj / argo-cd

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

Support envsubst in Kustomize patches #19459

Open sethryder opened 1 month ago

sethryder commented 1 month ago

Summary

It would be helpful if we could use envsubst (specifically Build Environment variables) in patches for Kustomize like we can for commonLabels and commonAnnotations. This is specifically for the Application kind as we can get this to work with go templates for ApplicationSets.

Motivation

There are times were we have specific labels we want to set on just Deployments and not on every object, for example the short hash of the git commit for the Datadog version label.

patches:
  - target:
      kind: Deployment
      name: deployment
    patch: |-
      - op: replace
        path: /metadata/labels/tags.datadoghq.com~1version
        value: ${ARGOCD_APP_REVISION_SHORT}
      - op: replace
        path: /spec/template/metadata/labels/tags.datadoghq.com~1version
        value: ${ARGOCD_APP_REVISION_SHORT}

Proposal

I believe it should work the same way as it does for commonLabels/commonAnnotations. But maybe a flag like commonAnnotationsEnvsubst for turning in on for patches would be best/required.

christianh814 commented 1 month ago

Unless I'm misunderstanding the ask, but I think this is available now

https://github.com/argoproj/argo-cd/blob/master/docs/operator-manual/application.yaml#L118

sethryder commented 1 month ago

Unless I'm misunderstanding the ask, but I think this is available now

https://github.com/argoproj/argo-cd/blob/master/docs/operator-manual/application.yaml#L118

I believe currently envsubst only works on Labels/Annotations. What I am looking for is being able to use them in the actual patch definitions. I mentioned commonAnnotationsEnvsubst as an example if Argo wanted to use something like patchEnvsubst to be able to turn it on/off.