From 75aa57bf24474fd2c574132eb09a75add25702b9 Mon Sep 17 00:00:00 2001 From: Nicolas Haas <116176330+NicolasHaas@users.noreply.github.com> Date: Tue, 9 Dec 2025 15:11:50 +0100 Subject: [PATCH] [common]: add PodDisruptionBudget (PDB) support for components Signed-off-by: Nicolas Haas <116176330+NicolasHaas@users.noreply.github.com> --- charts/common/Chart.yaml | 5 ++-- charts/common/README.md | 8 +++++- charts/common/README.md.gotmpl | 9 ++++++ charts/common/ci/values.test.yaml | 17 ++++++++++++ charts/common/templates/_pdb.yaml | 40 +++++++++++++++++++++++++++ charts/common/templates/includes.yaml | 4 +++ charts/common/values.yaml | 25 +++++++++++++++++ 7 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 charts/common/templates/_pdb.yaml diff --git a/charts/common/Chart.yaml b/charts/common/Chart.yaml index 6431d91..87d1cb2 100644 --- a/charts/common/Chart.yaml +++ b/charts/common/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: common description: "Bedag's common Helm chart to use for creating other Helm charts" -version: 12.6.0 +version: 12.7.0 # A chart can be either an 'application' or a 'library' chart. # # Application charts are a collection of templates that can be packaged into versioned archives @@ -27,5 +27,4 @@ annotations: artifacthub.io/prerelease: "false" artifacthub.io/license: Apache-2.0 artifacthub.io/changes: | - - "[Changed]: extra annotations and labels support sprig statements" - - "[Added]: Possibility to optionally set appVersion in values" + - "[Added]: PodDisruptionBudget (PDB) support for components" diff --git a/charts/common/README.md b/charts/common/README.md index 66606d1..ad38c79 100644 --- a/charts/common/README.md +++ b/charts/common/README.md @@ -1,6 +1,6 @@ # common -![Version: 12.6.0](https://img.shields.io/badge/Version-12.6.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) +![Version: 12.7.0](https://img.shields.io/badge/Version-12.7.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) Bedag's common Helm chart to use for creating other Helm charts @@ -67,3 +67,9 @@ Major Changes to functions are documented with the version affected. **Before up | servicemonitor.basicAuth.userKey | string | `"username"` | userKey is the default key to grab the username in the secret | | servicemonitor.deploy | bool | `false` | deploy has to be set to true for rendering to be applied | | servicemonitor.endpoints | object | `{}` | | + +## PodDisruptionBudget + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| components.component-1.pdbs | object | `{}` | pdbs is a dictionary of Pod Disruption Budgets to be configured for the component | diff --git a/charts/common/README.md.gotmpl b/charts/common/README.md.gotmpl index 42bf92a..8ed6bf5 100644 --- a/charts/common/README.md.gotmpl +++ b/charts/common/README.md.gotmpl @@ -64,3 +64,12 @@ Major Changes to functions are documented with the version affected. **Before up | {{ .Key }} | {{ .Type }} | {{ if .Default }}{{ .Default }}{{ else }}{{ .AutoDefault }}{{ end }} | {{ if .Description }}{{ .Description }}{{ else }}{{ .AutoDescription }}{{ end }} | {{- end }} {{- end }} + +## PodDisruptionBudget + +{{ template "table.heading" . }} +{{- range .Values }} + {{- if and (hasPrefix "components.component-1.pdbs" .Key) }} +| {{ .Key }} | {{ .Type }} | {{ if .Default }}{{ .Default }}{{ else }}{{ .AutoDefault }}{{ end }} | {{ if .Description }}{{ .Description }}{{ else }}{{ .AutoDescription }}{{ end }} | + {{- end }} +{{- end }} diff --git a/charts/common/ci/values.test.yaml b/charts/common/ci/values.test.yaml index 71e698c..bea5a74 100644 --- a/charts/common/ci/values.test.yaml +++ b/charts/common/ci/values.test.yaml @@ -13,6 +13,7 @@ includes: pvcs: true job: true cronjob: true + pdb: true # start common.ingress ingress: @@ -77,6 +78,14 @@ components: kubernetes.io/metadata.name: namespace-1 # end common.networkpolicy + + # start common.pdb + pdbs: + pdb-1: + deploy: true + minAvailable: 1 + # end common.pdb + controller: deploy: true type: "Deployment" @@ -185,6 +194,14 @@ components: ipBlock: cidr: 0.0.0.0/0 # end common.networkpolicy + + # start common.pdb + pdbs: + pdb-1: + deploy: true + maxUnavailable: "50%" + # end common.pdb + controller: deploy: true type: "StatefulSet" diff --git a/charts/common/templates/_pdb.yaml b/charts/common/templates/_pdb.yaml new file mode 100644 index 0000000..9c107ac --- /dev/null +++ b/charts/common/templates/_pdb.yaml @@ -0,0 +1,40 @@ +{{- define "common.pdb" -}} +{{- $root := . }} +{{- range $componentname, $component := .Values.components }} +{{- if $component.pdbs }} +{{- range $pdbname, $pdb := $component.pdbs }} +{{- if $pdb.deploy }} +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ template "library.name" $root }}-{{ $componentname }}-{{ $pdbname }} + labels: +{{ include "library.labels.standard" $root | indent 4 }} + app.kubernetes.io/component: {{ $componentname }} +spec: + {{- if $pdb.minAvailable }} + minAvailable: {{ $pdb.minAvailable }} + {{- end }} + {{- if $pdb.maxUnavailable }} + maxUnavailable: {{ $pdb.maxUnavailable }} + {{- end }} + {{- if $pdb.unhealthyPodEvictionPolicy }} + unhealthyPodEvictionPolicy: {{ $pdb.unhealthyPodEvictionPolicy }} + {{- end }} + selector: + matchLabels: +{{- if not $pdb.overrideSelectors }} + app.kubernetes.io/name: {{ template "library.name" $root }} + app.kubernetes.io/instance: {{ $root.Release.Name }} + app.kubernetes.io/component: {{ $componentname }} +{{- else }} +{{- range $key, $val := $pdb.overrideSelectors }} + {{ $key }}: {{ $val | quote }} +{{- end }} +{{- end }} +{{- end }} +{{- end }} +{{- end }} +{{- end }} +{{- end -}} diff --git a/charts/common/templates/includes.yaml b/charts/common/templates/includes.yaml index c947881..08fa3ec 100644 --- a/charts/common/templates/includes.yaml +++ b/charts/common/templates/includes.yaml @@ -56,3 +56,7 @@ {{- if .Values.includes.networkpolicy }} {{- template "common.networkpolicy" . }} {{- end -}} + +{{- if .Values.includes.pdb }} + {{- template "common.pdb" . }} +{{- end -}} diff --git a/charts/common/values.yaml b/charts/common/values.yaml index 7763600..f3ecc6c 100644 --- a/charts/common/values.yaml +++ b/charts/common/values.yaml @@ -33,6 +33,7 @@ includes: pvcs: false servicemonitor: false networkpolicy: false + pdb: false # timezone to set as environment variable 'TZ' in each pod. Comment out for using default ("Europe/Zurich") # timezone: "Europe/Zurich" @@ -303,6 +304,30 @@ components: # port: 8081 # end common.networkpolicy + # start common.pdb + # -- pdbs is a dictionary of Pod Disruption Budgets to be configured for the component + pdbs: {} + # specify the name of the pdb + # pdb-1: + # -- deploy has to be set to true for rendering to be applied + # deploy: false + # -- minAvailable specifies the minimum number of pods that must be available during a disruption. + # Can be an absolute number (e.g. 1) or a percentage (e.g. "50%"). + # Either minAvailable or maxUnavailable must be set, but not both. + # minAvailable: 1 + # -- maxUnavailable specifies the maximum number of pods that can be unavailable during a disruption. + # Can be an absolute number (e.g. 1) or a percentage (e.g. "50%"). + # Either minAvailable or maxUnavailable must be set, but not both. + # maxUnavailable: 1 + # -- unhealthyPodEvictionPolicy defines the criteria for when unhealthy pods should be considered for eviction. + # Valid values are "IfHealthyBudget" and "AlwaysAllow". Default behavior if not set depends on the Kubernetes version. + # unhealthyPodEvictionPolicy: "IfHealthyBudget" + # -- overrideSelectors is optional for overriding the default labels: 'app.kubernetes.io/name', 'app.kubernetes.io/instance' & 'app.kubernetes.io/component' + # overrideSelectors: + # label1: "value1" + # label2: "value2" + # end common.pdb + # controller is used for deploying pods via Deployment, StatefulSet, Job or CronJob ressources controller: # deploy has to be set to true for rendering to be applied