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/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/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..ac5a1ef22 --- /dev/null +++ b/charts/javadoc/tests/defaults_test.yaml @@ -0,0 +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 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