_validataionCsiSMB.tpl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. {{/* Validate SMB CSI */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.storage.smbCSI.validation" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData:
  6. driver: The name of the driver.
  7. mountOptions: The mount options.
  8. server: The server address.
  9. share: The share to the SMB share.
  10. */}}
  11. {{- define "ix.v1.common.lib.storage.smbCSI.validation" -}}
  12. {{- $rootCtx := .rootCtx -}}
  13. {{- $objectData := .objectData -}}
  14. {{- if hasKey $rootCtx.Values.global "ixChartContext" -}}
  15. {{- if not $rootCtx.Values.global.ixChartContext.hasSMBCSI -}}
  16. {{- fail "SMB CSI - Not supported CSI" -}}
  17. {{- end -}}
  18. {{- end -}}
  19. {{- $required := (list "server" "share" "username" "password") -}}
  20. {{- range $item := $required -}}
  21. {{- if not (get $objectData $item) -}}
  22. {{- fail (printf "SMB CSI - Expected <%v> to be non-empty" $item) -}}
  23. {{- end -}}
  24. {{- end -}}
  25. {{- if hasPrefix "//" $objectData.server -}}
  26. {{- fail "SMB CSI - Did not expect <server> to start with [//]" -}}
  27. {{- end -}}
  28. {{- if hasPrefix "/" $objectData.share -}}
  29. {{- fail "SMB CSI - Did not expect <share> to start with [/]" -}}
  30. {{- end -}}
  31. {{/* TODO: Allow only specific opts? / set specific opts by default? */}}
  32. {{- $validOpts := list -}}
  33. {{- range $opt := $objectData.mountOptions -}}
  34. {{- if not (kindIs "map" $opt) -}}
  35. {{- fail (printf "SMB CSI - Expected <mountOption> item to be a dict, but got [%s]" (kindOf $opt)) -}}
  36. {{- end -}}
  37. {{- if not $opt.key -}}
  38. {{- fail "SMB CSI - Expected key in <mountOptions> to be non-empty" -}}
  39. {{- end -}}
  40. {{/*
  41. {{- $key := tpl $opt.key $rootCtx -}}
  42. {{- if not (mustHas $key $validOpts) -}}
  43. {{- fail (printf "SMB CSI - Expected <mountOptions> to be one of [%v], but got [%v]" (join ", " $validOpts) $opt) -}}
  44. {{- end -}}
  45. */}}
  46. {{- end -}}
  47. {{- end -}}