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/deployment.yaml b/charts/reports/templates/deployment.yaml index 47a62ac8d..a05b5776a 100644 --- a/charts/reports/templates/deployment.yaml +++ b/charts/reports/templates/deployment.yaml @@ -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 }} @@ -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: 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..fdef7a19a 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: @@ -17,6 +18,8 @@ tests: set: htmlVolume: hostPath: /host + resources: + cpu: 100ms asserts: - hasDocuments: count: 1 @@ -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" diff --git a/charts/reports/tests/defaults_values_test.yaml b/charts/reports/tests/defaults_values_test.yaml index 12d7365c5..37ce4aaf6 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,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 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