Skip to content

Commit 59b16c4

Browse files
committed
Use Env expansion for namespace in args
When deploying the controller to a custom namespace, users have to overwrite the namespace attribute as well as the hardcoded namespace values in a number of args for the Deployment and the admission controller Jobs. Instead, this commit, uses the namespace name from the DownwardAPI, and allows users to simply change the namespace attribute without having to worry about the container args.
1 parent 3435e78 commit 59b16c4

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

charts/ingress-nginx/templates/_helpers.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Users can provide an override for an explicit service they want bound via `.Valu
4848
4949
*/}}
5050
{{- define "ingress-nginx.controller.publishServicePath" -}}
51-
{{- $defServiceName := printf "%s/%s" .Release.Namespace (include "ingress-nginx.controller.fullname" .) -}}
51+
{{- $defServiceName := printf "%s/%s" "$(POD_NAMESPACE)" (include "ingress-nginx.controller.fullname" .) -}}
5252
{{- $servicePath := default $defServiceName .Values.controller.publishService.pathOverride }}
5353
{{- print $servicePath | trimSuffix "-" -}}
5454
{{- end -}}

charts/ingress-nginx/templates/admission-webhooks/job-patch/job-createSecret.yaml

+7-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ spec:
3838
imagePullPolicy: {{ .Values.controller.admissionWebhooks.patch.image.pullPolicy }}
3939
args:
4040
- create
41-
- --host={{ include "ingress-nginx.controller.fullname" . }}-admission,{{ include "ingress-nginx.controller.fullname" . }}-admission.{{ .Release.Namespace }}.svc
42-
- --namespace={{ .Release.Namespace }}
41+
- --host={{ include "ingress-nginx.controller.fullname" . }}-admission,{{ include "ingress-nginx.controller.fullname" . }}-admission.$(POD_NAMESPACE).svc
42+
- --namespace=$(POD_NAMESPACE)
4343
- --secret-name={{ include "ingress-nginx.fullname" . }}-admission
44+
env:
45+
- name: POD_NAMESPACE
46+
valueFrom:
47+
fieldRef:
48+
fieldPath: metadata.namespace
4449
restartPolicy: OnFailure
4550
serviceAccountName: {{ include "ingress-nginx.fullname" . }}-admission
4651
{{- if .Values.controller.admissionWebhooks.patch.nodeSelector }}

charts/ingress-nginx/templates/admission-webhooks/job-patch/job-patchWebhook.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ spec:
3939
args:
4040
- patch
4141
- --webhook-name={{ include "ingress-nginx.fullname" . }}-admission
42-
- --namespace={{ .Release.Namespace }}
42+
- --namespace=$(POD_NAMESPACE)
4343
- --patch-mutating=false
4444
- --secret-name={{ include "ingress-nginx.fullname" . }}-admission
4545
- --patch-failure-policy={{ .Values.controller.admissionWebhooks.failurePolicy }}
46+
env:
47+
- name: POD_NAMESPACE
48+
valueFrom:
49+
fieldRef:
50+
fieldPath: metadata.namespace
4651
restartPolicy: OnFailure
4752
serviceAccountName: {{ include "ingress-nginx.fullname" . }}-admission
4853
{{- if .Values.controller.admissionWebhooks.patch.nodeSelector }}

charts/ingress-nginx/templates/controller-deployment.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,22 @@ spec:
7171
args:
7272
- /nginx-ingress-controller
7373
{{- if .Values.defaultBackend.enabled }}
74-
- --default-backend-service={{ .Release.Namespace }}/{{ include "ingress-nginx.defaultBackend.fullname" . }}
74+
- --default-backend-service=$(POD_NAMESPACE)/{{ include "ingress-nginx.defaultBackend.fullname" . }}
7575
{{- end }}
7676
{{- if .Values.controller.publishService.enabled }}
7777
- --publish-service={{ template "ingress-nginx.controller.publishServicePath" . }}
7878
{{- end }}
7979
- --election-id={{ .Values.controller.electionID }}
8080
- --ingress-class={{ .Values.controller.ingressClass }}
81-
- --configmap={{ .Release.Namespace }}/{{ include "ingress-nginx.controller.fullname" . }}
81+
- --configmap=$(POD_NAMESPACE)/{{ include "ingress-nginx.controller.fullname" . }}
8282
{{- if .Values.tcp }}
83-
- --tcp-services-configmap={{ .Release.Namespace }}/{{ include "ingress-nginx.fullname" . }}-tcp
83+
- --tcp-services-configmap=$(POD_NAMESPACE)/{{ include "ingress-nginx.fullname" . }}-tcp
8484
{{- end }}
8585
{{- if .Values.udp }}
86-
- --udp-services-configmap={{ .Release.Namespace }}/{{ include "ingress-nginx.fullname" . }}-udp
86+
- --udp-services-configmap=$(POD_NAMESPACE)/{{ include "ingress-nginx.fullname" . }}-udp
8787
{{- end }}
8888
{{- if .Values.controller.scope.enabled }}
89-
- --watch-namespace={{ default .Release.Namespace .Values.controller.scope.namespace }}
89+
- --watch-namespace={{ default "$(POD_NAMESPACE)" .Values.controller.scope.namespace }}
9090
{{- end }}
9191
{{- if and .Values.controller.reportNodeInternalIp .Values.controller.hostNetwork }}
9292
- --report-node-internal-ip-address={{ .Values.controller.reportNodeInternalIp }}

0 commit comments

Comments
 (0)