_persistentVolumeClaim.tpl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. {{/* PersistentVolumeClaim Class */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.class.pvc" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData:
  6. name: The name of the PVC.
  7. labels: The labels of the PVC.
  8. annotations: The annotations of the PVC.
  9. size: The size of the PVC. (Default: 1Gi)
  10. volumeName: The name of the volume to bind to. (Default: "")
  11. retain: Whether to retain the PVC after deletion. (Default: false)
  12. storageClass: The storage class to use. (Absent)
  13. */}}
  14. {{- define "ix.v1.common.class.pvc" -}}
  15. {{- $rootCtx := .rootCtx -}}
  16. {{- $objectData := .objectData -}}
  17. {{- $pvcRetain := $rootCtx.Values.fallbackDefaults.pvcRetain -}}
  18. {{- if (kindIs "bool" $objectData.retain) -}}
  19. {{- $pvcRetain = $objectData.retain -}}
  20. {{- end -}}
  21. {{- $pvcSize := $rootCtx.Values.fallbackDefaults.pvcSize -}}
  22. {{- with $objectData.size -}}
  23. {{- $pvcSize = tpl . $rootCtx -}}
  24. {{- end }}
  25. ---
  26. apiVersion: v1
  27. kind: PersistentVolumeClaim
  28. metadata:
  29. name: {{ $objectData.name }}
  30. {{- $labels := (mustMerge ($objectData.labels | default dict) (include "ix.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}}
  31. {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }}
  32. labels:
  33. {{- . | nindent 4 }}
  34. {{- end -}}
  35. {{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "ix.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
  36. {{- if $pvcRetain -}}
  37. {{- $_ := set $annotations "\"helm.sh/resource-policy\"" "keep" -}}
  38. {{- end -}}
  39. {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }}
  40. annotations:
  41. {{- . | nindent 4 }}
  42. {{- end }}
  43. spec:
  44. accessModes:
  45. {{- include "ix.v1.common.lib.pvc.accessModes" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "Persistent Volume Claim") | trim | nindent 4 }}
  46. resources:
  47. requests:
  48. storage: {{ $pvcSize }}
  49. {{- with $objectData.volumeName }}
  50. volumeName: {{ tpl . $rootCtx }}
  51. {{- end -}}
  52. {{- include "ix.v1.common.lib.storage.storageClassName" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "Persistent Volume Claim") | trim | nindent 2 }}
  53. {{- end -}}