From f61280773ea7da6c6b432d4e2d3bd98575f4adbc Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Tue, 7 Feb 2023 18:08:02 +0200 Subject: [PATCH] add pvc class and spawner and tests --- .../tests/persistence/metadata_test.yaml | 85 ++++++++ .../tests/persistence/names_test.yaml | 34 +++ .../tests/persistence/pvc_data_test.yaml | 199 ++++++++++++++++++ .../tests/persistence/validation_test.yaml | 70 ++++++ library/common/1.0.0/docs/persistence.md | 50 +++++ .../common/1.0.0/templates/classes/_pvc.tpl | 56 +++++ .../1.0.0/templates/classes/_statefulset.tpl | 1 + .../templates/lib/storage/_accessModes.tpl | 31 +++ .../lib/storage/_storageClassName.tpl | 53 +++++ .../templates/lib/storage/_validation.tpl | 30 +++ .../common/1.0.0/templates/loader/_apply.tpl | 3 + .../common/1.0.0/templates/spawner/_pvc.tpl | 39 ++++ library/common/1.0.0/values.yaml | 154 +++++++------- 13 files changed, 732 insertions(+), 73 deletions(-) create mode 100644 library/common-test/tests/persistence/metadata_test.yaml create mode 100644 library/common-test/tests/persistence/names_test.yaml create mode 100644 library/common-test/tests/persistence/pvc_data_test.yaml create mode 100644 library/common-test/tests/persistence/validation_test.yaml create mode 100644 library/common/1.0.0/docs/persistence.md create mode 100644 library/common/1.0.0/templates/classes/_pvc.tpl create mode 100644 library/common/1.0.0/templates/lib/storage/_accessModes.tpl create mode 100644 library/common/1.0.0/templates/lib/storage/_storageClassName.tpl create mode 100644 library/common/1.0.0/templates/lib/storage/_validation.tpl create mode 100644 library/common/1.0.0/templates/spawner/_pvc.tpl diff --git a/library/common-test/tests/persistence/metadata_test.yaml b/library/common-test/tests/persistence/metadata_test.yaml new file mode 100644 index 0000000000..b695de1063 --- /dev/null +++ b/library/common-test/tests/persistence/metadata_test.yaml @@ -0,0 +1,85 @@ +suite: persistence pvc metadata test +templates: + - common.yaml +chart: + appVersion: &appVer v9.9.9 +tests: + - it: should pass with pvc created with labels and annotations + set: + label1: label1 + label2: global_label2 + annotation1: annotation1 + annotation2: global_annotation2 + global: + labels: + g_label1: global_label1 + g_label2: "{{ .Values.label2 }}" + annotations: + g_annotation1: global_annotation1 + g_annotation2: "{{ .Values.annotation2 }}" + persistence: + my-volume1: + enabled: true + labels: + label1: "{{ .Values.label1 }}" + label2: label2 + annotations: + annotation1: "{{ .Values.annotation1 }}" + annotation2: annotation2 + type: pvc + asserts: + - documentIndex: &pvcDoc 0 + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + isAPIVersion: + of: v1 + - documentIndex: *pvcDoc + equal: + path: metadata.annotations + value: + annotation1: annotation1 + annotation2: annotation2 + g_annotation1: global_annotation1 + g_annotation2: global_annotation2 + - documentIndex: *pvcDoc + equal: + path: metadata.labels + value: + app: common-test-1.0.0 + release: RELEASE-NAME + helm-revision: 0 + helm.sh/chart: common-test-1.0.0 + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: *appVer + g_label1: global_label1 + g_label2: global_label2 + label1: label1 + label2: label2 + + - it: should pass with pvc created with retain set to true + set: + persistence: + my-volume1: + enabled: true + type: pvc + retain: true + asserts: + - documentIndex: *pvcDoc + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + equal: + path: metadata.annotations + value: + "helm.sh/resource-policy": keep + - documentIndex: *pvcDoc + equal: + path: metadata.labels + value: + app: common-test-1.0.0 + release: RELEASE-NAME + helm-revision: 0 + helm.sh/chart: common-test-1.0.0 + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: *appVer diff --git a/library/common-test/tests/persistence/names_test.yaml b/library/common-test/tests/persistence/names_test.yaml new file mode 100644 index 0000000000..1e59e9749a --- /dev/null +++ b/library/common-test/tests/persistence/names_test.yaml @@ -0,0 +1,34 @@ +suite: persistence pvc name test +templates: + - common.yaml +tests: + - it: should generate correct name + set: + persistence: + my-volume1: + enabled: true + type: pvc + my-volume2: + enabled: true + type: pvc + asserts: + - documentIndex: &pvcDoc 0 + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + isAPIVersion: + of: v1 + - documentIndex: *pvcDoc + equal: + path: metadata.name + value: release-name-common-test-my-volume1 + - documentIndex: &otherPvcDoc 1 + isKind: + of: PersistentVolumeClaim + - documentIndex: *otherPvcDoc + isAPIVersion: + of: v1 + - documentIndex: *otherPvcDoc + equal: + path: metadata.name + value: release-name-common-test-my-volume2 diff --git a/library/common-test/tests/persistence/pvc_data_test.yaml b/library/common-test/tests/persistence/pvc_data_test.yaml new file mode 100644 index 0000000000..b8864a6a27 --- /dev/null +++ b/library/common-test/tests/persistence/pvc_data_test.yaml @@ -0,0 +1,199 @@ +suite: pvc data name test +templates: + - common.yaml +tests: + - it: should create pvc + set: + persistence: + my-volume1: + enabled: true + type: pvc + asserts: + - documentIndex: &pvcDoc 0 + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + isAPIVersion: + of: v1 + - documentIndex: *pvcDoc + equal: + path: metadata.name + value: release-name-common-test-my-volume1 + - documentIndex: *pvcDoc + equal: + path: spec.accessModes + value: + - ReadWriteOnce + - documentIndex: *pvcDoc + equal: + path: spec.resources.requests.storage + value: 1Gi + - documentIndex: *pvcDoc + isNull: + path: spec.volumeName + - documentIndex: *pvcDoc + isNull: + path: spec.storageClassName + + - it: should create pvc with accessModes set as string + set: + some_mode: ReadWriteMany + persistence: + my-volume1: + enabled: true + type: pvc + accessModes: "{{ .Values.some_mode }}" + asserts: + - documentIndex: *pvcDoc + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + equal: + path: spec.accessModes + value: + - ReadWriteMany + + - it: should create pvc with accessModes set as list + set: + some_mode: ReadWriteMany + persistence: + my-volume1: + enabled: true + type: pvc + accessModes: + - "{{ .Values.some_mode }}" + - ReadWriteOnce + asserts: + - documentIndex: *pvcDoc + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + equal: + path: spec.accessModes + value: + - ReadWriteMany + - ReadWriteOnce + + - it: should create pvc with size set + set: + some_size: 20Gi + persistence: + my-volume1: + enabled: true + type: pvc + size: "{{ .Values.some_size }}" + asserts: + - documentIndex: *pvcDoc + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + equal: + path: spec.resources.requests.storage + value: 20Gi + + - it: should create pvc with volumeName set + set: + some_vol_name: some-pv-name + persistence: + my-volume1: + enabled: true + type: pvc + volumeName: "{{ .Values.some_vol_name }}" + asserts: + - documentIndex: *pvcDoc + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + equal: + path: spec.volumeName + value: some-pv-name + + - it: should create pvc with storageClass set "-" + set: + some_storage_class: "-" + persistence: + my-volume1: + enabled: true + type: pvc + storageClass: "{{ .Values.some_storage_class }}" + asserts: + - documentIndex: *pvcDoc + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + equal: + path: spec.storageClassName + value: "" + + - it: should create pvc with storageClass set + set: + some_storage_class: "some-storage-class" + persistence: + my-volume1: + enabled: true + type: pvc + storageClass: "{{ .Values.some_storage_class }}" + asserts: + - documentIndex: *pvcDoc + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + equal: + path: spec.storageClassName + value: some-storage-class + + - it: should create pvc with storageClass not set, but have fallbackDefaults set + set: + fallbackDefaults: + storageClass: some-storage-class + persistence: + my-volume1: + enabled: true + type: pvc + asserts: + - documentIndex: *pvcDoc + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + equal: + path: spec.storageClassName + value: some-storage-class + + - it: should create pvc with storageClass set "SCALE-ZFS" and within ixChartContext + set: + global: + ixChartContext: + storageClassName: ix-storage-class-releasename + some_storage_class: "SCALE-ZFS" + persistence: + my-volume1: + enabled: true + type: pvc + storageClass: "{{ .Values.some_storage_class }}" + asserts: + - documentIndex: *pvcDoc + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + equal: + path: spec.storageClassName + value: ix-storage-class-releasename + + - it: should create pvc with storageClass not set and within ixChartContext + set: + global: + ixChartContext: + storageClassName: ix-storage-class-releasename + some_storage_class: "SCALE-ZFS" + persistence: + my-volume1: + enabled: true + type: pvc + asserts: + - documentIndex: *pvcDoc + isKind: + of: PersistentVolumeClaim + - documentIndex: *pvcDoc + equal: + path: spec.storageClassName + value: ix-storage-class-releasename diff --git a/library/common-test/tests/persistence/validation_test.yaml b/library/common-test/tests/persistence/validation_test.yaml new file mode 100644 index 0000000000..4422f92d24 --- /dev/null +++ b/library/common-test/tests/persistence/validation_test.yaml @@ -0,0 +1,70 @@ +suite: persistence validation test +templates: + - common.yaml +tests: + - it: should fail with annotations not a dict + set: + persistence: + volume1: + enabled: true + annotations: not-a-dict + asserts: + - failedTemplate: + errorMessage: Persistence - Expected to be a dictionary, but got [string] + + - it: should fail with labels not a dict + set: + persistence: + volume1: + enabled: true + labels: not-a-dict + asserts: + - failedTemplate: + errorMessage: Persistence - Expected to be a dictionary, but got [string] + + - it: should fail with pod targetSelector not a map + set: + persistence: + volume1: + enabled: true + targetSelector: not-a-map + asserts: + - failedTemplate: + errorMessage: Persistence - Expected to be [dict], but got [string] + + - it: should fail with invalid type + set: + persistence: + volume1: + enabled: true + type: not-a-type + asserts: + - failedTemplate: + errorMessage: Persistence - Expected to be one of [pvc, emptyDir, nfs, hostPath, ixVolume, secret, configmap], but got [not-a-type] + + - it: should fail without storageClassName in ixChartContext + set: + global: + ixChartContext: + storageClassName: "" + persistence: + volume1: + enabled: true + type: pvc + asserts: + - failedTemplate: + errorMessage: PVC - Expected non-empty + + - it: should fail without storageClassName in ixChartContext with SCALE-ZFS explicitly set + set: + global: + ixChartContext: + storageClassName: "" + persistence: + volume1: + enabled: true + type: pvc + storageClass: SCALE-ZFS + asserts: + - failedTemplate: + errorMessage: PVC - Expected non-empty on [SCALE-ZFS] storageClass diff --git a/library/common/1.0.0/docs/persistence.md b/library/common/1.0.0/docs/persistence.md new file mode 100644 index 0000000000..c11153a56a --- /dev/null +++ b/library/common/1.0.0/docs/persistence.md @@ -0,0 +1,50 @@ +# Persistence + +| Key | Type | Required | Helm Template | Default | Description | +| :----------------------------------------- | :-----------: | :------: | :----------------: | :----------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------- | +| persistence | `dict` | ❌ | ❌ | `{}` | Define the persistence as dicts | +| persistence.[volume-name] | `dict` | ✅ | ❌ | `{}` | Holds persistence definition | +| persistence.[volume-name].enabled | `boolean` | ✅ | ❌ | `false` | Enables or Disables the persistence | +| persistence.[volume-name].labels | `dict` | ❌ | ✅ (On value only) | `{}` | Additional labels for persistence | +| persistence.[volume-name].annotations | `dict` | ❌ | ✅ (On value only) | `{}` | Additional annotations for persistence | +| persistence.[volume-name].type | `string` | ❌ | ❌ | `pvc` | Define the persistence type (pvc, ixVolume, nfs, hostPath, configmap, secret) | +| persistence.[volume-name].retain | `boolean` | ❌ | ❌ | `{{ .Values.global.fallbackDefaults.pvcRetain }}` | Define wether the to add helm annotation to retain resource on uninstall (Middleware should also retain it when deleting the NS) | +| persistence.[volume-name].accessModes | `string/list` | ❌ | ✅ | `{{ .Values.global.fallbackDefaults.pvcAccessModes }}` | Define the accessModes of the PVC, if it's single can be defined as a string, multiple as a list | +| persistence.[volume-name].size | `string` | ❌ | ✅ | `{{ .Values.global.fallbackDefaults.pvcSize }}` | Define the size of the PVC, or the sizeLimit of the emptyDir (Default does not apply there) | +| persistence.[volume-name].volumeName | `string` | ❌ | ✅ | | Define the volumeName of a PV, backing the claim | +| persistence.[volume-name].existingClaim | `string` | ❌ | ✅ | | Define an existing claim to use | +| persistence.[volume-name].storageClassName | `string` | ❌ | ✅ | See `templates/lib/storage/_storageClassName.tpl` | Define an existing claim to use | +| persistence.[volume-name].targetSelectAll | `boolean` | ❌ | ❌ | `false` | Define wether to define this volume to all workloads and mount it on all containers | + +--- + +Appears in: + +- `.Values.persistence` + +--- + +Naming scheme: + +- `$FullName-$PersistenceName` (release-name-chart-name-PersistenceName) + +--- + +Examples: + +```yaml +persistence: + pvc-vol: + enabled: true + type: pvc + labels: + label1: value1 + annotations: + annotation1: value1 + accessModes: ReadWriteOnce + volumeName: volume-name-backing-the-pvc + existingClaim: existing-claim-name + retain: true + size: 2Gi + targetSelectAll: true +``` diff --git a/library/common/1.0.0/templates/classes/_pvc.tpl b/library/common/1.0.0/templates/classes/_pvc.tpl new file mode 100644 index 0000000000..a26b679a8c --- /dev/null +++ b/library/common/1.0.0/templates/classes/_pvc.tpl @@ -0,0 +1,56 @@ +{{/* PVC Class */}} +{{/* Call this template: +{{ include "ix.v1.common.class.pvc" (dict "rootCtx" $ "objectData" $objectData) }} + +rootCtx: The root context of the template. It is used to access the global context. +objectData: + name: The name of the PVC. + labels: The labels of the PVC. + annotations: The annotations of the PVC. +*/}} + +{{- define "ix.v1.common.class.pvc" -}} + + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + + {{- $pvcRetain := $rootCtx.Values.fallbackDefaults.pvcRetain -}} + {{- if (kindIs "bool" $objectData.retain) -}} + {{- $pvcRetain = $objectData.retain -}} + {{- end -}} + + {{- $pvcSize := $rootCtx.Values.fallbackDefaults.pvcSize -}} + {{- with $objectData.size -}} + {{- $pvcSize = tpl . $rootCtx -}} + {{- end }} +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ $objectData.name }} + {{- $labels := (mustMerge ($objectData.labels | default dict) (include "ix.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}} + {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} + labels: + {{- . | nindent 4 }} + {{- end -}} + {{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "ix.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}} + {{- if $pvcRetain -}} + {{- $_ := set $annotations "\"helm.sh/resource-policy\"" "keep" -}} + {{- end -}} + {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }} + annotations: + {{- . | nindent 4 }} + {{- end }} +spec: + accessModes: + {{- include "ix.v1.common.lib.pvc.accessModes" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 4 }} + resources: + requests: + storage: {{ $pvcSize }} + {{- with $objectData.volumeName }} + volumeName: {{ tpl . $rootCtx }} + {{- end -}} + {{- with (include "ix.v1.common.lib.pvc.storageClassName" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }} + storageClassName: {{ . }} + {{- end -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/classes/_statefulset.tpl b/library/common/1.0.0/templates/classes/_statefulset.tpl index a8f70ed6c0..8a6bdafc30 100644 --- a/library/common/1.0.0/templates/classes/_statefulset.tpl +++ b/library/common/1.0.0/templates/classes/_statefulset.tpl @@ -51,3 +51,4 @@ spec: spec: {{- include "ix.v1.common.lib.workload.pod" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 6 }} {{- end -}} +{{/* TODO: VCT */}} diff --git a/library/common/1.0.0/templates/lib/storage/_accessModes.tpl b/library/common/1.0.0/templates/lib/storage/_accessModes.tpl new file mode 100644 index 0000000000..38e31b01ca --- /dev/null +++ b/library/common/1.0.0/templates/lib/storage/_accessModes.tpl @@ -0,0 +1,31 @@ +{{/* PVC - Access Modes */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.pvc.accessModes" (dict "rootCtx" $rootCtx "objectData" $objectData) -}} +rootCtx: The root context of the pvc +objectData: The object data of the pvc +*/}} + +{{- define "ix.v1.common.lib.pvc.accessModes" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + + {{- $accessModes := $objectData.accessModes -}} + + {{- if kindIs "string" $accessModes -}} + {{- $accessModes = (list $accessModes) -}} + {{- end -}} + + {{- if not $accessModes -}} + {{- $accessModes = $rootCtx.Values.fallbackDefaults.pvcAccessModes -}} + {{- end -}} + + {{- $validAccessModes := (list "ReadWriteOnce" "ReadOnlyMany" "ReadWriteMany" "ReadWriteOncePod") -}} + + {{- range $accessModes -}} + {{- $mode := tpl . $rootCtx -}} + {{- if not (mustHas $mode $validAccessModes) -}} + {{- fail (printf "PVC - Expected entry to be one of [%s], but got [%s]" (join ", " $validAccessModes) $mode) -}} + {{- end }} +- {{ $mode }} + {{- end -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/storage/_storageClassName.tpl b/library/common/1.0.0/templates/lib/storage/_storageClassName.tpl new file mode 100644 index 0000000000..bfe17fe889 --- /dev/null +++ b/library/common/1.0.0/templates/lib/storage/_storageClassName.tpl @@ -0,0 +1,53 @@ +{{/* PVC - Storage Class Name */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.pvc.storageClassName" (dict "rootCtx" $rootCtx "objectData" $objectData) -}} +rootCtx: The root context of the pvc +objectData: The object data of the pvc +*/}} +{{- define "ix.v1.common.lib.pvc.storageClassName" -}} + {{- $objectData := .objectData -}} + {{- $rootCtx := .rootCtx -}} + + {{/* + If storageClass is defined on the objectData: (Takes precedence over ixChartContext and fallbackDefaults) + * "-" returns "", which means requesting a PV without class + * "SCALE-ZFS" returns the value set on Values.global.ixChartContext.storageClassName + (*) "SCALE-SMB" returns the value set on Values.global.ixChartContext.smbStorageClassName (Example for the future) + * Else return the original defined storageClass + + Else if we are in an ixChartContext, always return the storageClassName defined on the ixChartContext + + Else if there is a storageClass defined in Values.fallbackDefaults.storageClass, return this + + In any other case, return nothing + */}} + + {{- $className := "" -}} + {{- if $objectData.storageClass -}} + {{- $storageClass := (tpl $objectData.storageClass $rootCtx) -}} + + {{- if eq "-" $storageClass -}} + {{- $className = "\"\"" -}} + {{- else if eq "SCALE-ZFS" $storageClass -}} + {{- if not $rootCtx.Values.global.ixChartContext.storageClassName -}} + {{- fail "PVC - Expected non-empty on [SCALE-ZFS] storageClass" -}} + {{- end -}} + {{- $className = tpl $rootCtx.Values.global.ixChartContext.storageClassName $rootCtx -}} + {{- else -}} + {{- $className = tpl $storageClass $rootCtx -}} + {{- end -}} + + {{- else if $rootCtx.Values.global.ixChartContext -}} + {{- if not $rootCtx.Values.global.ixChartContext.storageClassName -}} + {{- fail "PVC - Expected non-empty " -}} + {{- end -}} + {{- $className = tpl $rootCtx.Values.global.ixChartContext.storageClassName $rootCtx -}} + + {{- else if $rootCtx.Values.fallbackDefaults.storageClass -}} + + {{- $className = tpl $rootCtx.Values.fallbackDefaults.storageClass $rootCtx -}} + + {{- end -}} + + {{- $className -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/storage/_validation.tpl b/library/common/1.0.0/templates/lib/storage/_validation.tpl new file mode 100644 index 0000000000..9e4831ff61 --- /dev/null +++ b/library/common/1.0.0/templates/lib/storage/_validation.tpl @@ -0,0 +1,30 @@ +{{/* PVC Validation */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.persistence.validation" (dict "objectData" $objectData) -}} +objectData: + rootCtx: The root context. + objectData: The service object. +*/}} + +{{- define "ix.v1.common.lib.persistence.validation" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + + {{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}} + {{- fail (printf "Persistence - Expected to be a dictionary, but got [%v]" (kindOf $objectData.labels)) -}} + {{- end -}} + + {{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}} + {{- fail (printf "Persistence - Expected to be a dictionary, but got [%v]" (kindOf $objectData.annotations)) -}} + {{- end -}} + + {{- $types := (list "pvc" "emptyDir" "nfs" "hostPath" "ixVolume" "secret" "configmap") -}} + {{- if not (mustHas $objectData.type $types) -}} + {{- fail (printf "Persistence - Expected to be one of [%s], but got [%s]" (join ", " $types) $objectData.type) -}} + {{- end -}} + + {{- if and $objectData.targetSelector (not (kindIs "map" $objectData.targetSelector)) -}} + {{- fail (printf "Persistence - Expected to be [dict], but got [%s]" (kindOf $objectData.targetSelector)) -}} + {{- end -}} + +{{- end -}} diff --git a/library/common/1.0.0/templates/loader/_apply.tpl b/library/common/1.0.0/templates/loader/_apply.tpl index eaff583191..6176d55def 100644 --- a/library/common/1.0.0/templates/loader/_apply.tpl +++ b/library/common/1.0.0/templates/loader/_apply.tpl @@ -22,4 +22,7 @@ {{/* Render Services(s) */}} {{- include "ix.v1.common.spawner.service" . | nindent 0 -}} + {{/* Render PVC(s) */}} + {{- include "ix.v1.common.spawner.pvc" . | nindent 0 -}} + {{- end -}} diff --git a/library/common/1.0.0/templates/spawner/_pvc.tpl b/library/common/1.0.0/templates/spawner/_pvc.tpl new file mode 100644 index 0000000000..ee74c2c0e2 --- /dev/null +++ b/library/common/1.0.0/templates/spawner/_pvc.tpl @@ -0,0 +1,39 @@ +{{/* PVC Spawwner */}} +{{/* Call this template: +{{ include "ix.v1.common.spawner.pvc" $ -}} +*/}} + +{{- define "ix.v1.common.spawner.pvc" -}} + + {{- range $name, $persistence := .Values.persistence -}} + + {{- if $persistence.enabled -}} + + {{/* Create a copy of the persistence */}} + {{- $objectData := (mustDeepCopy $persistence) -}} + + {{ $_ := set $objectData "type" ($objectData.type | default $.Values.fallbackDefaults.persistenceType) }} + + {{/* Perform general validations */}} + {{- include "ix.v1.common.lib.persistence.validation" (dict "rootCtx" $ "objectData" $objectData) -}} + + {{/* Only spawn PVC if it's enabled and type of "pvc" */}} + {{- if eq "pvc" $objectData.type -}} + + {{- $objectName := (printf "%s-%s" (include "ix.v1.common.lib.chart.names.fullname" $) $name) -}} + {{/* Perform validations */}} + {{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}} + + {{/* Set the name of the secret */}} + {{- $_ := set $objectData "name" $objectName -}} + {{- $_ := set $objectData "shortName" $name -}} + + {{/* Call class to create the object */}} + {{- include "ix.v1.common.class.pvc" (dict "rootCtx" $ "objectData" $objectData) -}} + + {{- end -}} + {{- end -}} + + {{- end -}} + +{{- end -}} diff --git a/library/common/1.0.0/values.yaml b/library/common/1.0.0/values.yaml index 59004d000d..8b9e8dbc74 100644 --- a/library/common/1.0.0/values.yaml +++ b/library/common/1.0.0/values.yaml @@ -10,8 +10,6 @@ global: addTraefikAnnotations: false # -- Minimum nodePort value minNodePort: 9000 - # -- Scale Storage Class - scaleZFSStorageClass: '{{ printf "ix-storage-class-%v" .Release.Name }}' # TODO: fallbackDefaults: @@ -22,6 +20,15 @@ fallbackDefaults: serviceProtocol: TCP # -- Default Service Type serviceType: ClusterIP + # -- Default persistence type + persistenceType: pvc + # -- Default Retain PVC + pvcRetain: false + # -- Default PVC Size + pvcSize: 1Gi + # -- Default PVC Access Modes + pvcAccessModes: + - ReadWriteOnce # -- Injected from SCALE middleware # Only for reference here @@ -120,96 +127,97 @@ persistence: enabled: true type: emptyDir mountPath: /shared - targetSelector: all + targetSelectAll: true varlogs: enabled: true type: emptyDir mountPath: /var/logs - targetSelector: all + targetSelectAll: true tmp: enabled: true type: emptyDir mountPath: /tmp - targetSelector: all + targetSelectAll: true devshm: # TODO: Enable by default? enabled: false type: emptyDir mountPath: /dev/shm - targetSelector: all - # -- Volume name - vol-name: - # -- Enables the volume - enabled: false - # -- Type of volume - type: type - # -- Volume Options + targetSelectAll: true - # - ConfigMap, Secret - # Default Mode (ConfigMap, Secret) - defaultMode: "0600" - # Items (ConfigMap, Secret) - items: - - key: key - path: path + # # -- Volume name + # vol-name: + # # -- Enables the volume + # enabled: false + # # -- Type of volume + # type: type + # # -- Volume Options - # - EmptyDir - # Medium - medium: Memory - # SizeLimit - size: 1Gi + # # - ConfigMap, Secret + # # Default Mode (ConfigMap, Secret) + # defaultMode: "0600" + # # Items (ConfigMap, Secret) + # items: + # - key: key + # path: path - # - HostPath - # Host Path - hostPath: /path/to/host - # Host Path Type - hostPathType: DirectoryOrCreate + # # - EmptyDir + # # Medium + # medium: Memory + # # SizeLimit + # size: 1Gi - # - NFS - # Server - server: nfs-server - # Path - path: /path/to/nfs + # # - HostPath + # # Host Path + # hostPath: /path/to/host + # # Host Path Type + # hostPathType: DirectoryOrCreate - # - ixVolumes - # datasetName - datasetName: dataset-name - # Host Path Type - # hostPathType: DirectoryOrCreate + # # - NFS + # # Server + # server: nfs-server + # # Path + # path: /path/to/nfs - # - PVC - # labels (Only for PVC type) - labels: {} - # annotations (Only for PVC type) - annotations: {} - # Size - # size: 1Gi - # Retain - retain: false - # Storage Class - storageClassName: "" - # Existing Claim - existingClaim: "" - # VolumeName - volumeName: "" - # Access Modes - accessModes: - - ReadWriteOnce - # -- Options that apply to all volumeMounts - # Can be overruled per volumeMount under targetSelector - mountPath: /shared - readOnly: False - subPath: "" - mountPropagation: "" - # Where to define the volume and mount the volume - # targetSelector: all - targetSelector: - pod-name: - container-name: - mountPath: /shared - readOnly: False - subPath: "" - mountPropagation: "" + # # - ixVolumes + # # datasetName + # datasetName: dataset-name + # # Host Path Type + # # hostPathType: DirectoryOrCreate + + # # - PVC + # # labels (Only for PVC type) + # labels: {} + # # annotations (Only for PVC type) + # annotations: {} + # # Size + # # size: 1Gi + # # Retain + # retain: false + # # Storage Class + # storageClassName: "" + # # Existing Claim + # existingClaim: "" + # # VolumeName + # volumeName: "" + # # Access Modes + # accessModes: + # - ReadWriteOnce + # # -- Options that apply to all volumeMounts + # # Can be overruled per volumeMount under targetSelector + # mountPath: /shared + # readOnly: False + # subPath: "" + # mountPropagation: "" + # # Where to define the volume and mount the volume + # # targetSelector: all + # targetSelector: + # pod-name: + # container-name: + # mountPath: /shared + # readOnly: False + # subPath: "" + # mountPropagation: "" # -- Service service: