Skip to content

Commit

Permalink
feat(reports): add PodDisruptionBudget and unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
smerle33 committed Oct 3, 2023
1 parent 121b052 commit 7a8422e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
2 changes: 1 addition & 1 deletion charts/reports/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ description: A Helm chart for reports.jenkins.io
maintainers:
- name: timja
name: reports
version: 0.3.1
version: 0.4.0
11 changes: 9 additions & 2 deletions charts/reports/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 "reports.selectorLabels" -}}
app.kubernetes.io/name: {{ include "reports.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "reports.labels" -}}
app.kubernetes.io/name: {{ include "reports.name" . }}
{{ include "reports.selectorLabels" . }}
helm.sh/chart: {{ include "reports.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand Down
8 changes: 6 additions & 2 deletions charts/reports/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ spec:
mountPath: /usr/share/nginx/html
- name: config
mountPath: /etc/nginx/conf.d
{{- with .Values.resources }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- end}}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand All @@ -66,9 +68,11 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{- with .Values.htmlVolume }}
- name: html
{{- toYaml . | nindent 10 }}
{{- if .Values.htmlVolume }}
{{ toYaml .Values.htmlVolume | indent 10 }}
{{- else }}
emptyDir: {}
{{- end }}
- name: config
configMap:
Expand Down
18 changes: 18 additions & 0 deletions charts/reports/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 "reports.fullname" . }}
labels:
{{- include "reports.labels" . | nindent 4 }}
spec:
{{- with .Values.poddisruptionbudget.minAvailable }}
minAvailable: {{ . }}
{{- end }}
{{- with .Values.poddisruptionbudget.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
selector:
matchLabels:
{{- include "reports.selectorLabels" . | nindent 6 }}
{{- end }}
16 changes: 16 additions & 0 deletions charts/reports/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
- nginx-configmap.yaml # Direct dependency of deployment.yaml
- pdb.yaml
tests:
- it: should create an ingress when ingress.enabled is true
set:
Expand All @@ -28,3 +29,18 @@ tests:
- equal:
path: spec.template.spec.volumes[0].hostPath
value: /host
- 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: "reports"
20 changes: 20 additions & 0 deletions charts/reports/tests/defaults_values_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ templates:
- deployment.yaml
- ingress.yaml
- nginx-configmap.yaml # Direct dependency of deployment.yaml
- pdb.yaml
tests:
- it: should not create an ingress by default
template: ingress.yaml
Expand All @@ -19,3 +20,22 @@ tests:
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
value: IfNotPresent
- equal:
path: metadata.labels["app.kubernetes.io/name"]
value: reports
- equal:
path: metadata.labels["app.kubernetes.io/managed-by"]
value: Helm
- equal:
path: spec.template.spec.volumes[0].name
value: html
- equal:
path: spec.template.spec.volumes[0].emptyDir
value: {}
- 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/reports/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ htmlVolume:
azureStorageAccountName:
# key for accessing the azure storage account
azureStorageAccountKey:
poddisruptionbudget:
minAvailable: 1

0 comments on commit 7a8422e

Please sign in to comment.