diff --git a/charts/reports/Chart.yaml b/charts/reports/Chart.yaml index 7465c6f71..e164fd1d0 100644 --- a/charts/reports/Chart.yaml +++ b/charts/reports/Chart.yaml @@ -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 diff --git a/charts/reports/templates/_helpers.tpl b/charts/reports/templates/_helpers.tpl index 3f5415d72..6c4c35f5d 100644 --- a/charts/reports/templates/_helpers.tpl +++ b/charts/reports/templates/_helpers.tpl @@ -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 }} diff --git a/charts/reports/templates/pdb.yaml b/charts/reports/templates/pdb.yaml new file mode 100644 index 000000000..75c1a6cc1 --- /dev/null +++ b/charts/reports/templates/pdb.yaml @@ -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 }} diff --git a/charts/reports/tests/custom_values_test.yaml b/charts/reports/tests/custom_values_test.yaml index 85f672b4b..a924a5829 100644 --- a/charts/reports/tests/custom_values_test.yaml +++ b/charts/reports/tests/custom_values_test.yaml @@ -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: @@ -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" diff --git a/charts/reports/tests/defaults_values_test.yaml b/charts/reports/tests/defaults_values_test.yaml index 12d7365c5..afd61ebaa 100644 --- a/charts/reports/tests/defaults_values_test.yaml +++ b/charts/reports/tests/defaults_values_test.yaml @@ -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 @@ -19,3 +20,8 @@ tests: - equal: path: spec.template.spec.containers[0].imagePullPolicy value: IfNotPresent + - it: should not generate any pdb with default values + template: pdb.yaml + asserts: + - hasDocuments: + count: 0 diff --git a/charts/reports/values.yaml b/charts/reports/values.yaml index 0ef02c044..b895be226 100644 --- a/charts/reports/values.yaml +++ b/charts/reports/values.yaml @@ -53,3 +53,5 @@ htmlVolume: azureStorageAccountName: # key for accessing the azure storage account azureStorageAccountKey: +poddisruptionbudget: + minAvailable: 1