_storageClassName.tpl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. {{/* PVC - Storage Class Name */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.storage.storageClassName" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
  4. rootCtx: The root context of the chart.
  5. objectData: The object data of the pvc
  6. */}}
  7. {{- define "ix.v1.common.lib.storage.storageClassName" -}}
  8. {{- $objectData := .objectData -}}
  9. {{- $rootCtx := .rootCtx -}}
  10. {{- $caller := .caller -}}
  11. {{/*
  12. If type is "ix-zfs-pvc":
  13. Return the value set .Values.global.ixChartContext.storageClassName
  14. If storageClass is defined on the objectData:
  15. If the value is "-" (dash):
  16. Return ""
  17. Else:
  18. Return the original defined storageClass (smb-pv-pvc and nfs-pv-pvc will fall into this case)
  19. Else if there is a storageClass defined in .Values.fallbackDefaults.storageClass: (Default is "")
  20. Return this
  21. */}}
  22. {{- $className := "" -}}
  23. {{- if eq "ix-zfs-pvc" $objectData.type -}}
  24. {{- if not $rootCtx.Values.global.ixChartContext.storageClassName -}}
  25. {{- fail (printf "%s - Expected non-empty <global.ixChartContext.storageClassName> on [ix-zfs-pvc] type" $caller) -}}
  26. {{- end -}}
  27. {{- $className = tpl $rootCtx.Values.global.ixChartContext.storageClassName $rootCtx -}}
  28. {{- else if $objectData.storageClass -}}
  29. {{- $className = (tpl $objectData.storageClass $rootCtx) -}}
  30. {{- else if $rootCtx.Values.fallbackDefaults.storageClass -}} {{/* Probably useful in CI scenarios */}}
  31. {{- $className = tpl $rootCtx.Values.fallbackDefaults.storageClass $rootCtx -}}
  32. {{- end -}}
  33. {{/*
  34. Empty value on storageClasName key means no storageClass
  35. While absent storageClasName key means use the default storageClass
  36. Because helm strips "", we need to use "-" to represent empty value
  37. */}}
  38. {{- if $className -}}
  39. {{- if eq "-" $className }}
  40. storageClassName: ""
  41. {{- else }}
  42. storageClassName: {{ $className }}
  43. {{- end -}}
  44. {{- end -}}
  45. {{- end -}}