Skip to content

Commit

Permalink
Add support for ephemeral volume (configMap) (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoucefGuichi committed Mar 16, 2023
1 parent 96cbc7e commit 5660435
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 80 deletions.
16 changes: 16 additions & 0 deletions charts/common/templates/_customFileConfigmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- define "common.customFileConfigmap.tpl" -}}
{{- range .Values.volumes }}
{{- if .fileName }}

apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "common.robustName" .fileName }}
namespace: {{ $.Release.Namespace }}
data:
{{ .fileName }}: |
{{- .fileContent | nindent 4 }}
{{- end }}
{{- end }}
{{- end -}}
4 changes: 2 additions & 2 deletions charts/common/templates/_pvc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- define "common.pvc.tpl" -}}
{{- range .Values.volumes }}
{{- if not (or .existingClaim .hostPath) }}
{{- if not (or .existingClaim .hostPath .fileName .emptyDir .existingConfigMap) }}
{{- $robustName := include "common.robustName" $.Release.Name }}
---
apiVersion: v1
Expand All @@ -23,4 +23,4 @@ spec:
storage: {{ .size | default "1Gi" }}
{{- end }}
{{- end }}
{{- end -}}
{{- end -}}
17 changes: 15 additions & 2 deletions charts/common/templates/_volumeMountsRef.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
{{- if or (or (or (.Values.volumes) (.Values.sealedFileSecrets)) .Values.fileSecrets) .Values.existingFileSecrets }}
volumeMounts: &volumeMounts
{{- range .Values.volumes }}
- name: {{ .name }}
mountPath: {{ .path }}

{{- $volumeName := .name -}}
{{- if .existingConfigMap }}
{{- $volumeName = .existingConfigMap -}}
{{- end }}
{{- if .fileName }}
{{- $volumeName = include "common.robustName" .fileName -}}
{{- end }}

- name: {{ $volumeName }}
mountPath: {{ .path }}
{{- if .subPath }}
subPath: {{ .subPath }}
{{- end }}
{{- end }}
{{- range .Values.sealedFileSecrets }}
- name: {{ .name }}
mountPath: {{ .path }}
Expand All @@ -25,3 +37,4 @@ volumeMounts: &volumeMounts
{{- end }}
{{- end }}
{{- end }}

21 changes: 18 additions & 3 deletions charts/common/templates/_volumesRef.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@
{{- if or (or (or (.Values.volumes) (.Values.sealedFileSecrets)) .Values.fileSecrets) .Values.existingFileSecrets }}
volumes:
{{- range .Values.volumes }}
- name: {{ .name }}

{{- $volumeName := .name -}}
{{- if .existingConfigMap }}
{{- $volumeName = .existingConfigMap -}}
{{- end }}
{{- if .fileName }}
{{- $volumeName = include "common.robustName" .fileName -}}
{{- end }}

- name: {{ $volumeName }}
{{- if .emptyDir }}
emptyDir: {}
{{- else if .existingConfigMap }}
configMap:
name: {{ .existingConfigMap }}
{{- else if .fileName }}
configMap:
name: {{ $volumeName }}
{{- else if .hostPath }}
hostPath:
path: {{ .hostPath.path }}
Expand All @@ -18,8 +33,8 @@ volumes:
{{ else }}
claimName: {{ printf "%s-%s" $.Release.Name .name }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- range .Values.sealedFileSecrets }}
- name: {{ .name }}
secret:
Expand Down
Binary file modified charts/cron-job/charts/common-0.2.0.tgz
Binary file not shown.
Binary file modified charts/onechart/charts/common-0.2.0.tgz
Binary file not shown.
9 changes: 6 additions & 3 deletions charts/onechart/helm-ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,14 @@
"uiSchema": {
"#/properties/volumes": {
"items": {
"emptyDir": {
"ui:widget": "hidden"
"emptyDir": {
"ui:widget": "hidden"
},
"configMapValue": {
"ui:widget": "textarea"
}
}
}
}
},
"metaData": {
"name": "Volumes",
Expand Down
1 change: 1 addition & 0 deletions charts/onechart/templates/custom-file-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- include "common.customFileConfigmap.tpl" . -}}
22 changes: 22 additions & 0 deletions charts/onechart/tests/custom_file_configmap_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
suite: test deployment
templates:
- custom-file-configmap.yaml
tests:
- it: Should create configmaps for custom string files
set:
volumes:
- fileName: myFile.conf
fileContent: |
blablabla
bla
path: /randomPath/myFile.conf
subPath: myFile.conf
asserts:
- hasDocuments:
count: 1
- equal:
path: data
value:
myFile.conf: |
blablabla
bla
58 changes: 58 additions & 0 deletions charts/onechart/tests/deployment_volumes_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,61 @@ tests:
- name: data
hostPath:
path: /somewhere/over/the/rainbow
- it: Should use emptyDir
set:
volumes:
- name: myScratchDisk
path: /randomPath
emptyDir: true
asserts:
- equal:
path: spec.template.spec.volumes
value:
- name: myScratchDisk
emptyDir: {}
- equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- name: myScratchDisk
mountPath: /randomPath
- it: Should use a configMap
set:
volumes:
- existingConfigMap: my-configmap
path: /randomPath/app.conf
subPath: app.conf
asserts:
- equal:
path: spec.template.spec.volumes
value:
- name: my-configmap
configMap:
name: my-configmap
- equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- name: my-configmap
mountPath: /randomPath/app.conf
subPath: app.conf
- it: Should use a configmap with custom value
set:
volumes:
- fileName: myfile.conf
fileContent: |
blablabla
bla
path: /randomPath/myfile.conf
subPath: myfile.conf
asserts:
- equal:
path: spec.template.spec.volumes
value:
- name: myfile-conf
configMap:
name: myfile-conf
- equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- name: myfile-conf
mountPath: /randomPath/myfile.conf
subPath: myfile.conf
Loading

0 comments on commit 5660435

Please sign in to comment.