companyinfo / helm-charts

Company.info Helm charts repository
https://companyinfo.github.io/helm-charts
Apache License 2.0
71 stars 23 forks source link

envVars with object should quote environment variables #34

Open maarten-blokker opened 8 months ago

maarten-blokker commented 8 months ago

Hello, i've been using helmet for a little while and it makes creating a Helm chart quite a bit easier for me, thanks for creating this project!

In a recent task, I needed to define a chart with environment variables, including a port and a boolean value. Initially, Helmet used a list for envVars, which meant my custom envVars would override the predefined ones. However, with the update to version 0.11.0, Helmet now supports using a dictionary for envVars, allowing me to specify my variables in a values file without overriding the existing ones.

Unfortunately, I encountered a problem where the function fails to render environment variables as strings:

#values.yaml
image:
  repository: repo
envVars:
  SHOULD_BE_STRING: "true"
  SHOULD_BE_STRING_AS_WELL: "43"

this renders the following output:

...
    spec:
      restartPolicy: Always
      containers:
        - name: test
          image: docker.io/repo:latest
          imagePullPolicy: Always
          env:            
            - name: SHOULD_BE_STRING
              value: true
            - name: SHOULD_BE_STRING_AS_WELL
              value: 43
...

The spec.template.spec.containers.env.value should be a string, but the output incorrectly presents these values as a boolean and an integer (unquoted values).

bittrance commented 1 day ago

There is another probably common occasion where this is a problem, namely where you use YAML anchors. The obvious example is with port numbers which must be integers. E.g.:

ports:
  - name: api
    containerPort: &containerPort 8080

envVars:
  - name: BIND_PORT
    value: *containerPort

Kubernetes will fail this manifest because containerPort must be an int and env var must be a string. The linked PR would allow this.