0

I'm fairly new to helm as I use charts created by other ppl for our applications and I'm trying to do something that I suppose is kinda easy but couldn't manage to find how to. Basically I want to pass application version to my react app. Based on the few information I found, here is what I came up with

image:
    tag: 0.2.6
extraEnv:
  - name: REACT_APP_APP_VERSION
    value: {image.tag}

thx in advance

kadamb
  • 1,532
  • 3
  • 29
  • 55
  • 1
    See if you can find any solution here: https://stackoverflow.com/questions/49928819/how-to-pull-environment-variables-with-helm-charts – kadamb May 28 '20 at 19:02

2 Answers2

0

I assume the code you sent is your values.yaml. Then, the first part is correct.

image:
    tag: 0.2.6

Now, you don't specify variables passed to pod in values.yaml, but in your templates/* files. For example, to pass an variable to your pod, you can use the following code:

env:
  - name: REACT_APP_APP_VERSION
    value: "{{ .Values.image.tag }}"

Check this for the complete example.

Note that you cannot use values from values.yaml inside values.yaml. So the code you sent won't work. That is because, the values.yaml file itself is not evaluated.

Rafał Leszko
  • 4,939
  • 10
  • 19
  • Actually we have a values.yaml that contains values that are identical to every env. Then we have have an override values for each env and this is where I have both image.tag and REACT_APP_APP_VERSION var. I guess it's impossible to achieve what I wanna do without major conf changes then. Thx for you help – Maxime Couture May 28 '20 at 12:58
  • you actually can use templates in values.yaml and call `tpl` function for values in your chart template – edbighead May 29 '20 at 07:45
0

From Documentation

The tpl function allows developers to evaluate strings as templates inside a template. This is useful to pass a template string as a value to a chart or render external configuration files. Syntax: {{ tpl TEMPLATE_STRING VALUES }}

You will have something similar to

values.yaml

image:
  repository: k8s.gcr.io/busybox
  tag: "latest"

extraEnv: "{{ .Values.image.tag }}"

pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  containers:
  - name: test
    image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
    env:
    - name: REACT_APP_APP_VERSION
      value: {{ tpl .Values.extraEnv . }}

helm template output for pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  containers:
  - name: test
    image: "k8s.gcr.io/busybox:latest"
    env:
    - name: REACT_APP_APP_VERSION
      value: latest
Mohammad Faisal
  • 5,783
  • 15
  • 70
  • 117
edbighead
  • 5,607
  • 5
  • 29
  • 35