From 80842150c0471b99d0a9edbcab51109d08c496a7 Mon Sep 17 00:00:00 2001 From: Akash Shrivastava Date: Fri, 6 Sep 2024 20:51:43 +0530 Subject: [PATCH] feat: [PL-56708]: adding PDB function (#123) Signed-off-by: Akash Shrivastava --- src/common/Chart.yaml | 2 +- src/common/templates/_pdb.tpl | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/common/templates/_pdb.tpl diff --git a/src/common/Chart.yaml b/src/common/Chart.yaml index c7865aa..874529e 100644 --- a/src/common/Chart.yaml +++ b/src/common/Chart.yaml @@ -15,7 +15,7 @@ type: library # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.3.54 +version: 1.3.55 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/src/common/templates/_pdb.tpl b/src/common/templates/_pdb.tpl new file mode 100644 index 0000000..e1b0a1a --- /dev/null +++ b/src/common/templates/_pdb.tpl @@ -0,0 +1,47 @@ +{{/* +Create Pod Distribution Budget Configurations +Usage example: +{{- include "harnesscommon.pdb.renderPodDistributionBudget" . }} +*/}} +{{- define "harnesscommon.pdb.renderPodDistributionBudget" -}} +{{- $ := .ctx }} +{{- if or $.Values.global.pdb.create $.Values.pdb.create }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ default $.Chart.Name $.Values.nameOverride | trunc 63 | trimSuffix "-" }} + namespace: {{ $.Release.Namespace }} + {{- if $.Values.global.commonLabels }} + labels: {{- include "harnesscommon.tplvalues.render" ( dict "value" .Values.global.commonLabels "context" $ ) | nindent 4 }} + {{- end }} + {{- if $.Values.global.commonAnnotations }} + annotations: {{- include "harnesscommon.tplvalues.render" ( dict "value" .Values.global.commonAnnotations "context" $ ) | nindent 4 }} + {{- end }} +spec: + {{- $minAvailable := "50%" }} + {{- $maxUnavailable := "" }} + + {{- if $.Values.global.pdb.minAvailable }} + {{- $minAvailable = $.Values.global.pdb.minAvailable }} + {{- end }} + {{- if $.Values.pdb.minAvailable }} + {{- $minAvailable = $.Values.pdb.minAvailable }} + {{- end }} + {{- if $.Values.global.pdb.maxUnavailable }} + {{- $maxUnavailable = $.Values.global.pdb.maxUnavailable }} + {{- end }} + {{- if $.Values.pdb.maxUnavailable }} + {{- $maxUnavailable = $.Values.pdb.maxUnavailable }} + {{- end }} + + {{- if $minAvailable }} + minAvailable: {{ $minAvailable }} + {{- end }} + {{- if $maxUnavailable }} + maxUnavailable: {{ $maxUnavailable }} + {{- end }} + {{- $selectorFunction := printf "%s.selectorLabels" $.Chart.Name }} + selector: + matchLabels: {{ include $selectorFunction $ | nindent 6 }} +{{- end }} +{{- end }}