Lesson 5 · This repo's library-chart architecture

Named templates & helpers

Reusable template blocks — define + include — and the fullname/labels pattern that glues objects together.

Your win: explain what a named template is, how define/include work, and the fullname/labels helper pattern — the foundation of the util.* library you'll dissect next lesson.

Named templates = functions for YAML

A named template (a "partial") is a reusable block created with {{ define "name" }}…{{ end }} and invoked with include.1 Think of it as a function: define once, call from many manifests. By convention they live in leading-underscore files (so they don't render as manifests) and are prefixed with a namespace to avoid clashes — here, everything is util.*.

# define once (in a _*.tpl file)
{{- define "util.labels" -}}
app.kubernetes.io/name: {{ include "util.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

# call from any manifest, indented into place
metadata:
  labels: {{- include "util.labels" . | nindent 4 }}

Recall Lesson 3: use include (not template) so the output can be piped to nindent. The . passed as the second argument is the context the template renders against — get that wrong and .Values is empty inside the partial.

The fullname / labels pattern

Two helpers appear in nearly every real chart, because they solve a concrete problem — keeping an object's name and labels consistent so a Deployment, its Pods, and its Service selector all agree (Course 2 L4–5):2

Anchor — the repo's helpers (no _helpers.tpl) Instead of one _helpers.tpl, this repo splits partials by concern, all util.*: Every object template — Deployment, Service, PDB — calls these, which is why a service's Deployment name, its Service, and their selector labels always line up.
Why the 63-char truncation matters Kubernetes label values (and many names) are capped at 63 characters. A fullname helper always trunc 63 | trimSuffix "-" so a long release/chart name can't produce an invalid object. It's a small detail interviewers love, and forgetting it is a real production bug.
Read this next

Helm docs — Named Templates + Best Practices (labels)

define/include/template, the naming convention, and the standard labels/fullname pattern.

helm.sh — Named Templates
helm.sh — Best Practices: Labels

Check yourself (from memory)

Q1. A named template is created and used with…

{{ define "name" }}…{{ end }} creates it; include "name" . renders it (pipeable, unlike template).

Q2. The second argument in include "util.labels" . is…

Pass . so .Values/.Release resolve inside the partial; wrong context = empty values.

Q3. The fullname helper truncates to 63 chars because…

The 63-char limit on label values / DNS names; the helper does trunc 63 | trimSuffix "-" to stay valid.
Named templates + the fullname/labels pattern — and this repo's helpers.
recall, then click to reveal
A NAMED TEMPLATE (partial) = a reusable block: {{ define "name" }}…{{ end }}, invoked with include "name" . (pipeable; prefer over template). Convention: leading-underscore file (no manifest) + namespace prefix to avoid clashes. Pass . = the CONTEXT (so .Values/.Release resolve). FULLNAME/LABELS PATTERN: fullname = canonical object name (trunc 63 | trimSuffix "-" for K8s's 63-char cap); labels = standard app.kubernetes.io/*; selectorLabels = the stable subset a Service/ReplicaSet matches → keeps Deployment/Pods/Service in sync. REPO: no _helpers.tpl; split into util.name/fullname (_name.tpl), util.labels/selectorLabels (_label.tpl), util.environment/vendor (_env.tpl).
Want to read the actual util.fullname body, or see how util.labels.v2 adds a component for the -consumers workload? Ask me.

1. Helm — Named Templates.

2. Helm — Best Practices: Labels.