Skip to content

Commit

Permalink
Merge pull request #828 from smerle33/PDB/mirrorbits
Browse files Browse the repository at this point in the history
feat(mirrorbits): add PodDisruptionBudget and unittest
  • Loading branch information
dduportal authored Oct 4, 2023
2 parents d73f6d9 + b91c629 commit 00be960
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 1 deletion.
2 changes: 1 addition & 1 deletion charts/mirrorbits/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ maintainers:
- email: jenkins-infra-team@googlegroups.com
name: jenkins-infra-team
name: mirrorbits
version: 1.0.1
version: 1.1.0
16 changes: 16 additions & 0 deletions charts/mirrorbits/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,19 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "mirrorbits.files.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mirrorbits.name" . }}-files
app.kubernetes.io/instance: {{ .Release.Name }}-files
{{- end }}

{{/*
Selector labels
*/}}
{{- define "mirrorbits.rsyncd.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mirrorbits.name" . }}-rsyncd
app.kubernetes.io/instance: {{ .Release.Name }}-rsyncd
{{- end }}
18 changes: 18 additions & 0 deletions charts/mirrorbits/templates/pdb.files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if (gt (int .Values.replicaCount.files) 1) }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "mirrorbits.fullname" . }}-files
labels:
{{- include "mirrorbits.labels" . | nindent 4 }}
spec:
{{- with .Values.poddisruptionbudget.files.minAvailable }}
minAvailable: {{ . }}
{{- end }}
{{- with .Values.poddisruptionbudget.files.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
selector:
matchLabels:
{{- include "mirrorbits.files.selectorLabels" . | nindent 6 }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/mirrorbits/templates/pdb.rsyncd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if (gt (int .Values.replicaCount.rsyncd) 1) }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "mirrorbits.fullname" . }}-rsyncd
labels:
{{- include "mirrorbits.labels" . | nindent 4 }}
spec:
{{- with .Values.poddisruptionbudget.rsyncd.minAvailable }}
minAvailable: {{ . }}
{{- end }}
{{- with .Values.poddisruptionbudget.rsyncd.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
selector:
matchLabels:
{{- include "mirrorbits.rsyncd.selectorLabels" . | nindent 6 }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/mirrorbits/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if (gt (int .Values.replicaCount.mirrorbits) 1) }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "mirrorbits.fullname" . }}
labels:
{{- include "mirrorbits.labels" . | nindent 4 }}
spec:
{{- with .Values.poddisruptionbudget.mirrorbits.minAvailable }}
minAvailable: {{ . }}
{{- end }}
{{- with .Values.poddisruptionbudget.mirrorbits.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
selector:
matchLabels:
{{- include "mirrorbits.selectorLabels" . | nindent 6 }}
{{- end }}
57 changes: 57 additions & 0 deletions charts/mirrorbits/tests/custom_values_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ templates:
- secret.yaml # Direct dependency of deployment(.*).yaml
- service.files.yaml
- service.rsyncd.yaml
- pdb.yaml
- pdb.files.yaml
- pdb.rsyncd.yaml
tests:
- it: Should set the correct service selector labels when a fullNameOverride is specified
template: service.files.yaml
Expand Down Expand Up @@ -167,3 +170,57 @@ tests:
count: 1
- isKind:
of: Service
- it: should ensure the pdb has correct spec
template: pdb.yaml
set:
replicaCount.mirrorbits: 2
poddisruptionbudget.mirrorbits.minAvailable: 2
poddisruptionbudget.mirrorbits.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: "mirrorbits"
- it: should ensure the pdb.files has correct spec
template: pdb.files.yaml
set:
replicaCount.files: 2
poddisruptionbudget.files.minAvailable: 2
poddisruptionbudget.files.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: "mirrorbits-files"
- it: should ensure the pdb.rsyncd has correct spec
template: pdb.rsyncd.yaml
set:
replicaCount.rsyncd: 2
poddisruptionbudget.rsyncd.minAvailable: 2
poddisruptionbudget.rsyncd.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: "mirrorbits-rsyncd"
18 changes: 18 additions & 0 deletions charts/mirrorbits/tests/defaults_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ templates:
- configmap.rsyncd.rsyncd-conf.yaml
- configmap.rsyncd.jenkins-motd.yaml
- service.rsyncd.yaml
- pdb.yaml
- pdb.files.yaml
- pdb.rsyncd.yaml
tests:
- it: should not create any ingress by default
template: ingress.yaml
Expand Down Expand Up @@ -90,3 +93,18 @@ tests:
value: /var/log/mirrorbits
- notExists:
path: spec.template.spec.affinity
- it: should not generate any pdb with default values
template: pdb.yaml
asserts:
- hasDocuments:
count: 0
- it: should not generate any pdb with default values
template: pdb.files.yaml
asserts:
- hasDocuments:
count: 0
- it: should not generate any pdb with default values
template: pdb.rsyncd.yaml
asserts:
- hasDocuments:
count: 0
8 changes: 8 additions & 0 deletions charts/mirrorbits/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,11 @@ rsyncd:
# **Read Only**
#
# Feel free to reach out on https://www.jenkins.io/chat/#jenkins-infra/ with any question you may have

poddisruptionbudget:
mirrorbits:
minAvailable: 1
files:
minAvailable: 1
rsyncd:
minAvailable: 1

0 comments on commit 00be960

Please sign in to comment.