_pvc.tpl 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. {{- $size := $objectData.size | default $.Values.fallbackDefaults.pvcSize -}}
  33. {{- $hashValues := (printf "%s-%s-%s" $size $objectData.server $objectData.share) -}}
  34. {{- if $objectData.domain -}}
  35. {{- $hashValues = (printf "%s-%s" $hashValues $objectData.domain) -}}
  36. {{- end -}}
  37. {{/* Create a unique name taking into account server and share,
  38. without this, changing one of those values is not possible */}}
  39. {{- $hash := adler32sum $hashValues -}}
  40. {{- $_ := set $objectData "name" (printf "%s-%v" $objectName $hash) -}}
  41. {{- $_ := set $objectData "provisioner" "smb.csi.k8s.io" -}}
  42. {{- $_ := set $objectData "driver" "smb.csi.k8s.io" -}}
  43. {{- $_ := set $objectData "storageClass" $objectData.name -}}
  44. {{/* Create secret with creds */}}
  45. {{- $secretData := (dict
  46. "name" $objectData.name
  47. "labels" ($objectData.labels | default dict)
  48. "annotations" ($objectData.annotations | default dict)
  49. "data" (dict "username" $objectData.username "password" $objectData.password)
  50. ) -}}
  51. {{- with $objectData.domain -}}
  52. {{- $_ := set $secretData.data "domain" . -}}
  53. {{- end -}}
  54. {{- include "ix.v1.common.class.secret" (dict "rootCtx" $ "objectData" $secretData) -}}
  55. {{/* Create the PV */}}
  56. {{- include "ix.v1.common.class.pv" (dict "rootCtx" $ "objectData" $objectData) -}}
  57. {{- else if eq $objectData.type "nfs-pv-pvc" -}}
  58. {{/* Validate NFS CSI */}}
  59. {{- include "ix.v1.common.lib.storage.nfsCSI.validation" (dict "rootCtx" $ "objectData" $objectData) -}}
  60. {{- $size := $objectData.size | default $.Values.fallbackDefaults.pvcSize -}}
  61. {{- $hashValues := (printf "%s-%s-%s" $size $objectData.server $objectData.share) -}}
  62. {{/* Create a unique name taking into account server and share,
  63. without this, changing one of those values is not possible */}}
  64. {{- $hash := adler32sum $hashValues -}}
  65. {{- $_ := set $objectData "name" (printf "%s-%v" $objectName $hash) -}}
  66. {{- $_ := set $objectData "provisioner" "nfs.csi.k8s.io" -}}
  67. {{- $_ := set $objectData "driver" "nfs.csi.k8s.io" -}}
  68. {{- $_ := set $objectData "storageClass" $objectData.name -}}
  69. {{/* Create the PV */}}
  70. {{- include "ix.v1.common.class.pv" (dict "rootCtx" $ "objectData" $objectData) -}}
  71. {{- end -}}
  72. {{/* Call class to create the object */}}
  73. {{- include "ix.v1.common.class.pvc" (dict "rootCtx" $ "objectData" $objectData) -}}
  74. {{- end -}}
  75. {{- end -}}
  76. {{- end -}}
  77. {{- end -}}