From 950eb5718653920b965ac0731e1d5c08e0708e31 Mon Sep 17 00:00:00 2001 From: Chi-En Wu Date: Wed, 15 Apr 2020 17:07:34 +0800 Subject: [PATCH] feat: add template `common.pdb` --- templates/_pdb.yaml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 templates/_pdb.yaml diff --git a/templates/_pdb.yaml b/templates/_pdb.yaml new file mode 100644 index 0000000..5e6382a --- /dev/null +++ b/templates/_pdb.yaml @@ -0,0 +1,34 @@ +{{/* vim: set filetype=mustache: */}} + +{{- define "common.pdb.tpl" -}} +apiVersion: policy/v1beta1 +kind: PodDisruptionBudget +{{ include "common.metadata" . }} +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" }} + {{- end -}} + {{- with .minAvailable }} + minAvailable: {{ . }} + {{- end }} + {{- with .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" .) -}} +{{- end -}}