Skip to content

Commit

Permalink
feat(account-app): adding a PodDisruptionBudget
Browse files Browse the repository at this point in the history
  • Loading branch information
smerle33 committed Sep 28, 2023
1 parent 6a647c8 commit a72a24d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions charts/accountapp/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
jenkins.io/maintainer: {{ (index .Chart.Maintainers 0).Name }}
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "accountapp.selectorLabels" -}}
app.kubernetes.io/name: {{ include "accountapp.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/accountapp/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if (gt (int .Values.replicaCount) 1) }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "accountapp.fullname" . }}
labels:
{{- include "accountapp.labels" . | nindent 4 }}
spec:
{{- with .Values.poddisruptionbudget.minAvailable }}
minAvailable: {{ . }}
{{- end }}
{{- with .Values.poddisruptionbudget.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
selector:
matchLabels:
{{- include "accountapp.selectorLabels" . | nindent 6 }}
{{- end }}
16 changes: 16 additions & 0 deletions charts/accountapp/tests/custom_values_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ templates:
- deployment.yaml
- ingress.yaml
- secret.yaml # Direct dependency of deployment.yaml
- pdb.yaml
tests:
- it: should create a Secret with the correct value
set:
Expand Down Expand Up @@ -51,3 +52,18 @@ tests:
- equal:
path: spec.template.spec.containers[0].resources.requests.cpu
value: 500m
- it: should ensure the pdb has correct spec
template: pdb.yaml
set:
replicaCount: 2
poddisruptionbudget.minAvailable: 2
poddisruptionbudget.maxUnavailable: 1
asserts:
- isKind:
of: PodDisruptionBudget
- equal:
path: spec.minAvailable
value: 2
- equal:
path: spec.selector.matchLabels['app.kubernetes.io/name']
value: "accountapp"
6 changes: 6 additions & 0 deletions charts/accountapp/tests/defaults_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ templates:
- deployment.yaml
- ingress.yaml
- secret.yaml # Direct dependency of deployment.yaml
- pdb.yaml
tests:
- it: should create an ingress by default
template: ingress.yaml
Expand All @@ -21,3 +22,8 @@ tests:
value: IfNotPresent
- notExists:
path: spec.template.spec.containers[0].resources
- it: should not generate any pdb with default values
template: pdb.yaml
asserts:
- hasDocuments:
count: 0
2 changes: 2 additions & 0 deletions charts/accountapp/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ election:
close: 1970-01-02
logDir: /var/log/accountapp/elections
candidates: bob,alice
poddisruptionbudget:
minAvailable: 1

0 comments on commit a72a24d

Please sign in to comment.