From 3cda910be6287de1c26b42d166f6c6eaba8f6072 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Mon, 1 Mar 2021 18:38:55 +0100 Subject: [PATCH] Add Unlimited Custom hostPath mounts (#201) --- .../development/unlimited-storage-mounts.md | 69 ++++++++++++++++ .github/docs/general/storage.md | 4 + library/common-test/Chart.yaml | 2 +- library/common-test/ci/basic-values.yaml | 22 ++++- library/common-test/ci/codeserver-values.yaml | 22 ++++- library/common-test/values.yaml | 18 +++- library/common/Chart.yaml | 2 +- .../templates/lib/controller/_container.tpl | 2 +- .../templates/lib/controller/_volumes.tpl | 2 +- .../templates/lib/storage/_appStorage.tpl | 82 +++++++++++++------ .../lib/storage/_mountPermissionsJob.tpl | 2 +- library/common/values.yaml | 5 +- 12 files changed, 195 insertions(+), 37 deletions(-) create mode 100644 .github/docs/development/unlimited-storage-mounts.md diff --git a/.github/docs/development/unlimited-storage-mounts.md b/.github/docs/development/unlimited-storage-mounts.md new file mode 100644 index 00000000000..80823531d19 --- /dev/null +++ b/.github/docs/development/unlimited-storage-mounts.md @@ -0,0 +1,69 @@ +# Unlimited Storage Mounts + +We support presenting the user with a "Do it yourself" style list, in which the user can add unlimited paths on the host system to mount. +It should always be included in any App, to give users the option to customise things however they like. + +### Example + +``` + - variable: appExtraVolumeMounts + label: "Custom app storage" + group: "Storage" + schema: + type: list + default: [] + items: + - variable: volumeMount + label: "Custom Storage" + schema: + type: dict + attrs: + - variable: enabled + label: "Enabled" + schema: + type: boolean + default: true + required: true + hidden: true + editable: false + - variable: setPermissions + label: "Automatic Permissions" + description: "Automatically set permissions on install" + schema: + type: boolean + default: true + hidden: false + - variable: name + label: "Mountpoint Name" + schema: + type: string + default: "" + required: true + editable: true + - variable: emptyDir + label: "emptyDir" + schema: + type: boolean + default: false + hidden: true + editable: false + - variable: mountPath + label: "Mount Path" + description: "Path to mount inside the pod" + schema: + type: path + required: true + default: "" + editable: true + - variable: hostPathEnabled + label: "host Path Enabled" + schema: + type: boolean + default: true + hidden: true + - variable: hostPath + label: "Host Path" + schema: + type: hostpath + required: true +``` diff --git a/.github/docs/general/storage.md b/.github/docs/general/storage.md index 61810ee196e..fa875e06cac 100644 --- a/.github/docs/general/storage.md +++ b/.github/docs/general/storage.md @@ -33,3 +33,7 @@ Setting permissions automatically means we `chown` the folder and all folder wit However, we only do so when installing or updating an app. These permission get based on the user and group you enter in the App configuration dialog and default to `568` (the SCALE default Apps user). + +### Custom Storage + +Besides the earlier mentioned storage options, we also provide the option to mount as many host folders as you want. This is limited to hostPath mounts only. diff --git a/library/common-test/Chart.yaml b/library/common-test/Chart.yaml index f87a67d38bc..770f47005ad 100644 --- a/library/common-test/Chart.yaml +++ b/library/common-test/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 kubeVersion: ">=1.16.0-0" name: common-test -version: 1.3.2 +version: 1.4.0 # upstream_version: # appVersion: description: Helper chart to test different use cases of the common library diff --git a/library/common-test/ci/basic-values.yaml b/library/common-test/ci/basic-values.yaml index 07e67df6e7b..23e5b375933 100644 --- a/library/common-test/ci/basic-values.yaml +++ b/library/common-test/ci/basic-values.yaml @@ -25,16 +25,32 @@ appVolumeMounts: emptyDir: true datasetName: "data" mountPath: "/data" - hostPathEnabled: true - hostPath: "/tmp" + hostPathEnabled: false + hostPath: "" test: enabled: true - emptyDir: true + emptyDir: false datasetName: "test" mountPath: "/test" hostPathEnabled: true hostPath: "/tmp" +appExtraVolumeMounts: + - name: "extratest1" + enabled: true + emptyDir: true + datasetName: "extratest1" + mountPath: "/extratest1" + hostPathEnabled: false + hostPath: "" + - name: "extratest2" + enabled: true + emptyDir: false + datasetName: "extratest2" + mountPath: "/extratest2" + hostPathEnabled: true + hostPath: "/tmp" + appAdditionalServicesEnabled: true appAdditionalServices: extra-tcp: diff --git a/library/common-test/ci/codeserver-values.yaml b/library/common-test/ci/codeserver-values.yaml index 183aa4455e9..38af9e0c379 100644 --- a/library/common-test/ci/codeserver-values.yaml +++ b/library/common-test/ci/codeserver-values.yaml @@ -33,16 +33,32 @@ appVolumeMounts: emptyDir: true datasetName: "data" mountPath: "/data" - hostPathEnabled: true - hostPath: "/tmp" + hostPathEnabled: false + hostPath: "" test: enabled: true - emptyDir: true + emptyDir: false datasetName: "test" mountPath: "/test" hostPathEnabled: true hostPath: "/tmp" +appExtraVolumeMounts: + - name: "extratest1" + enabled: true + emptyDir: true + datasetName: "extratest1" + mountPath: "/extratest1" + hostPathEnabled: false + hostPath: "" + - name: "extratest2" + enabled: true + emptyDir: false + datasetName: "extratest2" + mountPath: "/extratest2" + hostPathEnabled: true + hostPath: "/tmp" + appAdditionalServicesEnabled: true appAdditionalServices: extra-tcp: diff --git a/library/common-test/values.yaml b/library/common-test/values.yaml index ffca89a2c0f..998c40cfc1b 100644 --- a/library/common-test/values.yaml +++ b/library/common-test/values.yaml @@ -21,11 +21,27 @@ appVolumeMounts: hostPath: "" test: enabled: true - emptyDir: true + emptyDir: false datasetName: "test" mountPath: "/test" + hostPathEnabled: true + hostPath: "/tmp" + +appExtraVolumeMounts: + - name: "extratest1" + enabled: true + emptyDir: true + datasetName: "extratest1" + mountPath: "/extratest1" hostPathEnabled: false hostPath: "" + - name: "extratest2" + enabled: true + emptyDir: false + datasetName: "extratest2" + mountPath: "/extratest2" + hostPathEnabled: true + hostPath: "/tmp" appAdditionalServicesEnabled: true appAdditionalServices: diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 581c6243025..7d3e31d96ca 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 kubeVersion: ">=1.16.0-0" name: common -version: 1.5.0 +version: 1.6.0 # upstream_version: 3.0.1 # appVersion: description: Function library for TrueCharts diff --git a/library/common/templates/lib/controller/_container.tpl b/library/common/templates/lib/controller/_container.tpl index 5cd6243ad41..228088edb41 100644 --- a/library/common/templates/lib/controller/_container.tpl +++ b/library/common/templates/lib/controller/_container.tpl @@ -65,7 +65,7 @@ The main container included in the controller. {{- end }} {{- end }} {{- end }} - {{- include "common.storage.configuredAppVolumeMounts" . | indent 2 }} + {{ include "common.storage.allContainerVolumeMounts" . | nindent 2 }} {{- if .Values.additionalVolumeMounts }} {{- toYaml .Values.additionalVolumeMounts | nindent 2 }} {{- end }} diff --git a/library/common/templates/lib/controller/_volumes.tpl b/library/common/templates/lib/controller/_volumes.tpl index cd10260ee45..23cd7641870 100644 --- a/library/common/templates/lib/controller/_volumes.tpl +++ b/library/common/templates/lib/controller/_volumes.tpl @@ -25,7 +25,7 @@ Volumes included by the controller. {{- end }} {{- end }} {{- end }} -{{- include "common.storage.configuredAppVolumes" . }} +{{ include "common.storage.allAppVolumes" . | nindent 0 }} {{- if .Values.additionalVolumes }} {{- toYaml .Values.additionalVolumes | nindent 0 }} {{- end }} diff --git a/library/common/templates/lib/storage/_appStorage.tpl b/library/common/templates/lib/storage/_appStorage.tpl index 75a08fb3a5f..b08463580d7 100644 --- a/library/common/templates/lib/storage/_appStorage.tpl +++ b/library/common/templates/lib/storage/_appStorage.tpl @@ -1,40 +1,76 @@ {{/* Define appVolumeMounts for container */}} -{{- define "common.storage.configuredAppVolumeMounts" -}} -{{- if .Values.appVolumeMounts }} -{{- range $name, $avm := .Values.appVolumeMounts -}} -{{- if $avm.enabled }} +{{- define "common.storage.configureAppVolumeMountsInContainer" -}} +{{ range $name, $avm := . }} +{{- if (default true $avm.enabled) -}} +{{ if $avm.name }} +{{ $name = $avm.name }} +{{ end }} - name: {{ $name }} mountPath: {{ $avm.mountPath }} - {{- if $avm.subPath }} + {{ if $avm.subPath }} subPath: {{ $avm.subPath }} - {{- end }} -{{- end }} -{{- end }} -{{- end }} + {{ end }} {{- end -}} +{{ end }} +{{- end -}} + {{/* Define hostPath for appVolumes */}} -{{- define "common.storage.configuredAppVolumes" -}} -{{- if .Values.appVolumeMounts }} -{{- range $name, $av := .Values.appVolumeMounts -}} -{{- if $av.enabled }} +{{- define "common.storage.configureAppVolumes" -}} +{{- range $name, $av := $.volMounts -}} +{{ if (default true $av.enabled) }} +{{ if $av.name }} +{{ $name = $av.name }} +{{ end }} - name: {{ $name }} - {{- if $av.emptyDir }} + {{ if $av.emptyDir }} emptyDir: {} - {{- else }} + {{- else -}} hostPath: {{ if $av.hostPathEnabled }} path: {{ required "hostPath not set" $av.hostPath }} - {{- else }} - {{- $volDict := dict "datasetName" $av.datasetName "ixVolumes" $.Values.ixVolumes -}} - path: {{ include "common.storage.retrieveHostPathFromiXVolume" $volDict }} - {{- end }} - {{- end }} -{{- end }} -{{- end }} -{{- end }} + {{ else }} + {{- $ixVolDict := dict "datasetName" $av.datasetName "ixVolumes" $.ixVolumes -}} + path: {{ include "common.storage.retrieveHostPathFromiXVolume" $ixVolDict }} + {{ end }} + {{ end }} +{{ end }} +{{- end -}} +{{- end -}} + + +{{/* +Get all volumes configuration +*/}} +{{- define "common.storage.allAppVolumes" -}} + +{{- $volDict := dict "volMounts" .Values.appVolumeMounts "ixVolumes" .Values.ixVolumes -}} +{{- $volExtraDict := dict "volMounts" .Values.appExtraVolumeMounts "ixVolumes" .Values.ixVolumes -}} + +{{- if .Values.appVolumeMounts -}} +{{- include "common.storage.configureAppVolumes" $volDict | nindent 0 -}} +{{- end -}} +{{- if .Values.appExtraVolumeMounts -}} +{{- include "common.storage.configureAppVolumes" $volExtraDict | nindent 0 -}} +{{- end -}} + +{{- end -}} + + +{{/* +Get all container volume moutns configuration +*/}} +{{- define "common.storage.allContainerVolumeMounts" -}} + +{{- if .Values.appVolumeMounts -}} +{{- include "common.storage.configureAppVolumeMountsInContainer" .Values.appVolumeMounts | nindent 0 -}} +{{- end -}} +{{- if .Values.appExtraVolumeMounts -}} +{{- include "common.storage.configureAppVolumeMountsInContainer" .Values.appExtraVolumeMounts | nindent 0 -}} +{{- end -}} + {{- end -}} diff --git a/library/common/templates/lib/storage/_mountPermissionsJob.tpl b/library/common/templates/lib/storage/_mountPermissionsJob.tpl index d31899bba7a..00ddad79416 100644 --- a/library/common/templates/lib/storage/_mountPermissionsJob.tpl +++ b/library/common/templates/lib/storage/_mountPermissionsJob.tpl @@ -55,7 +55,7 @@ spec: #securityContext: # volumeMounts: - {{- include "common.storage.configuredAppVolumeMounts" . | indent 12 }} + {{- include "common.storage.allContainerVolumeMounts" . | indent 12 }} {{- with (include "common.controller.volumes" . | trim) }} volumes: {{- . | nindent 8 }} diff --git a/library/common/values.yaml b/library/common/values.yaml index 1b1d69f69c4..1ebe8faecfa 100644 --- a/library/common/values.yaml +++ b/library/common/values.yaml @@ -493,8 +493,8 @@ fixMountPermissions: true # hostPath: "" # setPermissions: true -# -# data: +# appExtraVolumeMounts: +# - name: "data" # enabled: false # emptyDir: false # datasetName: "data" @@ -502,6 +502,7 @@ fixMountPermissions: true # subPath: some-subpath # hostPathEnabled: false # hostPath: "" +# setPermissions: true # appIngress: # main: