How does a parent chart reference a subchart's Service name reliably?
AdvancedConceptDependencies, Subcharts & Library Charts
Answer
Options, from simplest to cleanest:
- Rely on the subchart's naming convention and replicate it:
{{ .Release.Name }}-postgres. Breaks if the user setspostgres.fullnameOverride. - Read the override in the parent:
{{ .Values.postgres.fullnameOverride | default (printf "%s-postgres" .Release.Name) }}. - Call the subchart's own helper with a constructed context (works on any Helm 3 version; recent versions also expose the subchart scope as
.Subcharts.postgres):
{{- $pgCtx := dict "Values" .Values.postgres "Release" .Release "Chart" (dict "Name" "postgres") }}
host: {{ include "shop-postgres.fullname" $pgCtx }}
Document the chosen approach in values.yaml so overrides stay consistent.
More on Dependencies, Subcharts & Library Charts
How do you declare a chart dependency in Helm 3?BeginnerWhat is the difference between `helm dependency update` and `helm dependency build`?IntermediateWhat is `Chart.lock` and why commit it?BeginnerHow does `condition` work on a dependency?BeginnerWhat are `tags` on dependencies?IntermediateWhat does `alias` do on a dependency?Intermediate