Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(account-app): adding a PodDisruptionBudget #806

Merged
merged 4 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/accountapp/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ description: A Helm chart for accounts.jenkins.io
maintainers:
- name: timja
name: accountapp
version: 0.7.3
version: 0.8.0
11 changes: 9 additions & 2 deletions charts/accountapp/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ Create chart name and version as used by the chart label.
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "accountapp.selectorLabels" -}}
app.kubernetes.io/name: {{ include "accountapp.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "accountapp.labels" -}}
app.kubernetes.io/name: {{ include "accountapp.name" . }}
{{ include "accountapp.selectorLabels" . }}
helm.sh/chart: {{ include "accountapp.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand Down
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"
12 changes: 12 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,14 @@ tests:
value: IfNotPresent
- notExists:
path: spec.template.spec.containers[0].resources
- equal:
path: metadata.labels["app.kubernetes.io/name"]
value: accountapp
- equal:
path: metadata.labels["app.kubernetes.io/managed-by"]
value: Helm
- 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