_hostpathValidation.tpl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. {{/*
  2. Validate list of host path in a specific format
  3. */}}
  4. {{- define "common.storage.hostPathsValidation" -}}
  5. {{- $allowed_paths := (list "mnt" "sys" "dev" "cluster") -}}
  6. {{- range . -}}
  7. {{- $host_p := splitList "/" . -}}
  8. {{- $host_p := (without $host_p "") -}}
  9. {{- $error_msg := (printf "Invalid hostpath %s. Path must be a valid path under a given pool e.g `/mnt/tank/somepath` is valid whereas `/mnt` or `/mnt/tank` are invalid examples." .) -}}
  10. {{- if and (eq (index $host_p 0) "mnt") (lt ($host_p | len) 3) -}}
  11. {{- fail $error_msg -}}
  12. {{- else if (eq (index $host_p 0) "cluster") -}}
  13. {{- if (lt ($host_p | len) 2) -}}
  14. {{- fail $error_msg -}}
  15. {{- else if (eq (index $host_p 1) "ctdb_shared_vol") -}}
  16. {{- fail $error_msg -}}
  17. {{- end -}}
  18. {{- else if not (has (index $host_p 0) $allowed_paths) -}}
  19. {{- fail $error_msg -}}
  20. {{- end -}}
  21. {{- end -}}
  22. {{- end -}}
  23. {{/*
  24. Validate app volume mount's host path
  25. */}}
  26. {{- define "common.storage.appHostPathsValidate" -}}
  27. {{- $host_p := list -}}
  28. {{- range $path_name := .appVolumeMounts -}}
  29. {{- if ($path_name.hostPathEnabled) -}}
  30. {{- $host_p = mustAppend $host_p $path_name.hostPath -}}
  31. {{- end -}}
  32. {{- end -}}
  33. {{- include "common.storage.hostPathsValidation" $host_p -}}
  34. {{- end -}}
  35. {{/*
  36. Validate extra volume mount's host path
  37. */}}
  38. {{- define "common.storage.extraHostPathsValidate" -}}
  39. {{- $host_p := list -}}
  40. {{- range $index, $hostPathConfiguration := .extraAppVolumeMounts -}}
  41. {{- $host_p = mustAppend $host_p $hostPathConfiguration.hostPath -}}
  42. {{- end -}}
  43. {{- include "common.storage.hostPathsValidation" $host_p -}}
  44. {{- end -}}
  45. {{/*
  46. Validate volumes mount's host paths
  47. */}}
  48. {{- define "common.storage.hostPathValidate" -}}
  49. {{- include "common.storage.extraHostPathsValidate" . -}}
  50. {{- include "common.storage.appHostPathsValidate" . -}}
  51. {{- end -}}