Skip to content

Commit

Permalink
feat(mirrorbits-lite) allow overriding ingress and PV(C)s based on gl…
Browse files Browse the repository at this point in the history
…obal value from parent chart

chore(mirrorbits-lite) increase unit test coverage to PV and PVC with their volumeMounts

Signed-off-by: Damien Duportal <[email protected]>
  • Loading branch information
dduportal committed Oct 1, 2023
1 parent a2dc819 commit 9b112a8
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 25 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.2.1
version: 0.3.0
appVersion: "v0.5.1"
maintainers:
- email: [email protected]
Expand Down
4 changes: 4 additions & 0 deletions charts/mirrorbits-lite/charts/mocks/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
description: Mock Parent Chart Helpers
name: mock
version: 0.0.1
6 changes: 6 additions & 0 deletions charts/mirrorbits-lite/charts/mocks/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{/*
Mock parent chart helper template
*/}}
{{- define "parent.data-volume" -}}
parent-chart-shared-data
{{- end -}}
18 changes: 18 additions & 0 deletions charts/mirrorbits-lite/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,21 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Data directory volume definition. Might be defined from parent chart templates or autonomously
based on the presence of the global value provided by the parent chart.
*/}}
{{- define "mirrorbits-lite.data-volume" -}}
{{- if (dig "global" "storage" "enabled" false .Values.AsMap) }}
persistentVolumeClaim:
claimName: {{ include "parent.data-volume" . }}
{{- else }}
{{- if .Values.repository.persistentVolumeClaim.enabled }}
persistentVolumeClaim:
claimName: {{ .Values.repository.name | default (printf "%s-binary" (include "mirrorbits-lite.fullname" .)) }}
{{- else }}
emptyDir: {}
{{- end -}}
{{- end -}}
{{- end -}}
11 changes: 3 additions & 8 deletions charts/mirrorbits-lite/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ spec:
mountPath: /usr/share/GeoIP
- name: logs
mountPath: /var/log/mirrorbits
{{ if $.Values.repository.persistentVolumeClaim.enabled -}}
- name: binary
- name: data
mountPath: /srv/repo
{{- end }}
livenessProbe:
httpGet:
path: /?mirrorstats
Expand Down Expand Up @@ -114,8 +112,5 @@ spec:
emptyDir: {}
- name: logs
{{- toYaml .Values.logs.volume | nindent 10 }}
{{- if $.Values.repository.persistentVolumeClaim.enabled }}
- name: binary
persistentVolumeClaim:
claimName: {{ .Values.repository.name | default (printf "%s-binary" (include "mirrorbits-lite.fullname" .)) }}
{{- end }}
- name: data
{{- include "mirrorbits-lite.data-volume" . | nindent 10}}
2 changes: 1 addition & 1 deletion charts/mirrorbits-lite/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.ingress.enabled -}}
{{- if and .Values.ingress.enabled (not (dig "global" "ingress" "enabled" false .Values.AsMap)) -}}
{{- $fullName := include "mirrorbits-lite.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
apiVersion: networking.k8s.io/v1
Expand Down
6 changes: 3 additions & 3 deletions charts/mirrorbits-lite/templates/persistentVolume.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{ if $.Values.repository.persistentVolume.enabled -}}
{{ if and .Values.repository.persistentVolume.enabled (not (dig "global" "ingress" "enabled" false .Values.AsMap)) -}}
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ $.Values.repository.name | default (printf "%s-binary" (include "mirrorbits-lite.fullname" .)) }}
name: {{ .Values.repository.name | default (printf "%s-binary" (include "mirrorbits-lite.fullname" .)) }}
labels:
data: {{ $.Values.repository.name | default (printf "%s-binary" (include "mirrorbits-lite.fullname" . )) }}
data: {{ .Values.repository.name | default (printf "%s-binary" (include "mirrorbits-lite.fullname" . )) }}
spec:
{{ toYaml .Values.repository.persistentVolume.spec | nindent 2 }}
{{- end -}}
6 changes: 3 additions & 3 deletions charts/mirrorbits-lite/templates/persistentVolumeClaim.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{ if $.Values.repository.persistentVolumeClaim.enabled -}}
{{ if and .Values.repository.persistentVolumeClaim.enabled (not (dig "global" "ingress" "enabled" false .Values.AsMap)) -}}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ $.Values.repository.name | default (printf "%s-binary" (include "mirrorbits-lite.fullname" .)) }}
name: {{ .Values.repository.name | default (printf "%s-binary" (include "mirrorbits-lite.fullname" .)) }}
spec:
{{ toYaml $.Values.repository.persistentVolumeClaim.spec | nindent 2 }}
{{ toYaml .Values.repository.persistentVolumeClaim.spec | nindent 2 }}
{{- end -}}
81 changes: 72 additions & 9 deletions charts/mirrorbits-lite/tests/custom_values_test.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
suite: Tests with custom values
templates:
- deployment.yaml
- ingress.yaml
- secret.yaml # Direct dependency of deployment(.*).yaml
- service.yaml
- persistentVolume.yaml
- persistentVolumeClaim.yaml
- tests/mock_parent_helpers.tpl
set:
image:
pullPolicy: Always
logs:
volume:
persistentVolumeClaim:
claimName: foobar
geoipupdate:
account_id: my-account-id
license_key: my-license-key
Expand All @@ -16,11 +20,43 @@ set:
paths:
- path: /
pathType: IfNotPresent
templates:
- deployment.yaml
- ingress.yaml
- secret.yaml # Direct dependency of deployment(.*).yaml
- service
logs:
volume:
persistentVolumeClaim:
claimName: foobar
repository:
name: mirrorbits-binary
persistentVolumeClaim:
enabled: true
spec:
accessModes:
- ReadWriteMany
storageClassName: azurefile-csi-premium
resources:
requests:
storage: 1000Gi
volumeName: mirrorbits-binary
persistentVolume:
enabled: true
spec:
capacity:
storage: 1000Gi
storageClassName: azurefile-csi-premium
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
csi:
driver: file.csi.azure.com
readOnly: false
volumeHandle: mirrorbits-binary # make sure this volumeid is unique for every identical share in the cluster
volumeAttributes:
resourceGroup: prod-core-releases
shareName: mirrorbits
nodeStageSecretRef:
name: mirrorbits-binary
namespace: mirrorbits
mountOptions:
- dir_mode=0755
tests:
- it: Should set the correct service selector labels when a fullNameOverride is specified
template: service.yaml
Expand Down Expand Up @@ -60,6 +96,19 @@ tests:
- equal:
path: spec.template.spec.containers[0].volumeMounts[2].mountPath
value: /var/log/mirrorbits
# Data Volume
- equal:
path: spec.template.spec.volumes[3].name
value: data
- equal:
path: spec.template.spec.volumes[3].persistentVolumeClaim.claimName
value: mirrorbits-binary
- equal:
path: spec.template.spec.containers[0].volumeMounts[3].name
value: data
- equal:
path: spec.template.spec.containers[0].volumeMounts[3].mountPath
value: /srv/repo
- it: should create ingress with pathType set to the specified custom value by default
template: ingress.yaml
asserts:
Expand All @@ -70,3 +119,17 @@ tests:
- equal:
path: spec.rules[0].http.paths[0].pathType
value: "IfNotPresent"
- it: should define a customized "mirrorbits-lite" persistent volume
template: persistentVolume.yaml
asserts:
- hasDocuments:
count: 1
- isKind:
of: PersistentVolume
- it: should define a customized "mirrorbits-lite" PV claim
template: persistentVolumeClaim.yaml
asserts:
- hasDocuments:
count: 1
- isKind:
of: PersistentVolumeClaim
26 changes: 26 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,9 @@ templates:
- ingress.yaml
- secret.yaml # Direct dependency of deployment(.*).yaml
- service.yaml
- persistentVolume.yaml
- persistentVolumeClaim.yaml
- tests/mock_parent_helpers.tpl
tests:
- it: should not create any ingress by default
template: ingress.yaml
Expand Down Expand Up @@ -39,3 +42,26 @@ tests:
- equal:
path: spec.template.spec.containers[0].volumeMounts[2].mountPath
value: /var/log/mirrorbits
# Data Volume is an emptyDir by default
- equal:
path: spec.template.spec.volumes[3].name
value: data
- equal:
path: spec.template.spec.volumes[3].emptyDir
value: {}
- equal:
path: spec.template.spec.containers[0].volumeMounts[3].name
value: data
- equal:
path: spec.template.spec.containers[0].volumeMounts[3].mountPath
value: /srv/repo
- it: should not define any persistent volume
template: persistentVolume.yaml
asserts:
- hasDocuments:
count: 0
- it: should not define any PV claim
template: persistentVolumeClaim.yaml
asserts:
- hasDocuments:
count: 0
92 changes: 92 additions & 0 deletions charts/mirrorbits-lite/tests/parent_values_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
suite: Tests with values from parent (umbrella ingress and umbrella PVC)
templates:
- templates/deployment.yaml
- templates/ingress.yaml
- templates/secret.yaml # Direct dependency of deployment(.*).yaml
- templates/persistentVolume.yaml
- templates/persistentVolumeClaim.yaml
set:
# Mock chart parent inherited global values passed to subcharts
global:
storage:
enabled: true
ingress:
enabled: true
# Try to specify a ingress which must be ignored (parent prevails)
ingress:
enabled: true
hosts:
- host: chart-example.local
paths:
- path: /
pathType: IfNotPresent
# Try to specify a PV which must be ignored (parent prevails)
repository:
name: mirrorbits-binary
persistentVolumeClaim:
enabled: true
spec:
accessModes:
- ReadWriteMany
storageClassName: azurefile-csi-premium
resources:
requests:
storage: 1000Gi
volumeName: mirrorbits-binary
persistentVolume:
enabled: true
spec:
capacity:
storage: 1000Gi
storageClassName: azurefile-csi-premium
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
csi:
driver: file.csi.azure.com
readOnly: false
volumeHandle: mirrorbits-binary # make sure this volumeid is unique for every identical share in the cluster
volumeAttributes:
resourceGroup: prod-core-releases
shareName: mirrorbits
nodeStageSecretRef:
name: mirrorbits-binary
namespace: mirrorbits
mountOptions:
- dir_mode=0755
tests:
- it: should define a customized "mirrorbits-lite" deployment
template: deployment.yaml
asserts:
- hasDocuments:
count: 1
- isKind:
of: Deployment
# Data Volume (references a claim from parent chart)
- equal:
path: spec.template.spec.volumes[3].name
value: data
- equal:
path: spec.template.spec.volumes[3].persistentVolumeClaim.claimName
value: parent-chart-shared-data
- equal:
path: spec.template.spec.containers[0].volumeMounts[3].name
value: data
- equal:
path: spec.template.spec.containers[0].volumeMounts[3].mountPath
value: /srv/repo
- it: should not create any ingress
template: ingress.yaml
asserts:
- hasDocuments:
count: 0
- it: should not define any persistent volume
template: persistentVolume.yaml
asserts:
- hasDocuments:
count: 0
- it: should not define any PV claim
template: persistentVolumeClaim.yaml
asserts:
- hasDocuments:
count: 0

0 comments on commit 9b112a8

Please sign in to comment.