Skip to content

Commit 8b705eb

Browse files
committed
Refactor namespace handling in Docker registry Helm chart
- Create a reusable helper template "docker-registry.namespace" in _helpers.tpl - Replace all instances of "{{ .Values.namespace | default .Release.Namespace }}" with "{{ include "docker-registry.namespace" . }}" for consistency - Apply this change across all resource templates (deployment, service, configmap, secret, cronjob, pvc, etc.) This refactoring improves maintainability and ensures consistent namespace handling throughout the chart, particularly for multi-namespace deployments in combined charts. Signed-off-by: bwdmr <[email protected]>
1 parent 541f368 commit 8b705eb

File tree

10 files changed

+20
-9
lines changed

10 files changed

+20
-9
lines changed

templates/_helpers.tpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Allow the release namespace to be overridden for multi-namespace deployments in combined charts
4+
*/}}
5+
{{- define "docker-registry.namespace" -}}
6+
{{- if .Values.namespace -}}
7+
{{- .Values.namespace -}}
8+
{{- else -}}
9+
{{- .Release.Namespace -}}
10+
{{- end -}}
11+
{{- end -}}
12+
213
{{/*
314
Expand the name of the chart.
415
*/}}

templates/configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
kind: ConfigMap
33
metadata:
44
name: {{ template "docker-registry.fullname" . }}-config
5-
namespace: {{ .Values.namespace | default .Release.Namespace }}
5+
namespace: {{ include "docker-registry.namespace" . }}
66
labels:
77
app: {{ template "docker-registry.name" . }}
88
chart: {{ .Chart.Name }}-{{ .Chart.Version }}

templates/cronjob.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: batch/v1
33
kind: CronJob
44
metadata:
55
name: {{ template "docker-registry.fullname" . }}-garbage-collector
6-
namespace: {{ .Values.namespace | default .Release.Namespace }}
6+
namespace: {{ include "docker-registry.namespace" . }}
77
labels:
88
app: {{ template "docker-registry.name" . }}
99
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}

templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: apps/v1
22
kind: Deployment
33
metadata:
44
name: {{ template "docker-registry.fullname" . }}
5-
namespace: {{ .Values.namespace | default .Release.Namespace }}
5+
namespace: {{ include "docker-registry.namespace" . }}
66
labels:
77
app: {{ template "docker-registry.name" . }}
88
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}

templates/ingress.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ apiVersion: {{- if $apiVersions.Has "networking.k8s.io/v1" }} networking.k8s.io/
77
kind: Ingress
88
metadata:
99
name: {{ template "docker-registry.fullname" . }}
10-
namespace: {{ .Values.namespace | default .Release.Namespace }}
10+
namespace: {{ include "docker-registry.namespace" . }}
1111
labels:
1212
app: {{ template "docker-registry.name" . }}
1313
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}

templates/poddisruptionbudget.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ apiVersion: policy/v1beta1
77
kind: PodDisruptionBudget
88
metadata:
99
name: {{ template "docker-registry.fullname" . }}
10-
namespace: {{ .Values.namespace | default .Release.Namespace }}
10+
namespace: {{ include "docker-registry.namespace" . }}
1111
labels:
1212
app: {{ template "docker-registry.name" . }}
1313
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}

templates/pvc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: PersistentVolumeClaim
44
apiVersion: v1
55
metadata:
66
name: {{ template "docker-registry.fullname" . }}
7-
namespace: {{ .Values.namespace | default .Release.Namespace }}
7+
namespace: {{ include "docker-registry.namespace" . }}
88
labels:
99
app: {{ template "docker-registry.fullname" . }}
1010
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"

templates/secret.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
kind: Secret
33
metadata:
44
name: {{ template "docker-registry.fullname" . }}-secret
5-
namespace: {{ .Values.namespace | default .Release.Namespace }}
5+
namespace: {{ include "docker-registry.namespace" . }}
66
labels:
77
app: {{ template "docker-registry.name" . }}
88
chart: {{ .Chart.Name }}-{{ .Chart.Version }}

templates/service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
kind: Service
33
metadata:
44
name: {{ template "docker-registry.fullname" . }}
5-
namespace: {{ .Values.namespace | default .Release.Namespace }}
5+
namespace: {{ include "docker-registry.namespace" . }}
66
labels:
77
app: {{ template "docker-registry.name" . }}
88
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}

templates/serviceaccount.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
88
heritage: {{ .Release.Service }}
99
release: {{ .Release.Name }}
10-
namespace: {{ .Values.namespace | default .Release.Namespace }}
10+
namespace: {{ include "docker-registry.namespace" . }}
1111
{{- if .Values.serviceAccount.name }}
1212
name: {{ .Values.serviceAccount.name }}
1313
{{- else }}

0 commit comments

Comments
 (0)