chart: refuse to render without an explicit namespace
Helm falls back to the "default" namespace when --namespace is omitted, so a forgotten flag (or a Kustomize helmCharts entry without namespace) silently deployed into the wrong place. Render the namespace through one helper that fails on an empty or implicit "default" namespace, with allowDefaultNamespace as an explicit opt-in. scripts/check-chart.sh lints the chart, asserts every namespaced resource carries the passed namespace, and checks both failure and opt-in paths. CI runs it instead of the plain template call. Bump the chart to 0.2.1.
This commit is contained in:
1 parent
0cd0b9582d
commit
8e87fed93f
11 files changed
+120
-10
No files matched your search
@@ -31,3 +31,22 @@ app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- define "audiomanager.image" -}}
|
||||
{{- printf "%s:%s" .Values.image.repository (default .Chart.AppVersion .Values.image.tag) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
The namespace every resource is rendered into.
|
||||
|
||||
Helm falls back to "default" when --namespace is omitted, which would silently
|
||||
put the release somewhere the operator did not ask for. Refuse to render in
|
||||
that case unless the fallback is explicitly allowed, so a forgotten --namespace
|
||||
(or a kustomization without namespace:) fails instead of deploying.
|
||||
*/}}
|
||||
{{- define "audiomanager.namespace" -}}
|
||||
{{- $namespace := .Release.Namespace -}}
|
||||
{{- if not $namespace -}}
|
||||
{{- fail "a namespace is required: pass --namespace <namespace> (or set namespace: in the Kustomize helmCharts entry)" -}}
|
||||
{{- end -}}
|
||||
{{- if and (eq $namespace "default") (not .Values.allowDefaultNamespace) -}}
|
||||
{{- fail "refusing to deploy into the implicit \"default\" namespace: pass --namespace <namespace>, or set allowDefaultNamespace=true to opt in" -}}
|
||||
{{- end -}}
|
||||
{{- $namespace -}}
|
||||
{{- end -}}
|
||||
@@ -2,7 +2,7 @@ apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: {{ include "audiomanager.fullname" . }}-library
|
||||
namespace: {{ .Release.Namespace }}
|
||||
namespace: {{ include "audiomanager.namespace" . }}
|
||||
labels:
|
||||
{{- include "audiomanager.labels" . | nindent 4 }}
|
||||
data:
|
||||
|
||||
@@ -2,7 +2,7 @@ apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ include "audiomanager.fullname" . }}
|
||||
namespace: {{ .Release.Namespace }}
|
||||
namespace: {{ include "audiomanager.namespace" . }}
|
||||
labels:
|
||||
{{- include "audiomanager.labels" . | nindent 4 }}
|
||||
spec:
|
||||
|
||||
@@ -3,7 +3,7 @@ apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: {{ include "audiomanager.fullname" . }}
|
||||
namespace: {{ .Release.Namespace }}
|
||||
namespace: {{ include "audiomanager.namespace" . }}
|
||||
labels:
|
||||
{{- include "audiomanager.labels" . | nindent 4 }}
|
||||
{{- with .Values.ingress.annotations }}
|
||||
|
||||
@@ -3,7 +3,7 @@ apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: {{ include "audiomanager.fullname" . }}-data
|
||||
namespace: {{ .Release.Namespace }}
|
||||
namespace: {{ include "audiomanager.namespace" . }}
|
||||
labels:
|
||||
{{- include "audiomanager.labels" . | nindent 4 }}
|
||||
spec:
|
||||
|
||||
@@ -2,7 +2,7 @@ apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ include "audiomanager.fullname" . }}
|
||||
namespace: {{ .Release.Namespace }}
|
||||
namespace: {{ include "audiomanager.namespace" . }}
|
||||
labels:
|
||||
{{- include "audiomanager.labels" . | nindent 4 }}
|
||||
spec:
|
||||
|
||||
Reference in new issue
Block a user