helmfile icon indicating copy to clipboard operation
helmfile copied to clipboard

Incorrectly reported missing values from Values map

Open stjudecloud-cloudy opened this issue 5 years ago • 4 comments

When environment variables are used in helmfile.yaml definition, missing values are reported incorrectly.

How to reproduce the issue:

Following configuration files were used:

helmfile.yaml

helmDefaults:
  cleanupOnFail: false
  atomic: false
  wait: false

repositories:
- name: stable
  url: https://kubernetes-charts.storage.googleapis.com

releases:
- name: test
  namespace: {{ .Values.deploymentNamespace }}
  chart: {{ .Values.chartName }}

environments:
  default:
    values:
    - env/{{ requiredEnv "DEPLOYMENT_ENV" }}/values.yaml
    - deploymentNamespace: {{ requiredEnv "DEPLOYMENT_NS" }}
    - chartName: stable/{{ env "CHART_NAME" }}

env/dev/values.yaml

global:
  test: "123"

Tests carried:

With no environment variable set:

ubuntu:/tmp/helmfile$ ./helmfile -i apply
in ./helmfile.yaml: error during helmfile.yaml.part.0 parsing: template: stringTemplate:12:23: executing "stringTemplate" at <.Values.deploymentNamespace>: map has no entry for key "deploymentNamespace"

When DEPLOYMENT_NS is set:

ubuntu:/tmp/helmfile$ export DEPLOYMENT_NS=default 
ubuntu:/tmp/helmfile$ ./helmfile -i apply
in ./helmfile.yaml: error during helmfile.yaml.part.0 parsing: template: stringTemplate:12:23: executing "stringTemplate" at <.Values.deploymentNamespace>: map has no entry for key "deploymentNamespace"

still same error is displayed, even the environment variable is set.

With all environment variables set:

ubuntu:/tmp/helmfile$ export DEPLOYMENT_NS=default DEPLOYMENT_ENV=dev VERSION=0.1.1 CHART_NAME=vault-operator
ubuntu:/tmp/helmfile$ ./helmfile -i apply
Adding repo stable https://kubernetes-charts.storage.googleapis.com
"stable" has been added to your repositories

Comparing release=test, chart=stable/vault-operator
********************

        Release was not present in Helm.  Diff will show entire contents as new.

********************
default, test-vault-operator, ServiceAccount (v1) has been added:
- 
+ # Source: vault-operator/templates/service-account.yaml
+ apiVersion: v1
+ kind: ServiceAccount
+ metadata:
...

When referenced env/dev/values.yaml file is missing but all the environment variables are set:

ubuntu:/tmp/helmfile$ export DEPLOYMENT_NS=default DEPLOYMENT_ENV=dev VERSION=0.1.1 CHART_NAME=vault-operator
ubuntu:/tmp/helmfile$ ls -l env/dev/values.yaml
ls: cannot access 'env/dev/values.yaml': No such file or directory
ubuntu:/tmp/helmfile$ ./helmfile -i apply
in ./helmfile.yaml: error during helmfile.yaml.part.0 parsing: template: stringTemplate:12:23: executing "stringTemplate" at <.Values.deploymentNamespace>: map has no entry for key "deploymentNamespace"

Expected results: Each case should report different problem, different missing value, but instead it reports always same missing value. This makes any troubleshooting of any related issues difficult.

Helmfile version used: v0.125.7 ( same issue observed on version v0.102.0)

stjudecloud-cloudy avatar Aug 21 '20 18:08 stjudecloud-cloudy

Has anybody looked into the issue?

polasekr avatar Oct 13 '20 23:10 polasekr

@stjudecloud-cloudy @polasekr Hey! Due to how helmfile templating works, you need to put environments section before other configuration, and use of --- to split the parts would give you the best behaviour you might have expected.

So please try rewriting it like:


environments:
  default:
    values:
    - env/{{ requiredEnv "DEPLOYMENT_ENV" }}/values.yaml
    - deploymentNamespace: {{ requiredEnv "DEPLOYMENT_NS" }}
    - chartName: stable/{{ env "CHART_NAME" }}

---
helmDefaults:
  cleanupOnFail: false
  atomic: false
  wait: false

repositories:
- name: stable
  url: https://kubernetes-charts.storage.googleapis.com

releases:
- name: test
  namespace: {{ .Values.deploymentNamespace }}
  chart: {{ .Values.chartName }}

mumoshu avatar Oct 13 '20 23:10 mumoshu

@mumoshu I tested your version of helmfile and I can confirm that it behaves the expected way. Thank you for your solution. At the same time I am wondering, where I could do more reading on the topic of helmfile rendering, so I have better understanding of the solution itself. Would be possible to refer me to a specific section of documentation? Thank you again for your help.

polasekr avatar Oct 20 '20 13:10 polasekr

@mumoshu thanks this really helped me!

Just want to point out that the example configuration in the documentation does not follow this rule which led to my trouble in the first place.

https://github.com/roboll/helmfile#configuration

jholm117 avatar Feb 11 '22 17:02 jholm117