feat: allow arguments to be passed to templates

This commit is contained in:
Chi-En Wu
2020-04-22 10:26:17 +08:00
parent bddaab6942
commit 9aecdacf39
15 changed files with 137 additions and 143 deletions

View File

@ -1,35 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{- define "common.pdb.tpl" -}}
{{- $top := first . -}}
{{- $pdb := index . 1 -}}
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
{{ include "common.metadata" . | nindent 2 }}
{{ include "common.metadata" (list $top) | nindent 2 }}
spec:
selector:
matchLabels:
{{- include "common.selectorLabels" . | nindent 6 }}
{{- with .Values.podDisruptionBudget }}
{{- if not (or (empty .minAvailable) (empty .maxUnavailable)) -}}
{{- fail "podDisruptionBudget.minAvailable and podDisruptionBudget.maxUnavailable can not be set together" }}
{{- include "common.selectorLabels" $top | nindent 6 }}
{{- if not (or (empty $pdb.minAvailable) (empty $pdb.maxUnavailable)) -}}
{{- fail "minAvailable and maxUnavailable can not be set together" }}
{{- end -}}
{{- with .minAvailable }}
{{- with $pdb.minAvailable }}
minAvailable: {{ . }}
{{- end }}
{{- with .maxUnavailable }}
{{- with $pdb.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
{{- end }}
{{- end -}}
{{- define "common.pdb.if" -}}
{{- $top := first . -}}
{{- $autoscaling := $top.Values.autoscaling | default (dict) -}}
{{- if or (and $autoscaling.enabled (gt ($autoscaling.minReplicas | int) 1)) (gt ($top.Values.replicaCount | int) 1) }}
{{- include "common.utils.merge" (append . "common.pdb.tpl") -}}
{{- end -}}
{{- end -}}
{{- define "common.pdb" -}}
{{- include "common.utils.flattenCall" (list "common.pdb.if" .) -}}
{{- $top := first . -}}
{{- $pod := index . 2 -}}
{{- $autoscaling := index . 3 -}}
{{- if or (and $autoscaling.enabled (gt ($autoscaling.minReplicas | int) 1)) (gt ($pod.replicaCount | int) 1) }}
{{- include "common.utils.merge" (append . "common.pdb.tpl") -}}
{{- end -}}
{{- end -}}