From fc1271dc6a04bdf66bbb4a23317ec0c9f0f9db89 Mon Sep 17 00:00:00 2001 From: ironashram Date: Wed, 23 Mar 2022 12:27:38 +0100 Subject: [PATCH] improve custom template handling (#48) Add a new `templateFile` option that references a file instead of copy/pasting the template into the values chart. --- haproxy-ingress/README.md | 1 + haproxy-ingress/templates/_podtemplate.yaml | 10 +++++----- haproxy-ingress/templates/controller-template.yaml | 11 +++++++---- haproxy-ingress/values.yaml | 4 +++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/haproxy-ingress/README.md b/haproxy-ingress/README.md index 4406a12..f675921 100755 --- a/haproxy-ingress/README.md +++ b/haproxy-ingress/README.md @@ -109,6 +109,7 @@ Parameter | Description | Default `controller.extraContainers` | extra containers that to the haproxy-ingress-controller | `[]` `controller.initContainers` | extra containers that can initialize the haproxy-ingress-controller | `[]` `controller.template` | custom template for haproxy-ingress-controller | `{}` +`controller.templateFile` | custom haproxy template path for haproxy-ingress-controller | `""` `controller.defaultBackendService` | backend service to use if defaultBackend.enabled==false | `""` `controller.ingressClass` | name of the ingress class to route through this controller | `haproxy` `controller.ingressClassResource.enabled` | create an [IngressClass](https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class) resource for this controller | `false` diff --git a/haproxy-ingress/templates/_podtemplate.yaml b/haproxy-ingress/templates/_podtemplate.yaml index 882e7f2..cd3259f 100644 --- a/haproxy-ingress/templates/_podtemplate.yaml +++ b/haproxy-ingress/templates/_podtemplate.yaml @@ -1,7 +1,7 @@ {{- define "haproxy-ingress.controller.podTemplate" -}} metadata: annotations: -{{- if .Values.controller.template }} +{{- if or .Values.controller.template .Values.controller.templateFile }} checksum/config: {{ include (print $.Template.BasePath "/controller-template.yaml") . | sha256sum }} {{- end }} {{- if .Values.controller.podAnnotations }} @@ -94,7 +94,7 @@ spec: {{- if .Values.controller.extraEnvs }} {{- toYaml .Values.controller.extraEnvs | nindent 8 }} {{- end }} -{{- if or .Values.controller.haproxy.enabled .Values.controller.template .Values.controller.extraVolumeMounts }} +{{- if or .Values.controller.haproxy.enabled .Values.controller.template .Values.controller.templateFile .Values.controller.extraVolumeMounts }} volumeMounts: {{- if .Values.controller.haproxy.enabled }} - mountPath: /etc/haproxy @@ -104,7 +104,7 @@ spec: - mountPath: /var/run/haproxy name: run {{- end }} -{{- if .Values.controller.template }} +{{- if or .Values.controller.template .Values.controller.templateFile }} - name: haproxy-template mountPath: /etc/templates/haproxy {{- end }} @@ -226,7 +226,7 @@ spec: imagePullSecrets: {{- toYaml .Values.controller.imagePullSecrets | nindent 4 }} {{- end }} -{{- if or .Values.controller.haproxy.enabled .Values.controller.template .Values.controller.extraVolumes }} +{{- if or .Values.controller.haproxy.enabled .Values.controller.template .Values.controller.templateFile .Values.controller.extraVolumes }} volumes: {{- if .Values.controller.haproxy.enabled }} - name: etc @@ -236,7 +236,7 @@ spec: - name: run emptyDir: {} {{- end }} -{{- if .Values.controller.template }} +{{- if or .Values.controller.template .Values.controller.templateFile }} - name: haproxy-template configMap: name: {{ include "haproxy-ingress.fullname" . }}-template diff --git a/haproxy-ingress/templates/controller-template.yaml b/haproxy-ingress/templates/controller-template.yaml index 49b73d2..b589b1b 100644 --- a/haproxy-ingress/templates/controller-template.yaml +++ b/haproxy-ingress/templates/controller-template.yaml @@ -1,4 +1,4 @@ -{{- if .Values.controller.template -}} +{{- if or .Values.controller.template .Values.controller.templateFile -}} apiVersion: v1 kind: ConfigMap metadata: @@ -7,7 +7,10 @@ metadata: name: {{ include "haproxy-ingress.fullname" . }}-template namespace: {{ .Release.Namespace }} data: - haproxy.tmpl: |- -{{ .Values.controller.template | indent 4 }} -{{/* .Files.Get "haproxy.tmpl" | indent 4 */}} + haproxy.tmpl: | +{{- if .Values.controller.templateFile }} + {{- .Files.Get .Values.controller.templateFile | nindent 4 }} +{{- else }} + {{- .Values.controller.template | nindent 4 }} +{{- end }} {{- end }} diff --git a/haproxy-ingress/values.yaml b/haproxy-ingress/values.yaml index b51350f..5c68c5b 100644 --- a/haproxy-ingress/values.yaml +++ b/haproxy-ingress/values.yaml @@ -52,8 +52,10 @@ controller: ## Additional containers that can initialize the pod. initContainers: [] - # custom haproxy template + ## Custom haproxy template template: "" + ## Path to custom haproxy.tmpl to load into the configmap + templateFile: "" ## A manually deployed default backend service ## Ignored if defaultBackend.enabled = true