Hooks and Dependencies

Helm Hooks and Chart Dependencies

A hook is a template with a helm.sh/hook annotation, run at a lifecycle point (pre- or post- install, upgrade, delete or rollback, or test); Helm 29,435 waits for a hook Job to finish. BookNest runs its SQL migrations (Migration Job) this way, after the API has created the base schema:

The hook annotations in helm/booknest/templates/migrate-hook.yamlYAML
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-migrations
  annotations:
    helm.sh/hook: post-install,post-upgrade
    helm.sh/hook-weight: "-1"            # lower weights run first: the SQL before the Job
    helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
data: {{- (.Files.Glob "migrations/*.sql").AsConfig | nindent 2 }}
# ... then a Job with the same hook annotations runs psql over /migrations/*.sql ...

A failed hook fails the install or upgrade, and helm uninstall leaves hook objects behind unless a delete policy removes them. Use pre-upgrade when new code needs the migrated schema first.

A dependency is a subchart installed with yours. BookNest's PostgreSQL 1,289 StatefulSet becomes its own chart, helm/postgres, which an install can switch off for another database (PostgreSQL Operator). .Files.Glob reads only files inside the chart, so the migrations are copied in:

Declaring the postgres subchart and vendoring it with the migrationsShell
cat >> helm/booknest/Chart.yaml <<'EOF'
dependencies:
- name: postgres
  version: 0.1.0
  repository: file://../postgres
  condition: postgres.enabled
EOF
mkdir -p helm/booknest/migrations && cp db/migrations/*.sql helm/booknest/migrations/
helm dependency update helm/booknest --skip-refresh >/dev/null
find helm/booknest/charts helm/booknest/Chart.lock -type f
Output
helm/booknest/charts/postgres-0.1.0.tgz
helm/booknest/Chart.lock

repository also takes an HTTP or oci:// URL, and version a range such as ~16.7.0, which dependency update pins in Chart.lock (commit it). The parent's postgres: values reach the subchart as its .Values.