diff --git a/haproxy/templates/_helpers.tpl b/haproxy/templates/_helpers.tpl index 8c23e8f..71537a7 100644 --- a/haproxy/templates/_helpers.tpl +++ b/haproxy/templates/_helpers.tpl @@ -103,3 +103,26 @@ Encode an imagePullSecret string. {{- end }} {{/* vim: set filetype=mustache: */}} + +{{/* +Exposed ports to service +*/}} +{{- define "haproxy.exposedPorts" }} +{{- $exposedPorts := .Values.service.exposedPorts }} +{{- if empty $exposedPorts }} +{{- $containerPorts := .Values.containerPorts }} +{{- range $key, $port := $containerPorts }} +- name: {{ $key }} + protocol: TCP + port: {{ $port }} + targetPort: {{ $key }} +{{- end }} +{{- else }} +{{- range $key, $port := $exposedPorts }} +- name: {{ $key }} + protocol: TCP + port: {{ $port }} + targetPort: {{ $key }} +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/haproxy/templates/service.yaml b/haproxy/templates/service.yaml index 776d2b9..1f54def 100644 --- a/haproxy/templates/service.yaml +++ b/haproxy/templates/service.yaml @@ -51,14 +51,7 @@ spec: {{- end }} {{- if or .Values.containerPorts .Values.service.additionalPorts }} ports: - {{- with .Values.containerPorts }} - {{- range $key, $port := . }} - - name: {{ $key }} - protocol: TCP - port: {{ $port }} - targetPort: {{ $key }} - {{- end }} - {{- end }} + {{- include "haproxy.exposedPorts" . | nindent 3 -}} {{- with .Values.service.additionalPorts }} {{- range $key, $port := . }} - name: {{ $key }} diff --git a/haproxy/values.yaml b/haproxy/values.yaml index 13adc4a..85644ea 100644 --- a/haproxy/values.yaml +++ b/haproxy/values.yaml @@ -484,6 +484,12 @@ service: additionalPorts: {} # prometheus: 9101 + ## Deterministic exposure of ports to the service + ## .Values.containerPorts will be exposed if exposedPorts is empty + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/ + exposedPorts: {} + # http: 80 + serviceMonitor: ## Toggle the ServiceMonitor true if you have Prometheus Operator installed and configured enabled: false