From 0409c61b01fdfdbc1d3dba29c516eabd12453650 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Thu, 1 Dec 2022 19:50:22 +0200 Subject: [PATCH] initial pvc work --- library/common/1.0.0/templates/class/_pvc.tpl | 58 +++++++++++++++++++ .../common/1.0.0/templates/loader/_apply.tpl | 2 + .../common/1.0.0/templates/spawner/_pvc.tpl | 16 +++++ 3 files changed, 76 insertions(+) create mode 100644 library/common/1.0.0/templates/class/_pvc.tpl create mode 100644 library/common/1.0.0/templates/spawner/_pvc.tpl diff --git a/library/common/1.0.0/templates/class/_pvc.tpl b/library/common/1.0.0/templates/class/_pvc.tpl new file mode 100644 index 0000000000..e8f952275c --- /dev/null +++ b/library/common/1.0.0/templates/class/_pvc.tpl @@ -0,0 +1,58 @@ +{{/* Template for pvc object, can only be called by the spawner */}} +{{/* An "pvc" object and "root" is passed from the spawner */}} +{{- define "ix.v1.common.class.pvc" -}} + {{- $pvcValues := .pvc -}} + {{- $root := .root -}} + {{- $defaultSize := $root.Values.global.ixChartContext.defaultPVCSize -}} + + {{- $pvcName := include "ix.v1.common.names.fullname" $root -}} + + {{- if and (hasKey $pvcValues "nameOverride") $pvcValues.nameOverride -}} + {{- if not (eq $pvcValues.nameOverride "-") -}} + {{- $pvcName = printf "%v-%v" $pvcName $pvcValues.nameOverride -}} + {{- end -}} + {{- end -}} + + {{- with $pvcValues.forceName -}} + {{- $pvcName = tpl . $root -}} + {{- end -}} + + {{- $accessMode := (tpl (default "ReadWriteOnce" $pvcValues.accessMode) $root) | quote -}} + {{- $size := (tpl (default $defaultSize $pvcValues.size) $root) | quote }} + +--- +apiVersion: {{ include "ix.v1.common.capabilities.pvc.apiVersion" $root }} +kind: PersistentVolumeClaim +metadata: + name: {{ $pvcName }} + {{- $labels := (mustMerge ($pvcValues.labels | default dict) (include "ix.v1.common.labels" $root | fromYaml)) -}} + {{- with (include "ix.v1.common.util.labels.render" (dict "root" $root "labels" $labels) | trim) }} + labels: + {{- . | nindent 4 }} + {{- end }} + {{- $annotations := (mustMerge ($pvcValues.annotations | default dict) (include "ix.v1.common.annotations" $root | fromYaml)) -}} + {{- with (include "ix.v1.common.util.annotations.render" (dict "root" $root "annotations" $annotations) | trim) }} + annotations: + {{- . | nindent 4 }} + {{- end }} +spec: + accessModes: + - {{ $accessMode }} + resources: + requests: + storage: {{ $size }} + {{- with $pvcValues.volumeName }} + volumeName: {{ . | quote }} + {{- end -}} + {{/* + If no storageClassName is defined, either in global or in the persistence object, + do not define storageClassName, which means use the default storageClass of the node + */}} + {{- with (include "ix.v1.common.storage.storageClassName" (dict "persistence" $pvcValues "root" $root)) | trim }} + storageClassName: {{ . }} + {{- end -}} + {{/* Pass custom spec if defined */}} + {{- with $pvcValues.spec }} + {{- tpl (toYaml .) $root | nindent 2 }} + {{- 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 9334da53e3..9dc4d0c955 100644 --- a/library/common/1.0.0/templates/loader/_apply.tpl +++ b/library/common/1.0.0/templates/loader/_apply.tpl @@ -16,4 +16,6 @@ {{- end -}} {{- include "ix.v1.common.spawner.service" . | nindent 0 -}} + + {{- 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..f6b54989a0 --- /dev/null +++ b/library/common/1.0.0/templates/spawner/_pvc.tpl @@ -0,0 +1,16 @@ +{{/* Renders the PVC objects */}} +{{- define "ix.v1.common.spawner.pvc" -}} + {{- $defaultType := .Values.global.ixChartContext.defaultPersistenceType -}} + {{- range $name, $pvc := .Values.persistence -}} + {{- if and $pvc.enabled (eq (default $defaultType $pvc.type) "pvc") (not ($pvc.existingClaim)) -}} + {{- $pvcValues := $pvc -}} + + {{/* Default to $name if there is not a nameOverride given */}} + {{- if not $pvcValues.nameOverride -}} + {{- $_ := set $pvcValues "nameOverride" $name -}} + {{- end -}} + + {{- include "ix.v1.common.class.pvc" (dict "pvc" $pvcValues "root" $) -}} + {{- end -}} + {{- end -}} +{{- end -}}