_persistentVolume.tpl 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {{/* PersistentVolume Class */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.class.pv" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData:
  6. name: The name of the PV.
  7. labels: The labels of the PV.
  8. annotations: The annotations of the PV.
  9. provisioner: The provisioner to use for the PersistentVolume.
  10. driver: The driver to use for the csi
  11. retain: Whether to retain the PV after deletion. (Default: false)
  12. size: The size of the PersistentVolume. (Default: 1Gi)
  13. */}}
  14. {{- define "ix.v1.common.class.pv" -}}
  15. {{- $rootCtx := .rootCtx -}}
  16. {{- $objectData := .objectData -}}
  17. {{- $retain := $rootCtx.Values.fallbackDefaults.pvcRetain -}}
  18. {{- if (kindIs "bool" $objectData.retain) -}}
  19. {{- $retain = $objectData.retain -}}
  20. {{- end -}}
  21. {{- $reclaimPolicy := ternary "Retain" "Delete" $retain -}}
  22. {{- $pvcSize := $rootCtx.Values.fallbackDefaults.pvcSize -}}
  23. {{- with $objectData.size -}}
  24. {{- $pvcSize = tpl . $rootCtx -}}
  25. {{- end }}
  26. ---
  27. apiVersion: v1
  28. kind: PersistentVolume
  29. metadata:
  30. name: {{ $objectData.name }}
  31. {{- $labels := (mustMerge ($objectData.labels | default dict) (include "ix.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}}
  32. {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }}
  33. labels:
  34. {{- . | nindent 4 }}
  35. {{- end -}}
  36. {{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "ix.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
  37. {{- if $retain -}}
  38. {{- $_ := set $annotations "\"helm.sh/resource-policy\"" "keep" -}}
  39. {{- end -}}
  40. {{- $_ := set $annotations "pv.kubernetes.io/provisioned-by" $objectData.provisioner -}}
  41. {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }}
  42. annotations:
  43. {{- . | nindent 4 }}
  44. {{- end }}
  45. spec:
  46. capacity:
  47. storage: {{ $pvcSize }}
  48. persistentVolumeReclaimPolicy: {{ $reclaimPolicy }}
  49. storageClassName: {{ $objectData.name }}
  50. accessModes:
  51. {{- include "ix.v1.common.lib.pvc.accessModes" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "Persistent Volume") | trim | nindent 4 -}}
  52. {{- if $objectData.mountOptions }}
  53. mountOptions:
  54. {{- range $opt := $objectData.mountOptions -}}
  55. {{- if $opt.value }}
  56. - {{ printf "%s=%s" (tpl $opt.key $rootCtx) (tpl (include "ix.v1.common.helper.makeIntOrNoop" $opt.value) $rootCtx) }}
  57. {{- else }}
  58. - {{ tpl $opt.key $rootCtx }}
  59. {{- end -}}
  60. {{- end -}}
  61. {{- end -}}
  62. {{- if eq "smb-pv-pvc" $objectData.type -}}
  63. {{- include "ix.v1.common.lib.storage.smbCSI" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 -}}
  64. {{- else if eq "nfs-pv-pvc" $objectData.type -}}
  65. {{- include "ix.v1.common.lib.storage.nfsCSI" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 -}}
  66. {{- end -}}
  67. {{- end -}}