From 23e750386c79e50162fe636268486a3d9de7f17b Mon Sep 17 00:00:00 2001 From: ironashram Date: Tue, 15 Mar 2022 18:12:04 +0100 Subject: [PATCH 1/5] improve custom template handling --- haproxy-ingress/README.md | 2 +- haproxy-ingress/templates/controller-template.yaml | 3 +-- haproxy-ingress/values.yaml | 5 +++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/haproxy-ingress/README.md b/haproxy-ingress/README.md index 4406a12..7ef56c4 100755 --- a/haproxy-ingress/README.md +++ b/haproxy-ingress/README.md @@ -108,7 +108,7 @@ Parameter | Description | Default `controller.extraVolumeMounts` | extra volume mounts for the haproxy-ingress-controller | `[]` `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.template` | custom template for haproxy-ingress-controller | `false` `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/controller-template.yaml b/haproxy-ingress/templates/controller-template.yaml index 49b73d2..c970608 100644 --- a/haproxy-ingress/templates/controller-template.yaml +++ b/haproxy-ingress/templates/controller-template.yaml @@ -8,6 +8,5 @@ metadata: namespace: {{ .Release.Namespace }} data: haproxy.tmpl: |- -{{ .Values.controller.template | indent 4 }} -{{/* .Files.Get "haproxy.tmpl" | indent 4 */}} +{{ (.Files.Glob "custom_template/haproxy.tmpl").AsConfig | indent 2 }} {{- end }} diff --git a/haproxy-ingress/values.yaml b/haproxy-ingress/values.yaml index b51350f..b768ac7 100644 --- a/haproxy-ingress/values.yaml +++ b/haproxy-ingress/values.yaml @@ -52,8 +52,9 @@ controller: ## Additional containers that can initialize the pod. initContainers: [] - # custom haproxy template - template: "" + ## Custom haproxy template + ## if set to true loads custom_template/haproxy.tmpl into the custom template configmap + template: false ## A manually deployed default backend service ## Ignored if defaultBackend.enabled = true From 525d71a5a0fd63ee0a97f02fab47c5508a4d6241 Mon Sep 17 00:00:00 2001 From: ironashram Date: Tue, 15 Mar 2022 20:30:48 +0100 Subject: [PATCH 2/5] fix --- haproxy-ingress/templates/controller-template.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/haproxy-ingress/templates/controller-template.yaml b/haproxy-ingress/templates/controller-template.yaml index c970608..a9e7647 100644 --- a/haproxy-ingress/templates/controller-template.yaml +++ b/haproxy-ingress/templates/controller-template.yaml @@ -7,6 +7,5 @@ metadata: name: {{ include "haproxy-ingress.fullname" . }}-template namespace: {{ .Release.Namespace }} data: - haproxy.tmpl: |- {{ (.Files.Glob "custom_template/haproxy.tmpl").AsConfig | indent 2 }} {{- end }} From 2fe2a39208393e39b7d89b39922167c238b779d9 Mon Sep 17 00:00:00 2001 From: ironashram Date: Tue, 22 Mar 2022 09:25:46 +0100 Subject: [PATCH 3/5] defaults custom template load from file --- haproxy-ingress/templates/controller-template.yaml | 4 +++- haproxy-ingress/values.yaml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/haproxy-ingress/templates/controller-template.yaml b/haproxy-ingress/templates/controller-template.yaml index a9e7647..5bd9d4a 100644 --- a/haproxy-ingress/templates/controller-template.yaml +++ b/haproxy-ingress/templates/controller-template.yaml @@ -7,5 +7,7 @@ metadata: name: {{ include "haproxy-ingress.fullname" . }}-template namespace: {{ .Release.Namespace }} data: -{{ (.Files.Glob "custom_template/haproxy.tmpl").AsConfig | indent 2 }} + haproxy.tmpl: | +{{/* .Values.controller.template | indent 4 */}} +{{ .Files.Get "haproxy.tmpl" | indent 4 }} {{- end }} diff --git a/haproxy-ingress/values.yaml b/haproxy-ingress/values.yaml index b768ac7..9e5032a 100644 --- a/haproxy-ingress/values.yaml +++ b/haproxy-ingress/values.yaml @@ -53,7 +53,7 @@ controller: initContainers: [] ## Custom haproxy template - ## if set to true loads custom_template/haproxy.tmpl into the custom template configmap + ## if set to true loads haproxy.tmpl into the custom template configmap template: false ## A manually deployed default backend service From c31fa7abc3a72e8afed422f630d0295759775490 Mon Sep 17 00:00:00 2001 From: ironashram Date: Wed, 23 Mar 2022 09:46:33 +0100 Subject: [PATCH 4/5] add controller.templateFile key --- haproxy-ingress/README.md | 3 ++- haproxy-ingress/templates/controller-template.yaml | 9 ++++++--- haproxy-ingress/values.yaml | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/haproxy-ingress/README.md b/haproxy-ingress/README.md index 7ef56c4..337b4ee 100755 --- a/haproxy-ingress/README.md +++ b/haproxy-ingress/README.md @@ -108,7 +108,8 @@ Parameter | Description | Default `controller.extraVolumeMounts` | extra volume mounts for the haproxy-ingress-controller | `[]` `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 | `false` +`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/controller-template.yaml b/haproxy-ingress/templates/controller-template.yaml index 5bd9d4a..1902294 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: @@ -8,6 +8,9 @@ metadata: namespace: {{ .Release.Namespace }} data: haproxy.tmpl: | -{{/* .Values.controller.template | indent 4 */}} -{{ .Files.Get "haproxy.tmpl" | indent 4 }} +{{- if .Values.controller.templateFile -}} +{{ .Files.Get .Values.controller.templateFile | indent 4 }} +{{- else }} +{{ .Values.controller.template | indent 4 }} +{{- end }} {{- end }} diff --git a/haproxy-ingress/values.yaml b/haproxy-ingress/values.yaml index 9e5032a..5c68c5b 100644 --- a/haproxy-ingress/values.yaml +++ b/haproxy-ingress/values.yaml @@ -53,8 +53,9 @@ controller: initContainers: [] ## Custom haproxy template - ## if set to true loads haproxy.tmpl into the custom template configmap - template: false + template: "" + ## Path to custom haproxy.tmpl to load into the configmap + templateFile: "" ## A manually deployed default backend service ## Ignored if defaultBackend.enabled = true From c4d4aeb214265af3842bf64e125feb66c2985a42 Mon Sep 17 00:00:00 2001 From: ironashram Date: Wed, 23 Mar 2022 12:17:08 +0100 Subject: [PATCH 5/5] address comments --- haproxy-ingress/README.md | 2 +- haproxy-ingress/templates/_podtemplate.yaml | 10 +++++----- haproxy-ingress/templates/controller-template.yaml | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/haproxy-ingress/README.md b/haproxy-ingress/README.md index 337b4ee..f675921 100755 --- a/haproxy-ingress/README.md +++ b/haproxy-ingress/README.md @@ -109,7 +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.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 1902294..b589b1b 100644 --- a/haproxy-ingress/templates/controller-template.yaml +++ b/haproxy-ingress/templates/controller-template.yaml @@ -8,9 +8,9 @@ metadata: namespace: {{ .Release.Namespace }} data: haproxy.tmpl: | -{{- if .Values.controller.templateFile -}} -{{ .Files.Get .Values.controller.templateFile | indent 4 }} +{{- if .Values.controller.templateFile }} + {{- .Files.Get .Values.controller.templateFile | nindent 4 }} {{- else }} -{{ .Values.controller.template | indent 4 }} + {{- .Values.controller.template | nindent 4 }} {{- end }} {{- end }}