Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve custom template handling #48

Merged
merged 5 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 -}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing this same logic in the _podtemplate.yaml, look for controller.template

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, added

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 }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these trimleft configs broke the yaml parser, here is a config suggestion that worked for me:

  haproxy.tmpl: |
{{- if .Values.controller.templateFile }}
    {{- .Files.Get .Values.controller.templateFile | nindent 4 }}
{{- else }}
    {{- .Values.controller.template | nindent 4 }}
{{- end }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

{{- 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