hmar
hmar

Reputation: 117

Use Chart Values from Subchart in Helm

using 0.13.2 Helm provider terraform, I have a Chart with a subchart nested:

├── charts
│   └── postgres
│       ├── Chart.yaml
│       ├── templates
│       │   ├── deployment.yaml
│       │   ├── env.yaml
│       │   └── service.yaml
│       └── values.yaml
├── Chart.yaml
├── templates
│   ├── configmap.yaml
│   ├── deployment.yaml
│   ├── env.yaml
│   ├── ingress.yaml
│   └── service.yaml
└── values.yaml

I need to use from the deployment.yml of the postgres subchart, the values of the parent chart. How can I config the configmap of the subchart to get the parent chart values? My current configmap is like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-postgres-env
  namespace: {{ .Release.Namespace }}
data:
  {{- range $key, $val := .Values.environment }}
  {{ $key }}: {{ $val | quote }}
  {{- end }}

Thanks in advance.

Upvotes: 2

Views: 10573

Answers (1)

David Maze
David Maze

Reputation: 158656

You can't directly do this. In discussing Scope, Dependencies, and Values, the Helm documentation notes (with a motivating example):

Charts at a higher level have access to all of the variables defined beneath. So the WordPress chart can access [.Values.child.setting]. But lower level charts cannot access things in parent charts, so [the child] will not be able to access [a parent] property. Nor, for that matter, can it access [sibling subchart settings].

You have two options. If you move the settings under a global: key

global:
  environment:
    keys: values

then the parent and all subcharts will be able to access .Values.global.environment. Or, if you move the settings under a key specific to the subchart

postgres:
  environment:
    keys: values

then the subchart will see .Values.environment, and the parent can reference .Values.postgres.environment.

(If you can't use a prepackaged PostgreSQL chart, it's not necessarily wrong to flatten these parts into a single chart, making it clear from the filenames that something is statefulset-postgres.yml or svc-postgres.yml. Then the templates would be able to use the single .Values.)

Upvotes: 3

Related Questions