From 548bc52ae77db6ee087b28a47d203aada3a647da Mon Sep 17 00:00:00 2001 From: Majed Takieddine Date: Thu, 1 Aug 2024 12:36:11 -0500 Subject: [PATCH 1/6] add pvc support --- stack/templates/_helpers.tpl | 8 ++++++++ stack/templates/deployment.yaml | 21 +++++++++++++++++---- stack/templates/pvc.yaml | 33 +++++++++++++++++++++++++++++++++ stack/values.yaml | 8 ++++++++ 4 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 stack/templates/pvc.yaml diff --git a/stack/templates/_helpers.tpl b/stack/templates/_helpers.tpl index a5a3b42..0622a52 100644 --- a/stack/templates/_helpers.tpl +++ b/stack/templates/_helpers.tpl @@ -103,3 +103,11 @@ image: {{ .Values.image }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" {{- end }} {{- end }} + +{{- define "service.claimName" -}} +{{- if and .Values.persistence.existingClaim }} + {{- printf "%s" (tpl .Values.persistence.existingClaim $) -}} +{{- else -}} + {{- printf "%s" (include "service.fullname" .) -}} +{{- end -}} +{{- end -}} diff --git a/stack/templates/deployment.yaml b/stack/templates/deployment.yaml index 140cfe0..013dda2 100644 --- a/stack/templates/deployment.yaml +++ b/stack/templates/deployment.yaml @@ -71,9 +71,15 @@ spec: {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.volumeMounts }} + {{- if or .Values.persistence.enabled .Values.volumeMounts}} volumeMounts: - {{- toYaml . | nindent 12 }} + {{- if .Values.persistence.enabled }} + - name: data + mountPath: {{ .Values.persistence.mountPath }} + {{- end }} + {{- if .Values.volumeMounts }} + {{- toYaml .Values.volumeMounts | nindent 8 }} + {{- end }} {{- end }} {{- include "service.configuration" . | nindent 10}} {{- include "service.nonsensitiveEnvVars" (list $global.Values.global .Values) | nindent 10 }} @@ -96,9 +102,16 @@ spec: {{- end }} dnsPolicy: {{ .Values.dnsPolicy }} restartPolicy: {{ .Values.restartPolicy }} - {{- with .Values.volumes }} + {{- if or .Values.persistence.enabled .Values.volumes}} volumes: - {{- toYaml . | nindent 8 }} + {{- if .Values.persistence.enabled }} + - name: data + persistentVolumeClaim: + claimName: {{ include "service.claimName" . }} + {{- end }} + {{- if .Values.volumes }} + {{- toYaml .Values.volumes | nindent 8 }} + {{- end }} {{- end }} {{- with .Values.nodeSelector }} nodeSelector: diff --git a/stack/templates/pvc.yaml b/stack/templates/pvc.yaml new file mode 100644 index 0000000..038d890 --- /dev/null +++ b/stack/templates/pvc.yaml @@ -0,0 +1,33 @@ +{{ $global := . }} +{{ range $serviceName, $serviceValues := .Values.services }} + {{- $globalValuesDict := $global.Values.global | toYaml -}} + {{- $values := fromYaml $globalValuesDict -}} + {{- $values = set $values "name" $serviceName -}} + {{- $values := mergeOverwrite $values $serviceValues -}} + {{- $service := dict "Chart" $global.Chart "Release" $global.Release "Capabilities" $global.Capabilities "Values" $values -}} +{{- with $service -}} +--- +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ include "service.fullname" . }} + labels: + {{- include "service.labels" . | nindent 4 }} + annotations: + {{- include "stack.annotations" $service | nindent 4 }} +spec: + accessModes: + {{- range .Values.persistence.accessModes }} + - {{ . | quote }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.size | quote }} + {{- if .Values.persistence.storageClass }} + storageClassName: {{ .Values.persistence.storageClass }} + {{- end }} +{{- end }} +--- +{{- end }} +{{- end }} \ No newline at end of file diff --git a/stack/values.yaml b/stack/values.yaml index 9a08285..30c47a8 100644 --- a/stack/values.yaml +++ b/stack/values.yaml @@ -169,6 +169,14 @@ global: env: [] envFrom: [] + persistence: + enabled: false + storageClass: "" + accessModes: + - ReadWriteOnce + size: 8Gi + existingClaim: "" + mountPath: "" # Service overrides services: {} From bef716651aba494c2d88b37b87832ac7d0967102 Mon Sep 17 00:00:00 2001 From: Majed Takieddine <164077035+mt-czi@users.noreply.github.com> Date: Thu, 1 Aug 2024 12:40:43 -0500 Subject: [PATCH 2/6] remove trailing and Co-authored-by: Hayden Spitzley <105455169+hspitzley-czi@users.noreply.github.com> --- stack/templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack/templates/_helpers.tpl b/stack/templates/_helpers.tpl index 0622a52..b6332f8 100644 --- a/stack/templates/_helpers.tpl +++ b/stack/templates/_helpers.tpl @@ -105,7 +105,7 @@ image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.App {{- end }} {{- define "service.claimName" -}} -{{- if and .Values.persistence.existingClaim }} +{{- if .Values.persistence.existingClaim }} {{- printf "%s" (tpl .Values.persistence.existingClaim $) -}} {{- else -}} {{- printf "%s" (include "service.fullname" .) -}} From 7d10a11daba59c83ae488ae4c72b6fcb53eafca2 Mon Sep 17 00:00:00 2001 From: Majed Takieddine Date: Thu, 1 Aug 2024 13:05:24 -0500 Subject: [PATCH 3/6] fix indent --- stack/templates/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack/templates/deployment.yaml b/stack/templates/deployment.yaml index 013dda2..869140e 100644 --- a/stack/templates/deployment.yaml +++ b/stack/templates/deployment.yaml @@ -78,7 +78,7 @@ spec: mountPath: {{ .Values.persistence.mountPath }} {{- end }} {{- if .Values.volumeMounts }} - {{- toYaml .Values.volumeMounts | nindent 8 }} + {{- toYaml .Values.volumeMounts | nindent 12 }} {{- end }} {{- end }} {{- include "service.configuration" . | nindent 10}} From 23982c77cb7583d1ac566dd34d3f9e71203ca1a0 Mon Sep 17 00:00:00 2001 From: Majed Takieddine <164077035+mt-czi@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:00:46 -0500 Subject: [PATCH 4/6] Update stack/templates/deployment.yaml Co-authored-by: Hayden Spitzley <105455169+hspitzley-czi@users.noreply.github.com> --- stack/templates/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack/templates/deployment.yaml b/stack/templates/deployment.yaml index 82548e4..4c51e74 100644 --- a/stack/templates/deployment.yaml +++ b/stack/templates/deployment.yaml @@ -71,7 +71,7 @@ spec: {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} - {{- if or .Values.persistence.enabled .Values.volumeMounts}} + {{- if or (and .Values.persistence.enabled .Values.persistence.mountPath) .Values.volumeMounts}} volumeMounts: {{- if .Values.persistence.enabled }} - name: data From f0b4f3eb1f09c012cfda62e3228b279b5b16a528 Mon Sep 17 00:00:00 2001 From: Majed Takieddine <164077035+mt-czi@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:00:52 -0500 Subject: [PATCH 5/6] Update stack/templates/deployment.yaml Co-authored-by: Hayden Spitzley <105455169+hspitzley-czi@users.noreply.github.com> --- stack/templates/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack/templates/deployment.yaml b/stack/templates/deployment.yaml index 4c51e74..c5b5f34 100644 --- a/stack/templates/deployment.yaml +++ b/stack/templates/deployment.yaml @@ -73,7 +73,7 @@ spec: {{- toYaml .Values.resources | nindent 12 }} {{- if or (and .Values.persistence.enabled .Values.persistence.mountPath) .Values.volumeMounts}} volumeMounts: - {{- if .Values.persistence.enabled }} + {{- if and .Values.persistence.enabled .Values.persistence.mountPath) }} - name: data mountPath: {{ .Values.persistence.mountPath }} {{- end }} From 0afc7e83de289ae6b6d5cc27466fd4374061e9b1 Mon Sep 17 00:00:00 2001 From: Majed Takieddine Date: Fri, 2 Aug 2024 11:05:57 -0500 Subject: [PATCH 6/6] allow all pvc settings --- stack/templates/deployment.yaml | 2 +- stack/templates/pvc.yaml | 11 +---------- stack/values.yaml | 11 +++++++---- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/stack/templates/deployment.yaml b/stack/templates/deployment.yaml index c5b5f34..350d1ad 100644 --- a/stack/templates/deployment.yaml +++ b/stack/templates/deployment.yaml @@ -73,7 +73,7 @@ spec: {{- toYaml .Values.resources | nindent 12 }} {{- if or (and .Values.persistence.enabled .Values.persistence.mountPath) .Values.volumeMounts}} volumeMounts: - {{- if and .Values.persistence.enabled .Values.persistence.mountPath) }} + {{- if and .Values.persistence.enabled .Values.persistence.mountPath }} - name: data mountPath: {{ .Values.persistence.mountPath }} {{- end }} diff --git a/stack/templates/pvc.yaml b/stack/templates/pvc.yaml index 038d890..ce6fc04 100644 --- a/stack/templates/pvc.yaml +++ b/stack/templates/pvc.yaml @@ -17,16 +17,7 @@ metadata: annotations: {{- include "stack.annotations" $service | nindent 4 }} spec: - accessModes: - {{- range .Values.persistence.accessModes }} - - {{ . | quote }} - {{- end }} - resources: - requests: - storage: {{ .Values.persistence.size | quote }} - {{- if .Values.persistence.storageClass }} - storageClassName: {{ .Values.persistence.storageClass }} - {{- end }} + {{- toYaml .Values.persistence.pvc | nindent 2}} {{- end }} --- {{- end }} diff --git a/stack/values.yaml b/stack/values.yaml index 30c47a8..11aabcb 100644 --- a/stack/values.yaml +++ b/stack/values.yaml @@ -171,10 +171,13 @@ global: persistence: enabled: false - storageClass: "" - accessModes: - - ReadWriteOnce - size: 8Gi + pvc: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 8Gi + storageClassName: "default" existingClaim: "" mountPath: "" # Service overrides