Skip to content

Commit

Permalink
Merge pull request #827 from smerle33/PDB/jenkinsio
Browse files Browse the repository at this point in the history
feat(jenkinsio): add PodDisruptionBudget to jenkinsio and jenkinsio-zh with there unittest
  • Loading branch information
dduportal authored Oct 4, 2023
2 parents a1ef62a + b4d8def commit d73f6d9
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 5 deletions.
2 changes: 1 addition & 1 deletion charts/jenkinsio/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ maintainers:
- name: timja
- name: dduportal
name: jenkinsio
version: 1.0.0
version: 1.1.0
22 changes: 18 additions & 4 deletions charts/jenkinsio/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down
18 changes: 18 additions & 0 deletions charts/jenkinsio/templates/pdb-zh.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
18 changes: 18 additions & 0 deletions charts/jenkinsio/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
44 changes: 44 additions & 0 deletions charts/jenkinsio/tests/custom_values_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ templates:
- zh-deployment.yaml
- zh-configmap.yaml
- nginx-configmap.yaml
- pdb.yaml
- pdb-zh.yaml
set:
htmlVolume:
azureFile:
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions charts/jenkinsio/tests/defaults_values_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
5 changes: 5 additions & 0 deletions charts/jenkinsio/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ affinity:
htmlVolume: {}
zhHtmlVolume: {}
forceJenkinsIoHost: false
poddisruptionbudget:
jenkinsio:
minAvailable: 1
jenkinsiozh:
minAvailable: 1

0 comments on commit d73f6d9

Please sign in to comment.