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(reports): add PodDisruptionBudget and unittests #820

Merged
merged 3 commits into from
Oct 4, 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/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" . }}
smerle33 marked this conversation as resolved.
Show resolved Hide resolved
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
10 changes: 7 additions & 3 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 }}
{{- toYaml . | 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 }}
37 changes: 37 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 @@ -17,6 +18,8 @@ tests:
set:
htmlVolume:
hostPath: /host
resources:
cpu: 100ms
asserts:
- hasDocuments:
count: 1
Expand All @@ -28,3 +31,37 @@ tests:
- equal:
path: spec.template.spec.volumes[0].hostPath
value: /host
- equal:
path: spec.template.spec.containers[0].resources.cpu
value: 100ms
- it: should create a PDB with defaults when multiple replicas are set
template: pdb.yaml
set:
replicaCount: 2
asserts:
- isKind:
of: PodDisruptionBudget
- equal:
path: spec.minAvailable
value: 1
- equal:
path: spec.selector.matchLabels['app.kubernetes.io/name']
value: "reports"
- it: should ensure the pdb has correct spec
template: pdb.yaml
set:
replicaCount: 2
poddisruptionbudget.minAvailable: 2
poddisruptionbudget.maxUnavailable: 3
asserts:
- isKind:
of: PodDisruptionBudget
- equal:
path: spec.minAvailable
value: 2
- equal:
path: spec.maxUnavailable
value: 3
- 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