From 10dbee3a8519791bea3974150a7afd410cba68af Mon Sep 17 00:00:00 2001 From: Yosef Mihretie Date: Mon, 24 Feb 2025 15:55:50 -0500 Subject: [PATCH] allow mounting several efs volumes from one efs file system --- applications/web/templates/_helpers.tpl | 12 ++++++++++++ applications/web/templates/deployment.yaml | 10 +++++----- applications/web/templates/efs-storage-class.yaml | 9 +++++---- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/applications/web/templates/_helpers.tpl b/applications/web/templates/_helpers.tpl index b3163fc6f..cd47334f9 100644 --- a/applications/web/templates/_helpers.tpl +++ b/applications/web/templates/_helpers.tpl @@ -115,4 +115,16 @@ Otherwise, use the default path /data/efs/ {{- else -}} {{- printf "/data/efs/%s" .fullname -}} {{- end -}} +{{- end -}} + +{{/* +Get the EFS resource name. If index is 0, don't append it to the name. +*/}} +{{- define "docker-template.efsName" -}} +{{- $name := printf "efs-%s" .fullname -}} +{{- if ne (.index | int) 0 -}} +{{- printf "%s-%d" $name (.index | int) -}} +{{- else -}} +{{- $name -}} +{{- end -}} {{- end -}} \ No newline at end of file diff --git a/applications/web/templates/deployment.yaml b/applications/web/templates/deployment.yaml index 7aac6abd8..0e3d12121 100644 --- a/applications/web/templates/deployment.yaml +++ b/applications/web/templates/deployment.yaml @@ -410,8 +410,8 @@ spec: {{ end }} {{ if .Values.awsEfsStorage }} volumeMounts: - {{- range $v := .Values.awsEfsStorage }} - - name: efs-{{ $.Values.fullnameOverride }} + {{- range $index, $v := .Values.awsEfsStorage }} + - name: {{ include "docker-template.efsName" (dict "fullname" $.Values.fullnameOverride "index" $index) }} mountPath: {{ include "docker-template.efsMountPath" (dict "mountPath" $v.mountPath "fullname" $.Values.fullnameOverride) }} {{ end }} {{ end }} @@ -538,10 +538,10 @@ spec: {{- toYaml .Values.emptyDir.volumeOptions | nindent 12 }} {{ end }} {{ if .Values.awsEfsStorage }} - {{- range $v := .Values.awsEfsStorage }} - - name: efs-{{ $.Values.fullnameOverride }} + {{- range $index, $v := .Values.awsEfsStorage }} + - name: {{ include "docker-template.efsName" (dict "fullname" $.Values.fullnameOverride "index" $index) }} persistentVolumeClaim: - claimName: efs-{{ $.Values.fullnameOverride }} + claimName: {{ include "docker-template.efsName" (dict "fullname" $.Values.fullnameOverride "index" $index) }} {{ end }} {{ end }} {{ if .Values.fileSecretMounts.enabled }} diff --git a/applications/web/templates/efs-storage-class.yaml b/applications/web/templates/efs-storage-class.yaml index 6ecd6ca6f..6a018d27d 100644 --- a/applications/web/templates/efs-storage-class.yaml +++ b/applications/web/templates/efs-storage-class.yaml @@ -1,9 +1,9 @@ {{ if .Values.awsEfsStorage }} -{{- range $v := .Values.awsEfsStorage }} +{{- range $index, $v := .Values.awsEfsStorage }} kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: - name: efs-{{ $.Values.fullnameOverride }} + name: {{ include "docker-template.efsName" (dict "fullname" $.Values.fullnameOverride "index" $index) }} provisioner: efs.csi.aws.com parameters: provisioningMode: efs-ap @@ -14,13 +14,14 @@ parameters: apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: efs-{{ $.Values.fullnameOverride }} + name: {{ include "docker-template.efsName" (dict "fullname" $.Values.fullnameOverride "index" $index) }} spec: accessModes: - ReadWriteMany - storageClassName: efs-{{ $.Values.fullnameOverride }} + storageClassName: {{ include "docker-template.efsName" (dict "fullname" $.Values.fullnameOverride "index" $index) }} resources: requests: storage: 5Gi +--- {{- end }} {{- end }}