Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i reference the namespace in values.yaml?

I would like to be able to reference the current namespace in values.yaml to use it to suffix some values like this

# in values.yaml
someParam: someval-{{ .Release.Namespace }}

It much nicer to define it this way instead of going into all my templates and adding {{ .Release.Namespace }}. If I can do it in values.yaml it's much clearer and only needs to be defined in one place.

like image 810
red888 Avatar asked Aug 23 '19 22:08

red888


People also ask

Can you use values in chart YAML?

Chart developers may supply a file called values. yaml inside of a chart. This file can contain default values. Chart users may supply a YAML file that contains values.

What is release namespace?

Release. Namespace : The namespace to be released into (if the manifest doesn't override) Release. IsUpgrade : This is set to true if the current operation is an upgrade or rollback.

What is values YAML for?

The list above is in order of specificity: values. yaml is the default, which can be overridden by a parent chart's values. yaml , which can in turn be overridden by a user-supplied values file, which can in turn be overridden by --set parameters. Values files are plain YAML files. Let's edit mychart/values.


1 Answers

You can use named templates to define re-usable helper templates. E.g.

In templates/_helpers.tpl:

{{- define "myChart.someParam" -}}someval-{{ .Release.Namespace }}{{- end -}}

In templates/configmap.yaml (for example):

apiVersion: v1
kind: ConfigMap
metadata:
  name: something
data:
  foo: {{ template "myChart.someParam" . }}

The result:

$ helm template . --namespace=bar
---
# Source: helm/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: something
data:
  foo: someval-bar
like image 150
Amit Kumar Gupta Avatar answered Nov 03 '22 10:11

Amit Kumar Gupta