diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index 0a787c5..f32cb7f 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -26,6 +26,30 @@ spec: securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: + {{- if and .Values.nfs.enabled .Values.nfs.softFail }} + - name: nfs-mounter + image: alpine:3.20 + securityContext: + capabilities: + add: + - SYS_ADMIN + command: + - /bin/sh + - -c + - | + apk add --no-cache nfs-utils 2>/dev/null || { echo "Cannot install nfs-utils, skipping NFS mount."; exec sleep infinity; } + echo "Attempting NFS mount {{ .Values.nfs.server }}:{{ .Values.nfs.path }}..." + if timeout 30 mount -t nfs -o timeo=10,soft,retrans=2 {{ .Values.nfs.server }}:{{ .Values.nfs.path }} /mnt/shared; then + echo "NFS mounted successfully. Files are served directly from NFS." + else + echo "NFS mount failed or timed out, continuing with empty directory." + fi + exec sleep infinity + volumeMounts: + - name: public-files + mountPath: /mnt/shared + mountPropagation: Bidirectional + {{- end }} - name: {{ .Chart.Name }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} @@ -58,12 +82,19 @@ spec: volumeMounts: - name: public-files mountPath: {{ .Values.nfs.mountPath }} + {{- if .Values.nfs.softFail }} + mountPropagation: HostToContainer + {{- end }} {{- end }} - {{- if .Values.nfs.enabled }} + {{- if and .Values.nfs.enabled (not .Values.nfs.softFail) }} volumes: - name: public-files persistentVolumeClaim: claimName: {{ include "vhaudiquet-fr.fullname" . }}-public + {{- else if and .Values.nfs.enabled .Values.nfs.softFail }} + volumes: + - name: public-files + emptyDir: {} {{- end }} {{- with .Values.nodeSelector }} nodeSelector: diff --git a/chart/templates/persistentvolume.yaml b/chart/templates/persistentvolume.yaml index 7d67172..d78ca87 100644 --- a/chart/templates/persistentvolume.yaml +++ b/chart/templates/persistentvolume.yaml @@ -1,4 +1,4 @@ -{{- if .Values.nfs.enabled -}} +{{- if and .Values.nfs.enabled (not .Values.nfs.softFail) -}} apiVersion: v1 kind: PersistentVolume metadata: diff --git a/chart/templates/persistentvolumeclaim.yaml b/chart/templates/persistentvolumeclaim.yaml index 861bb53..ef8c264 100644 --- a/chart/templates/persistentvolumeclaim.yaml +++ b/chart/templates/persistentvolumeclaim.yaml @@ -1,4 +1,4 @@ -{{- if .Values.nfs.enabled -}} +{{- if and .Values.nfs.enabled (not .Values.nfs.softFail) -}} apiVersion: v1 kind: PersistentVolumeClaim metadata: diff --git a/chart/values.yaml b/chart/values.yaml index 2e56ae7..0672db4 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -104,3 +104,10 @@ nfs: storageSize: 10Gi # Storage class name (leave empty for default) storageClassName: "" + # When true, use a sidecar container with mount propagation instead of PV/PVC + # so the pod can still start if the NFS server is unreachable. The sidecar + # will attempt to mount NFS directly into the shared volume; if it fails the + # app runs with an empty public directory. Files are served directly from NFS + # (no copying), making this suitable for large volumes. + # Requires: SYS_ADMIN capability on the sidecar, mountPropagation support. + softFail: false