_pvc.tpl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {{/* PVC Spawwner */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.spawner.pvc" $ -}}
  4. */}}
  5. {{- define "ix.v1.common.spawner.pvc" -}}
  6. {{- range $name, $persistence := .Values.persistence -}}
  7. {{- if $persistence.enabled -}}
  8. {{/* Create a copy of the persistence */}}
  9. {{- $objectData := (mustDeepCopy $persistence) -}}
  10. {{- $_ := set $objectData "type" ($objectData.type | default $.Values.fallbackDefaults.persistenceType) -}}
  11. {{/* Perform general validations */}}
  12. {{- include "ix.v1.common.lib.persistence.validation" (dict "rootCtx" $ "objectData" $objectData) -}}
  13. {{- include "ix.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Persistence") -}}
  14. {{/*
  15. Naming scheme on pvc types:
  16. pvc creates a PVC with the default StorageClass (Useful for CI or testing on local cluster)
  17. ix-zfs-pvc creates a PVC and is dependent on iX values injection (eg StorageClass)
  18. smb-pv-pvc creates a PV and PVC (This still checks for iX values, but only when running in SCALE)
  19. nfs-pv-pvc creates a PV and PVC (This still checks for iX values, but only when running in SCALE)
  20. */}}
  21. {{/* Only spawn PVC if its enabled and any type of "pvc" */}}
  22. {{- if and (mustHas $objectData.type (list "smb-pv-pvc" "nfs-pv-pvc" "ix-zfs-pvc" "pvc")) (not $objectData.existingClaim) -}}
  23. {{- $objectName := (printf "%s-%s" (include "ix.v1.common.lib.chart.names.fullname" $) $name) -}}
  24. {{/* Perform validations */}}
  25. {{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}}
  26. {{/* Set the name of the secret */}}
  27. {{- $_ := set $objectData "name" $objectName -}}
  28. {{- $_ := set $objectData "shortName" $name -}}
  29. {{- if eq $objectData.type "smb-pv-pvc" -}}
  30. {{/* Validate SMB CSI */}}
  31. {{- include "ix.v1.common.lib.storage.smbCSI.validation" (dict "rootCtx" $ "objectData" $objectData) -}}
  32. {{- $hashValues := (printf "%s-%s" $objectData.server $objectData.share) -}}
  33. {{- if $objectData.domain -}}
  34. {{- $hashValues = (printf "%s-%s" $hashValues $objectData.domain) -}}
  35. {{- end -}}
  36. {{/* Create a unique name taking into account server and share,
  37. without this, changing one of those values is not possible */}}
  38. {{- $hash := adler32sum $hashValues -}}
  39. {{- $_ := set $objectData "name" (printf "%s-%v" $objectName $hash) -}}
  40. {{- $_ := set $objectData "provisioner" "smb.csi.k8s.io" -}}
  41. {{- $_ := set $objectData "driver" "smb.csi.k8s.io" -}}
  42. {{- $_ := set $objectData "storageClass" $objectData.name -}}
  43. {{/* Create secret with creds */}}
  44. {{- $secretData := (dict
  45. "name" $objectData.name
  46. "labels" ($objectData.labels | default dict)
  47. "annotations" ($objectData.annotations | default dict)
  48. "data" (dict "username" $objectData.username "password" $objectData.password)
  49. ) -}}
  50. {{- with $objectData.domain -}}
  51. {{- $_ := set $secretData.data "domain" . -}}
  52. {{- end -}}
  53. {{- include "ix.v1.common.class.secret" (dict "rootCtx" $ "objectData" $secretData) -}}
  54. {{/* Create the PV */}}
  55. {{- include "ix.v1.common.class.pv" (dict "rootCtx" $ "objectData" $objectData) -}}
  56. {{- else if eq $objectData.type "nfs-pv-pvc" -}}
  57. {{/* Validate NFS CSI */}}
  58. {{- include "ix.v1.common.lib.storage.nfsCSI.validation" (dict "rootCtx" $ "objectData" $objectData) -}}
  59. {{- $hashValues := (printf "%s-%s" $objectData.server $objectData.share) -}}
  60. {{/* Create a unique name taking into account server and share,
  61. without this, changing one of those values is not possible */}}
  62. {{- $hash := adler32sum $hashValues -}}
  63. {{- $_ := set $objectData "name" (printf "%s-%v" $objectName $hash) -}}
  64. {{- $_ := set $objectData "provisioner" "nfs.csi.k8s.io" -}}
  65. {{- $_ := set $objectData "driver" "nfs.csi.k8s.io" -}}
  66. {{- $_ := set $objectData "storageClass" $objectData.name -}}
  67. {{/* Create the PV */}}
  68. {{- include "ix.v1.common.class.pv" (dict "rootCtx" $ "objectData" $objectData) -}}
  69. {{- end -}}
  70. {{/* Call class to create the object */}}
  71. {{- include "ix.v1.common.class.pvc" (dict "rootCtx" $ "objectData" $objectData) -}}
  72. {{- end -}}
  73. {{- end -}}
  74. {{- end -}}
  75. {{- end -}}