Skip to content

Commit

Permalink
Merge pull request #837 from dduportal/feat/mirrorbits-lite/pdb
Browse files Browse the repository at this point in the history
feat(mirrorbits-lite) create a PDB when application is replicated
  • Loading branch information
dduportal authored Oct 6, 2023
2 parents 0a275de + c97444c commit fe46b67
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/mirrorbits-lite/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
description: Mirrobits lite helm chart for Kubernetes
name: mirrorbits-lite
version: 0.3.1
version: 0.4.0
appVersion: "v0.5.1"
maintainers:
- email: [email protected]
Expand Down
11 changes: 9 additions & 2 deletions charts/mirrorbits-lite/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 "mirrorbits-lite.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mirrorbits-lite.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "mirrorbits-lite.labels" -}}
app.kubernetes.io/name: {{ include "mirrorbits-lite.name" . }}
{{ include "mirrorbits-lite.selectorLabels" . }}
helm.sh/chart: {{ include "mirrorbits-lite.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand Down
18 changes: 18 additions & 0 deletions charts/mirrorbits-lite/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 "mirrorbits-lite.fullname" . }}
labels:
{{- include "mirrorbits-lite.labels" . | nindent 4 }}
spec:
{{- with .Values.poddisruptionbudget.minAvailable }}
minAvailable: {{ . }}
{{- end }}
{{- with .Values.poddisruptionbudget.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
selector:
matchLabels:
{{- include "mirrorbits-lite.selectorLabels" . | nindent 6 }}
{{- end }}
38 changes: 38 additions & 0 deletions charts/mirrorbits-lite/tests/custom_values_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ templates:
- ingress.yaml
- secret.yaml # Direct dependency of deployment.yaml
- service.yaml
- pdb.yaml
- persistentVolume.yaml
- persistentVolumeClaim.yaml
set:
replicaCount: 2
image:
pullPolicy: Always
geoipupdate:
Expand Down Expand Up @@ -82,6 +84,9 @@ tests:
- equal:
path: spec.template.spec.containers[*].imagePullPolicy
value: Always
- equal:
path: spec.replicas
value: 2
# Log volumes is a custom PVC
- equal:
path: spec.template.spec.volumes[2].name
Expand Down Expand Up @@ -132,3 +137,36 @@ tests:
count: 1
- isKind:
of: PersistentVolumeClaim
- it: create a default pdb when replicated
template: pdb.yaml
asserts:
- hasDocuments:
count: 1
- isKind:
of: PodDisruptionBudget
- equal:
path: spec.minAvailable
value: 1
- equal:
path: spec.selector.matchLabels['app.kubernetes.io/name']
value: mirrorbits-lite
- it: create a customized pdb when custom values are set
template: pdb.yaml
set:
poddisruptionbudget:
minAvailable: 2
maxUnavailable: 3
asserts:
- hasDocuments:
count: 1
- 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-lite
9 changes: 9 additions & 0 deletions charts/mirrorbits-lite/tests/defaults_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ templates:
- ingress.yaml
- secret.yaml # Direct dependency of deployment(.*).yaml
- service.yaml
- pdb.yaml
- persistentVolume.yaml
- persistentVolumeClaim.yaml
tests:
Expand All @@ -28,6 +29,9 @@ tests:
- equal:
path: "spec.template.spec.containers[*].imagePullPolicy"
value: IfNotPresent
- equal:
path: spec.replicas
value: 1
# Log volumes is an emptydir by default
- equal:
path: spec.template.spec.volumes[2].name
Expand Down Expand Up @@ -64,3 +68,8 @@ tests:
asserts:
- hasDocuments:
count: 0
- it: should not generate any pdb with default values
template: pdb.yaml
asserts:
- hasDocuments:
count: 0
3 changes: 3 additions & 0 deletions charts/mirrorbits-lite/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ repository:
enabled: false
# data hold secrets data used by persistentVolume
data: {}

poddisruptionbudget:
minAvailable: 1

0 comments on commit fe46b67

Please sign in to comment.