From b4d8defaba1d706c7cc4a6402e7b7281ee99f97a Mon Sep 17 00:00:00 2001 From: smerle33 Date: Wed, 4 Oct 2023 14:56:57 +0200 Subject: [PATCH] feat(jenkinsio): add PodDisruptionBudget to jenkinsio and jenkinsio-zh with there unittest --- charts/jenkinsio/Chart.yaml | 2 +- charts/jenkinsio/templates/_helpers.tpl | 22 ++++++++-- charts/jenkinsio/templates/pdb-zh.yaml | 18 ++++++++ charts/jenkinsio/templates/pdb.yaml | 18 ++++++++ .../jenkinsio/tests/custom_values_test.yaml | 44 +++++++++++++++++++ .../jenkinsio/tests/defaults_values_test.yaml | 12 +++++ charts/jenkinsio/values.yaml | 5 +++ 7 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 charts/jenkinsio/templates/pdb-zh.yaml create mode 100644 charts/jenkinsio/templates/pdb.yaml diff --git a/charts/jenkinsio/Chart.yaml b/charts/jenkinsio/Chart.yaml index 07c8591da..b81fbe9d2 100644 --- a/charts/jenkinsio/Chart.yaml +++ b/charts/jenkinsio/Chart.yaml @@ -4,4 +4,4 @@ maintainers: - name: timja - name: dduportal name: jenkinsio -version: 1.0.0 +version: 1.1.0 diff --git a/charts/jenkinsio/templates/_helpers.tpl b/charts/jenkinsio/templates/_helpers.tpl index 732d87412..d77452967 100644 --- a/charts/jenkinsio/templates/_helpers.tpl +++ b/charts/jenkinsio/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 "jenkinsio.selectorLabels" -}} +app.kubernetes.io/name: {{ include "jenkinsio.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + {{/* Common labels */}} {{- define "jenkinsio.labels" -}} -app.kubernetes.io/name: {{ include "jenkinsio.name" . }} +{{ include "jenkinsio.selectorLabels" . }} helm.sh/chart: {{ include "jenkinsio.chart" . }} -app.kubernetes.io/instance: {{ .Release.Name }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} @@ -46,13 +53,20 @@ jenkins.io/maintainer: {{ (index .Chart.Maintainers 0).Name }} {{- end -}} +{{/* +Selector labels +*/}} +{{- define "jenkinsio-zh.selectorLabels" -}} +app.kubernetes.io/name: {{ include "jenkinsio.name" . }}-zh +app.kubernetes.io/instance: {{ .Release.Name }}-zh +{{- end }} + {{/* Common labels */}} {{- define "zh-jenkinsio.labels" -}} -app.kubernetes.io/name: {{ include "jenkinsio.name" . }}-zh +{{ include "jenkinsio-zh.selectorLabels" . }} helm.sh/chart: {{ include "jenkinsio.chart" . }} -app.kubernetes.io/instance: {{ .Release.Name }}-zh {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} diff --git a/charts/jenkinsio/templates/pdb-zh.yaml b/charts/jenkinsio/templates/pdb-zh.yaml new file mode 100644 index 000000000..a40510e00 --- /dev/null +++ b/charts/jenkinsio/templates/pdb-zh.yaml @@ -0,0 +1,18 @@ +{{- if (gt (int .Values.replicaCount) 1) }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "jenkinsio.fullname" . }}-zh + labels: + {{- include "jenkinsio.labels" . | nindent 4 }} +spec: + {{- with .Values.poddisruptionbudget.jenkinsiozh.minAvailable }} + minAvailable: {{ . }} + {{- end }} + {{- with .Values.poddisruptionbudget.jenkinsiozh.maxUnavailable }} + maxUnavailable: {{ . }} + {{- end }} + selector: + matchLabels: + {{- include "jenkinsio-zh.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/jenkinsio/templates/pdb.yaml b/charts/jenkinsio/templates/pdb.yaml new file mode 100644 index 000000000..c6c13401f --- /dev/null +++ b/charts/jenkinsio/templates/pdb.yaml @@ -0,0 +1,18 @@ +{{- if (gt (int .Values.replicaCount) 1) }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "jenkinsio.fullname" . }} + labels: + {{- include "jenkinsio.labels" . | nindent 4 }} +spec: + {{- with .Values.poddisruptionbudget.jenkinsio.minAvailable }} + minAvailable: {{ . }} + {{- end }} + {{- with .Values.poddisruptionbudget.jenkinsio.maxUnavailable }} + maxUnavailable: {{ . }} + {{- end }} + selector: + matchLabels: + {{- include "jenkinsio.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/jenkinsio/tests/custom_values_test.yaml b/charts/jenkinsio/tests/custom_values_test.yaml index d92f71f06..804005882 100644 --- a/charts/jenkinsio/tests/custom_values_test.yaml +++ b/charts/jenkinsio/tests/custom_values_test.yaml @@ -4,6 +4,8 @@ templates: - zh-deployment.yaml - zh-configmap.yaml - nginx-configmap.yaml + - pdb.yaml + - pdb-zh.yaml set: htmlVolume: azureFile: @@ -66,3 +68,45 @@ tests: - equal: path: spec.template.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[0].labelSelector.matchExpressions[0].values[0] value: jenkinsio-zh + - it: should ensure the pdb has correct spec for jenkinsio + template: pdb.yaml + set: + replicaCount: 2 + poddisruptionbudget.jenkinsio.minAvailable: 2 + poddisruptionbudget.jenkinsio.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: "jenkinsio" + - equal: + path: metadata.labels["app.kubernetes.io/name"] + value: jenkinsio + - it: should ensure the pdb has correct spec for jenkinsio-zh + template: pdb-zh.yaml + set: + replicaCount: 2 + poddisruptionbudget.jenkinsiozh.minAvailable: 3 + poddisruptionbudget.jenkinsiozh.maxUnavailable: 4 + asserts: + - isKind: + of: PodDisruptionBudget + - equal: + path: spec.minAvailable + value: 3 + - equal: + path: spec.maxUnavailable + value: 4 + - equal: + path: spec.selector.matchLabels['app.kubernetes.io/name'] + value: "jenkinsio-zh" + - equal: + path: metadata.labels["app.kubernetes.io/name"] + value: jenkinsio diff --git a/charts/jenkinsio/tests/defaults_values_test.yaml b/charts/jenkinsio/tests/defaults_values_test.yaml index 57b51de02..4a1ac9693 100644 --- a/charts/jenkinsio/tests/defaults_values_test.yaml +++ b/charts/jenkinsio/tests/defaults_values_test.yaml @@ -4,6 +4,7 @@ templates: - zh-deployment.yaml - zh-configmap.yaml - nginx-configmap.yaml + - pdb.yaml tests: - it: should create a deployment for jenkins.io with default values template: deployment.yaml @@ -18,6 +19,12 @@ tests: - equal: path: spec.template.spec.volumes[0].name value: html + - equal: + path: metadata.labels["app.kubernetes.io/name"] + value: jenkinsio + - equal: + path: metadata.labels["app.kubernetes.io/managed-by"] + value: Helm - exists: path: spec.template.spec.volumes[0].emptyDir - notExists: @@ -34,3 +41,8 @@ tests: value: RELEASE-NAME-jenkinsio-zh - notExists: path: spec.template.spec.affinity + - it: should not generate any pdb with default values + template: pdb.yaml + asserts: + - hasDocuments: + count: 0 diff --git a/charts/jenkinsio/values.yaml b/charts/jenkinsio/values.yaml index d36d594d9..f8afba719 100644 --- a/charts/jenkinsio/values.yaml +++ b/charts/jenkinsio/values.yaml @@ -54,3 +54,8 @@ affinity: htmlVolume: {} zhHtmlVolume: {} forceJenkinsIoHost: false +poddisruptionbudget: + jenkinsio: + minAvailable: 1 + jenkinsiozh: + minAvailable: 1