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(httpd) allow overriding ingress and PV(C)s based on global value from parent chart #818

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
2 changes: 1 addition & 1 deletion charts/httpd/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
description: httpd helm chart for Kubernetes
name: httpd
version: 0.1.0
version: 0.2.0
18 changes: 18 additions & 0 deletions charts/httpd/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 "httpd.html-volume" -}}
{{- if (dig "global" "storage" "enabled" false .Values.AsMap) -}}
persistentVolumeClaim:
claimName: {{ include "mirrorbits-parent.pvc-name" . }}
{{- else }}
{{- if or .Values.repository.persistentVolumeClaim.enabled .Values.repository.reuseExistingPersistentVolumeClaim }}
persistentVolumeClaim:
claimName: {{ .Values.repository.name | default (printf "%s-binary" (include "httpd.fullname" .)) }}
{{- else }}
emptyDir: {}
{{- end -}}
{{- end -}}
{{- end -}}
16 changes: 6 additions & 10 deletions charts/httpd/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -38,15 +39,13 @@ spec:
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
{{ if or .Values.repository.persistentVolumeClaim.enabled .Values.repository.reuseExistingPersistentVolumeClaim -}}
- name: binary
mountPath: /usr/local/apache2/htdocs
readOnly: true
{{- end }}
- name: conf
mountPath: /usr/local/apache2/conf/httpd.conf
subPath: httpd.conf
readOnly: true
- name: html
mountPath: /usr/local/apache2/htdocs
readOnly: true
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand All @@ -63,8 +62,5 @@ spec:
- name: conf
configMap:
name: {{ include "httpd.fullname" . }}
{{ if or .Values.repository.persistentVolumeClaim.enabled .Values.repository.reuseExistingPersistentVolumeClaim -}}
- name: binary
persistentVolumeClaim:
claimName: {{ .Values.repository.name | default (printf "%s-binary" (include "httpd.fullname" .)) }}
{{- end }}
- name: html
{{- include "httpd.html-volume" . | nindent 10}}
2 changes: 1 addition & 1 deletion charts/httpd/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 "httpd.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
apiVersion: networking.k8s.io/v1
Expand Down
3 changes: 3 additions & 0 deletions charts/httpd/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 -}}
2 changes: 1 addition & 1 deletion charts/httpd/templates/persistentVolume.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ if $.Values.repository.persistentVolume.enabled -}}
{{ if and .Values.repository.persistentVolume.enabled (not (dig "global" "ingress" "enabled" false .Values.AsMap)) -}}
---
apiVersion: v1
kind: PersistentVolume
Expand Down
2 changes: 1 addition & 1 deletion charts/httpd/templates/persistentVolumeClaim.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ if .Values.repository.persistentVolumeClaim.enabled -}}
{{ if and .Values.repository.persistentVolumeClaim.enabled (not (dig "global" "ingress" "enabled" false .Values.AsMap)) -}}
---
apiVersion: v1
kind: PersistentVolumeClaim
Expand Down
114 changes: 66 additions & 48 deletions charts/httpd/tests/custom_values_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ templates:
- ingress.yaml
- secret.yaml # Direct dependency of deployment.yaml
- service.yaml
- persistentVolume.yaml
- persistentVolumeClaim.yaml
set:
image:
pullPolicy: Never
repository:
reuseExistingPersistentVolumeClaim: true
ingress:
enabled: true
hosts:
- host: chart-example.local
paths:
- path: /
pathType: IfNotPresent
tests:
- it: Should set the correct service selector labels when a fullNameOverride is specified
template: service.yaml
Expand Down Expand Up @@ -37,9 +51,6 @@ tests:
value: "RELEASE-NAME"
- it: should define a customized deployment
template: deployment.yaml
set:
image:
pullPolicy: Never
asserts:
- hasDocuments:
count: 1
Expand All @@ -48,33 +59,39 @@ tests:
- equal:
path: spec.template.spec.containers[*].imagePullPolicy
value: Never
- it: should define a "binary" volume if reuseExistingPersistentVolumeClaim is true
- it: should define a volume 'html' if reuseExistingPersistentVolumeClaim is true
template: deployment.yaml
set:
repository:
reuseExistingPersistentVolumeClaim: true
asserts:
- hasDocuments:
count: 1
- isKind:
of: Deployment
- lengthEqual:
path: spec.template.spec.volumes
count: 2
- contains:
path: spec.template.spec.volumes
content:
name: "binary"
any: true
- lengthEqual:
path: spec.template.spec.containers[0].volumeMounts
count: 2
- contains:
path: spec.template.spec.containers[0].volumeMounts
content:
name: "binary"
any: true
- it: should define a "binary" volume if repository.persistentVolumeClaim.enabled is true
- equal:
path: spec.template.spec.volumes[0].name
value: conf
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].name
value: conf
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].readOnly
value: true
# HTML volume uses an existing PVC (specified by values)
- equal:
path: spec.template.spec.volumes[1].name
value: html
- equal:
path: spec.template.spec.volumes[1].persistentVolumeClaim.claimName
value: httpd-binary
- equal:
path: spec.template.spec.containers[0].volumeMounts[1].name
value: html
- equal:
path: spec.template.spec.containers[0].volumeMounts[1].readOnly
value: true
- equal:
path: spec.template.spec.containers[0].volumeMounts[1].mountPath
value: /usr/local/apache2/htdocs
- it: should define a managed "html" volume if repository.persistentVolumeClaim.enabled is true
template: deployment.yaml
set:
repository:
Expand All @@ -85,32 +102,33 @@ tests:
count: 1
- isKind:
of: Deployment
- lengthEqual:
path: spec.template.spec.volumes
count: 2
- contains:
path: spec.template.spec.volumes
content:
name: "binary"
any: true
- lengthEqual:
path: spec.template.spec.containers[0].volumeMounts
count: 2
- contains:
path: spec.template.spec.containers[0].volumeMounts
content:
name: "binary"
any: true
- equal:
path: spec.template.spec.volumes[0].name
value: conf
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].name
value: conf
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].readOnly
value: true
# HTML volume uses an existing PVC (specified by values)
- equal:
path: spec.template.spec.volumes[1].name
value: html
- equal:
path: spec.template.spec.volumes[1].persistentVolumeClaim.claimName
value: httpd-binary
- equal:
path: spec.template.spec.containers[0].volumeMounts[1].name
value: html
- equal:
path: spec.template.spec.containers[0].volumeMounts[1].readOnly
value: true
- equal:
path: spec.template.spec.containers[0].volumeMounts[1].mountPath
value: /usr/local/apache2/htdocs
- it: should create ingress with pathType set to the specified custom value by default
template: ingress.yaml
set:
ingress:
enabled: true
hosts:
- host: chart-example.local
paths:
- path: /
pathType: IfNotPresent
asserts:
- hasDocuments:
count: 1
Expand Down
77 changes: 36 additions & 41 deletions charts/httpd/tests/defaults_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,15 @@ templates:
- ingress.yaml
- secret.yaml # Direct dependency of deployment(.*).yaml
dduportal marked this conversation as resolved.
Show resolved Hide resolved
- service.yaml
- persistentVolume.yaml
- persistentVolumeClaim.yaml
tests:
- it: should not create any ingress by default
template: ingress.yaml
asserts:
- hasDocuments:
count: 0
- it: should create ingress with pathType set to Prefix by default
template: ingress.yaml
set:
ingress:
enabled: true
hosts:
- host: chart-example.local
paths:
- path: /
asserts:
- hasDocuments:
count: 1
- isKind:
of: Ingress
- equal:
path: spec.rules[0].http.paths[0].pathType
value: "Prefix"
- it: should set the correct service selector labels
- it: should create a service with default values
template: service.yaml
asserts:
- hasDocuments:
Expand All @@ -41,20 +26,7 @@ tests:
- equal:
path: spec.selector["app.kubernetes.io/instance"]
value: "RELEASE-NAME"
- it: Should set the correct deployment metadata labels
template: deployment.yaml
asserts:
- hasDocuments:
count: 1
- isKind:
of: Deployment
- equal:
path: spec.template.metadata.labels["app.kubernetes.io/name"]
value: "httpd"
- equal:
path: spec.template.metadata.labels["app.kubernetes.io/instance"]
value: "RELEASE-NAME"
- it: should define the default deployment with default imagePullPolicy and metadata labels, and only a "conf" volume
- it: should create a Deployment with default values
template: deployment.yaml
asserts:
- hasDocuments:
Expand All @@ -68,17 +40,40 @@ tests:
path: spec.template.metadata.labels["app.kubernetes.io/instance"]
value: "RELEASE-NAME"
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
path: "spec.template.spec.containers[*].imagePullPolicy"
lemeurherve marked this conversation as resolved.
Show resolved Hide resolved
value: IfNotPresent
- lengthEqual:
path: spec.template.spec.volumes
count: 1
- equal:
path: spec.template.spec.volumes[0].name
value: "conf"
- lengthEqual:
path: spec.template.spec.containers[0].volumeMounts
count: 1
value: conf
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].name
value: "conf"
value: conf
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].readOnly
value: true
# HTML volume is an emptydir by default
- equal:
path: spec.template.spec.volumes[1].name
value: html
- equal:
path: spec.template.spec.volumes[1].emptyDir
value: {}
- equal:
path: spec.template.spec.containers[0].volumeMounts[1].name
value: html
- equal:
path: spec.template.spec.containers[0].volumeMounts[1].readOnly
value: true
- equal:
path: spec.template.spec.containers[0].volumeMounts[1].mountPath
value: /usr/local/apache2/htdocs
- 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
Loading