How do you use Garden variables with Kustomize?
# 🌱|help-and-getting-started
c
I have a Build action that provides Docker images to a Kubernetes Deployment, and I store the output of that Build action on the Deployment as a variable like
variables.SOME_IMAGE
so that the YAML files can substitute any instances of
${var.SOME_IMAGE}
and deploy with the right image. When I'm using Kustomize, however, it doesn't look like Kustomize is given access to Garden variables. So I can no longer use the
${var.SOME_IMAGE}
method I was using beforehand to get custom images into a Kustomize deployment. Is there a canonical way to access Garden variables when using Kustomize? Is this a bug or intended behavior?
q
Hi @clever-policeman-58407, to give me some idea, are you able to reproduce what your relevant
garden.yml
files look like for deploying your Kustomize manifests? Do you know of the
patchResources
field we expose for Kustomize? It's intended for cases like this. https://docs.garden.io/reference/module-types/kubernetes#patchresources You'd then reference the image https://docs.garden.io/other-plugins/container#referencing-from-other-actions https://docs.garden.io/reference/action-types/build/container#usd-actions.build.less-than-name-greater-than.outputs.deploymentimageid e.g.
${actions.build.<name>.outputs.deploymentImageId}
c
Ah, brilliant. This solves my usecase. For the sake of future searchers, this is an example of my usage with the completed solution:
Copy code
kind: Deploy
type: kubernetes
name: admin-api
variables:
  ADMIN_IMAGE: ${actions.build.admin-api.outputs.deployment-image-name}:${actions.build.admin-api.version}
dependencies:
  - build.admin-api
spec:
  kustomize:
    path: ./kubernetes/overlays/${environment.name}
  patchResources:
    - name: admin-api
      kind: Deployment
      patch:
        spec:
          template:
            spec:
              containers:
                - name: api-container
                  image: ${var.ADMIN_IMAGE}
              initContainers:
                - name: init-api
                  image: ${var.ADMIN_IMAGE}