eventhorizon
eventhorizon

Reputation: 3377

How to use a generated env configMap entry as a var in kustomize?

I have a generated config map

configMapGenerator:
  - name: template-vars
    envs:
      - templateVars.env

and would like to use one of the contained values

ROUTE_HOST=somewhere.else.org

as a variable

vars:
  - name: ROUTE_HOST
    objref:
      kind: ConfigMap
      name: template-vars
      apiVersion: v1
    fieldref:
      fieldpath: data.ROUTE_HOST

in my OCP route

apiVersion: route.openshift.io/v1
kind: Route
spec:
  host: $(ROUTE_HOST)

Is this possible?

I know that I can do some nearly equal thing with env vars:

env:
  - name: ROUTE_HOST
    valueFrom:
      configMapKeyRef:
        name: template-vars
        key: ROUTE_HOST

Upvotes: 5

Views: 4683

Answers (1)

ITChap
ITChap

Reputation: 4752

Yes it's possible. I currently do it for most of my ingresses host. By default the var plugins doesn't work on all the fields of all the resources. In order for kustomize to interpolate the $(ROUTE_HOST) in your resource, you need to add a configuration to your kustomization.yaml file:

kustomization.yaml:

configMapGenerator:
  - name: template-vars
    envs:
      - templateVars.env

vars:
  - name: ROUTE_HOST
    objref:
      kind: ConfigMap
      name: template-vars
      apiVersion: v1
    fieldref:
      fieldpath: data.ROUTE_HOST

configurations:
  - transformer_config.yaml

and transformer_config.yaml:

varReference:
  - path: spec/host

Upvotes: 6

Related Questions