Skip to content

Commit

Permalink
Update templates
Browse files Browse the repository at this point in the history
  • Loading branch information
htquanq committed Sep 21, 2023
1 parent e79b8a5 commit 83a999e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
8 changes: 1 addition & 7 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
{{- end }}
{{- end }}

{{- define "helm-library.common.required" -}}
{{- "No value found for '%s' in the template" -}}
{{- end -}}

{{- define "helm-library.common.labels" -}}
{{- $message := include "helm-library.required" . -}}
app.kubernetes.io/name: {{ required (printf $message "name") .Values.name | quote }}
{{- define "helm-library.common.labels" }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ .Chart.Name }}
Expand Down
37 changes: 24 additions & 13 deletions templates/_ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
{{- $ := .}}
{{- define "helm-library.ingress.template" }}
{{- $required := include "helm-library.common.required" $ }}
apiVersion: networking.k8s.io/v1 {{ include "helm-library.ingress.apiVersion" $ }}
{{- range .Values.ingress }}
{{- $ingressDict := dict }}
---
apiVersion: {{ include "helm-library.ingress.apiVersion" $ }}
kind: Ingress
metadata:
name: {{ required (printf $required "name") .Values.name | quote }}
name: {{ required "No value found for '%s'" .name | quote }}
labels:
{{ include "helm-library.common.labels" | indent 4 }}
{{- include "helm-library.common.labels" $ | indent 4 }}
annotations:
kubernetes.io/ingress.class: {{ .Values.ingress.class | default "nginx" | quote }}
{{ toYaml $.annotations | indent 4 }}
kubernetes.io/ingress.class: {{ .className | default "nginx" | quote }}
{{- if .annotations }}
{{- toYaml .annotations | indent 4 }}
{{- end }}
spec:
ingressClassName: {{ $.className | default "nginx" }}
{{- if $.host }}
ingressClassName: {{ .className | default "nginx" }}
{{- if .host }}
tls:
- hosts:
- {{ $.host }}
secretName: {{ $.name }}-tls
- {{ .host }}
secretName: {{ .name }}-tls
{{- end }}
rules:
{{- if $.host }}
- host: {{ $.host }}
{{- if .host }}
- host: {{ .host }}
http:
{{- else }}
- http:
{{- end }}
paths:
{{ include "helm-library.ingress.builder" $.paths | indent 6 }}

{{- if eq "networking.k8s.io/v1" (include "helm-library.ingress.apiVersion" $) }}
{{- $_ := set $ingressDict "networking" .paths }}
{{- else }}
{{- $_ := set $ingressDict "extension" .paths }}
{{- end }}
{{- include "helm-library.ingress.builder" $ingressDict | indent 6 }}
{{- end }}
{{- end }}
5 changes: 2 additions & 3 deletions templates/_secret.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{{- define "helm-library.secret.template" -}}
{{- $required := include "helm-library.common.required" . -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ required (printf $required "name") .Values.name | quote }}
name: {{ required "No value found for '%s'" .name | quote }}
labels:
{{- include "helm-library.common.labels" . | nindent 4 }}
type: {{ required (printf $required "secret.type") .Values.secret.type | quote }}
type: {{ required "No value found for '%s'" .type | quote }}
data: {}
{{- end }}
{{/* include this */}}
Expand Down

0 comments on commit 83a999e

Please sign in to comment.