Skip to content

Commit

Permalink
improve custom template handling (#48)
Browse files Browse the repository at this point in the history
Add a new `templateFile` option that references a file instead of copy/pasting the template into the values chart.
  • Loading branch information
ironashram authored Mar 23, 2022
1 parent 79133f5 commit fc1271d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions haproxy-ingress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
10 changes: 5 additions & 5 deletions haproxy-ingress/templates/_podtemplate.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 7 additions & 4 deletions haproxy-ingress/templates/controller-template.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.controller.template -}}
{{- if or .Values.controller.template .Values.controller.templateFile -}}
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -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 }}
4 changes: 3 additions & 1 deletion haproxy-ingress/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc1271d

Please sign in to comment.