5

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
halfer
  • 19,824
  • 17
  • 99
  • 186
eventhorizon
  • 2,977
  • 8
  • 33
  • 57
  • Note that we prefer a technical style of writing here. We gently discourage greetings, hope-you-can-helps, thanks, advance thanks, notes of appreciation, regards, kind regards, signatures, please-can-you-helps, chatty material and abbreviated txtspk, pleading, how long you've been stuck, voting advice, meta commentary, etc. Just explain your problem, and show what you've tried, what you expected, and what actually happened. – halfer Dec 16 '20 at 21:42

1 Answers1

6

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
Alexandre
  • 499
  • 1
  • 3
  • 15
ITChap
  • 4,057
  • 1
  • 21
  • 46