Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mirrorbits-lite) allow defining ingress and PV(C)s from parent chart #817

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions charts/mirrorbits-lite/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
.idea/
*.tmproj
.vscode/
tests/*
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
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 "mirrorbits-parent.pvc-name" . }}
{{- 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
3 changes: 3 additions & 0 deletions charts/mirrorbits-lite/templates/mocks/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- define "mirrorbits-parent.pvc-name" -}}
parent-chart-shared-data
{{- end -}}
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 -}}
80 changes: 71 additions & 9 deletions charts/mirrorbits-lite/tests/custom_values_test.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
suite: Tests with custom values
templates:
- deployment.yaml
- ingress.yaml
- secret.yaml # Direct dependency of deployment(.*).yaml
lemeurherve marked this conversation as resolved.
Show resolved Hide resolved
- service.yaml
- persistentVolume.yaml
- persistentVolumeClaim.yaml
set:
image:
pullPolicy: Always
logs:
volume:
persistentVolumeClaim:
claimName: foobar
geoipupdate:
account_id: my-account-id
license_key: my-license-key
Expand All @@ -16,11 +19,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 +95,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 +118,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
25 changes: 25 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,8 @@ templates:
- ingress.yaml
- secret.yaml # Direct dependency of deployment(.*).yaml
- service.yaml
- persistentVolume.yaml
- persistentVolumeClaim.yaml
tests:
- it: should not create any ingress by default
template: ingress.yaml
Expand Down Expand Up @@ -39,3 +41,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:
- deployment.yaml
- ingress.yaml
- secret.yaml # Direct dependency of deployment(.*).yaml
lemeurherve marked this conversation as resolved.
Show resolved Hide resolved
- persistentVolume.yaml
- 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