From 14b7b33ef3212226d93fbabcea978dabbd4a3ce5 Mon Sep 17 00:00:00 2001 From: smerle33 Date: Fri, 29 Sep 2023 17:05:33 +0200 Subject: [PATCH 1/2] feat(javadoc): adding PodDisruptionBudget to javadoc --- charts/javadoc/Chart.yaml | 2 +- charts/javadoc/templates/_helpers.tpl | 11 +++++++++-- charts/javadoc/templates/pdb.yaml | 18 ++++++++++++++++++ charts/javadoc/tests/custom_values_test.yaml | 19 +++++++++++++++++++ charts/javadoc/tests/defaults_test.yaml | 9 +++++++++ charts/javadoc/values.yaml | 2 ++ 6 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 charts/javadoc/templates/pdb.yaml create mode 100644 charts/javadoc/tests/custom_values_test.yaml create mode 100644 charts/javadoc/tests/defaults_test.yaml diff --git a/charts/javadoc/Chart.yaml b/charts/javadoc/Chart.yaml index 34451ecb8..4b4432e9a 100644 --- a/charts/javadoc/Chart.yaml +++ b/charts/javadoc/Chart.yaml @@ -4,4 +4,4 @@ description: A Helm chart for javadoc.jenkins.io maintainers: - name: timja name: javadoc -version: 0.3.0 +version: 0.4.0 diff --git a/charts/javadoc/templates/_helpers.tpl b/charts/javadoc/templates/_helpers.tpl index 6e29aea8e..d288c0dc0 100644 --- a/charts/javadoc/templates/_helpers.tpl +++ b/charts/javadoc/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 "javadoc.selectorLabels" -}} +app.kubernetes.io/name: {{ include "javadoc.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + {{/* Common labels */}} {{- define "javadoc.labels" -}} -app.kubernetes.io/name: {{ include "javadoc.name" . }} +{{ include "javadoc.selectorLabels" . }} helm.sh/chart: {{ include "javadoc.chart" . }} -app.kubernetes.io/instance: {{ .Release.Name }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} diff --git a/charts/javadoc/templates/pdb.yaml b/charts/javadoc/templates/pdb.yaml new file mode 100644 index 000000000..30c58ffa2 --- /dev/null +++ b/charts/javadoc/templates/pdb.yaml @@ -0,0 +1,18 @@ +{{- if (gt (int .Values.replicaCount) 1) }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "javadoc.fullname" . }} + labels: + {{- include "javadoc.labels" . | nindent 4 }} +spec: + {{- with .Values.poddisruptionbudget.minAvailable }} + minAvailable: {{ . }} + {{- end }} + {{- with .Values.poddisruptionbudget.maxUnavailable }} + maxUnavailable: {{ . }} + {{- end }} + selector: + matchLabels: + {{- include "javadoc.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/javadoc/tests/custom_values_test.yaml b/charts/javadoc/tests/custom_values_test.yaml new file mode 100644 index 000000000..de2792521 --- /dev/null +++ b/charts/javadoc/tests/custom_values_test.yaml @@ -0,0 +1,19 @@ +suite: Test with custom values +templates: + - pdb.yaml +tests: + - 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: "javadoc" diff --git a/charts/javadoc/tests/defaults_test.yaml b/charts/javadoc/tests/defaults_test.yaml new file mode 100644 index 000000000..8b8f74624 --- /dev/null +++ b/charts/javadoc/tests/defaults_test.yaml @@ -0,0 +1,9 @@ +suite: default tests +templates: + - pdb.yaml +tests: + - it: should not generate any pdb with default values + template: pdb.yaml + asserts: + - hasDocuments: + count: 0 diff --git a/charts/javadoc/values.yaml b/charts/javadoc/values.yaml index bce29968f..3901a5565 100644 --- a/charts/javadoc/values.yaml +++ b/charts/javadoc/values.yaml @@ -53,3 +53,5 @@ htmlVolume: azureStorageAccountName: # key for accessing the azure storage account azureStorageAccountKey: +poddisruptionbudget: + minAvailable: 1 From b0debe7eb0d4a1879d7e755618871aa8db8913d6 Mon Sep 17 00:00:00 2001 From: smerle33 Date: Mon, 2 Oct 2023 15:47:28 +0200 Subject: [PATCH 2/2] add a unittest for selector and cleanup volumes and resources --- charts/javadoc/templates/deployment.yaml | 8 +++++++- charts/javadoc/tests/defaults_test.yaml | 25 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/charts/javadoc/templates/deployment.yaml b/charts/javadoc/templates/deployment.yaml index 93b808a81..4c5adc2fe 100644 --- a/charts/javadoc/templates/deployment.yaml +++ b/charts/javadoc/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 }} @@ -67,7 +69,11 @@ spec: {{- end }} volumes: - name: html + {{- if .Values.htmlVolume }} {{ toYaml .Values.htmlVolume | indent 10 }} + {{- else }} + emptyDir: {} + {{- end }} - name: config configMap: name: javadoc diff --git a/charts/javadoc/tests/defaults_test.yaml b/charts/javadoc/tests/defaults_test.yaml index 8b8f74624..ac5a1ef22 100644 --- a/charts/javadoc/tests/defaults_test.yaml +++ b/charts/javadoc/tests/defaults_test.yaml @@ -1,9 +1,34 @@ suite: default tests templates: - pdb.yaml + - deployment.yaml + - nginx-configmap.yaml tests: - it: should not generate any pdb with default values template: pdb.yaml asserts: - hasDocuments: count: 0 + - it: Should generate a deployment with the default values + template: deployment.yaml + asserts: + - hasDocuments: + count: 1 + - isKind: + of: Deployment + - notExists: + path: spec.affinity + - equal: + path: metadata.labels["app.kubernetes.io/name"] + value: javadoc + - 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