mirror of
https://github.com/truecharts/library-charts.git
synced 2026-07-03 07:29:21 -03:00
feat: implement poddisruptionbudget object creation (#490)
**Description** poddisruptionbudget objects are rather easy to implement and offer another unique sellingpoint by being standardised. **⚙️ Type of change** - [x] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** <!-- Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration --> **📃 Notes:** <!-- Please enter any other relevant information here --> **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [ ] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🪞 I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Co-authored-by: Stavros kois <s.kois@outlook.com>
This commit is contained in:
@@ -3,7 +3,7 @@ appVersion: ""
|
||||
dependencies:
|
||||
- name: common
|
||||
repository: file://../common
|
||||
version: ~13.0.0
|
||||
version: ~13.1.0
|
||||
deprecated: false
|
||||
description: Helper chart to test different use cases of the common library
|
||||
home: https://github.com/truecharts/apps/tree/master/charts/library/common-test
|
||||
|
||||
@@ -15,4 +15,4 @@ maintainers:
|
||||
name: common
|
||||
sources: null
|
||||
type: library
|
||||
version: 13.0.1
|
||||
version: 13.1.0
|
||||
|
||||
54
library/common/templates/class/_podDisruptionBudget.tpl
Normal file
54
library/common/templates/class/_podDisruptionBudget.tpl
Normal file
@@ -0,0 +1,54 @@
|
||||
{{/* poddisruptionbudget Class */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.class.podDisruptionBudget" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
|
||||
rootCtx: The root context of the chart.
|
||||
objectData:
|
||||
name: The name of the podDisruptionBudget.
|
||||
labels: The labels of the podDisruptionBudget.
|
||||
annotations: The annotations of the podDisruptionBudget.
|
||||
data: The data of the podDisruptionBudget.
|
||||
namespace: The namespace of the podDisruptionBudget. (Optional)
|
||||
*/}}
|
||||
|
||||
{{- define "tc.v1.common.class.podDisruptionBudget" -}}
|
||||
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData }}
|
||||
---
|
||||
apiVersion: policy/v1
|
||||
kind: PodDisruptionBudget
|
||||
metadata:
|
||||
name: {{ $objectData.name }}
|
||||
namespace: {{ include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "Pod Disruption Budget") }}
|
||||
{{- $labels := (mustMerge ($objectData.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}}
|
||||
{{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }}
|
||||
labels:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end -}}
|
||||
{{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "tc.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
|
||||
{{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }}
|
||||
annotations:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end -}}
|
||||
data:
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- if $objectData.customLabels -}}
|
||||
{{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $objectData.customLabels) | trim) }}
|
||||
{{- . | nindent 6 }}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- $selectedPod := fromJson (include "tc.v1.common.lib.helpers.getSelectedPodValues" (dict "rootCtx" $rootCtx "objectData" $objectData)) }}
|
||||
{{- include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $ "objectType" "pod" "objectName" $selectedPod.shortName) | nindent 6 }}
|
||||
{{- end -}}
|
||||
{{- if hasKey "minAvailable" $objectData }}
|
||||
minAvailable: {{ $objectData.minAvailable }}
|
||||
{{- end -}}
|
||||
{{- if hasKey "maxUnavailable" $objectData }}
|
||||
maxUnavailable: {{ $objectData.maxUnavailable }}
|
||||
{{- end -}}
|
||||
{{- with $objectData.unhealthyPodEvictionPolicy }}
|
||||
unhealthyPodEvictionPolicy: {{ . }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,30 @@
|
||||
{{/* Metadata Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.podDisruptionBudget.validation" (dict "objectData" $objectData "caller" $caller) -}}
|
||||
objectData:
|
||||
labels: The labels of the configmap.
|
||||
annotations: The annotations of the configmap.
|
||||
data: The data of the configmap.
|
||||
*/}}
|
||||
|
||||
{{- define "tc.v1.common.lib.podDisruptionBudget.validation" -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
{{- $caller := .caller -}}
|
||||
|
||||
{{- with $objectData.unhealthyPodEvictionPolicy -}}
|
||||
{{- $policies := (list "IfHealthyBudget" "AlwaysAllow") -}}
|
||||
{{- if not (mustHas . $policies) -}}
|
||||
{{- fail (printf "Pod Disruption Budget - Expected <unhealthyPodEvictionPolicy> to be one of [%s], but got [%s]" (join ", " $policies) .) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $keys := (list "minAvailable" "maxUnavailable") -}}
|
||||
{{- range $key := $keys -}}
|
||||
{{- if hasKey $key $objectData -}}
|
||||
{{- if kindIs "invalid" (get $objectData $key) -}}
|
||||
{{- fail (printf "Pod Disruption Budget - Expected the defined key [%v] in <podDisruptionBudget.%s> to not be empty" $key $key) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
@@ -52,6 +52,9 @@
|
||||
{{/* Render Networkpolicy(s) */}}
|
||||
{{- include "tc.v1.common.spawner.networkpolicy" . | nindent 0 -}}
|
||||
|
||||
{{/* Render podDisruptionBudget(s) */}}
|
||||
{{- include "tc.v1.common.spawner.podDisruptionBudget" . | nindent 0 -}}
|
||||
|
||||
{{/* Render Prometheus Metrics(s) */}}
|
||||
{{- include "tc.v1.common.spawner.metrics" . | nindent 0 -}}
|
||||
|
||||
|
||||
58
library/common/templates/spawner/_podDisruptionBudget.tpl
Normal file
58
library/common/templates/spawner/_podDisruptionBudget.tpl
Normal file
@@ -0,0 +1,58 @@
|
||||
{{/* poddisruptionbudget Spawwner */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.spawner.podDisruptionBudget" $ -}}
|
||||
*/}}
|
||||
|
||||
{{- define "tc.v1.common.spawner.podDisruptionBudget" -}}
|
||||
|
||||
{{- range $name, $poddisruptionbudget := .Values.podDisruptionBudget -}}
|
||||
|
||||
{{- $enabled := false -}}
|
||||
{{- if hasKey $poddisruptionbudget "enabled" -}}
|
||||
{{- if not (kindIs "invalid" $poddisruptionbudget.enabled) -}}
|
||||
{{- $enabled = $poddisruptionbudget.enabled -}}
|
||||
{{- else -}}
|
||||
{{- fail (printf "Pod Disruption Budget - Expected the defined key [enabled] in <podDisruptionBudget.%s> to not be empty" $name) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if kindIs "string" $enabled -}}
|
||||
{{- $enabled = tpl $enabled $ -}}
|
||||
|
||||
{{/* After tpl it becomes a string, not a bool */}}
|
||||
{{- if eq $enabled "true" -}}
|
||||
{{- $enabled = true -}}
|
||||
{{- else if eq $enabled "false" -}}
|
||||
{{- $enabled = false -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $enabled -}}
|
||||
|
||||
{{/* Create a copy of the poddisruptionbudget */}}
|
||||
{{- $objectData := (mustDeepCopy $poddisruptionbudget) -}}
|
||||
|
||||
{{- $objectName := (printf "%s-%s" (include "tc.v1.common.lib.chart.names.fullname" $) $name) -}}
|
||||
{{- if hasKey $objectData "expandObjectName" -}}
|
||||
{{- if not $objectData.expandObjectName -}}
|
||||
{{- $objectName = $name -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Perform validations */}}
|
||||
{{- include "tc.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}}
|
||||
{{- include "tc.v1.common.lib.podDisruptionBudget.validation" (dict "objectData" $objectData) -}}
|
||||
{{- include "tc.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Pod Distruption Budget") -}}
|
||||
|
||||
{{/* Set the name of the poddisruptionbudget */}}
|
||||
{{- $_ := set $objectData "name" $objectName -}}
|
||||
{{- $_ := set $objectData "shortName" $name -}}
|
||||
|
||||
{{/* Call class to create the object */}}
|
||||
{{- include "tc.v1.common.class.podDisruptionBudget" (dict "rootCtx" $ "objectData" $objectData) -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
@@ -524,6 +524,16 @@ route:
|
||||
type: PathPrefix
|
||||
value: /
|
||||
|
||||
podDisruptionBudget:
|
||||
main:
|
||||
enabled: false
|
||||
# -- Custom Selector Labels
|
||||
# customLabels:
|
||||
# customKey: customValue
|
||||
targetSelector: main
|
||||
minAvailable: 1
|
||||
maxUnavailable: 1
|
||||
|
||||
metrics:
|
||||
main:
|
||||
enabled: false
|
||||
|
||||
Reference in New Issue
Block a user