volumes.go 515 B

12345678910111213141516171819202122
  1. package common
  2. import (
  3. "regexp"
  4. )
  5. var (
  6. k8sVolumeDir = regexp.MustCompile(`.+/(volumes/kubernetes.io~([^/]+)|volume-subpaths|k3s/storage)/(pvc-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})`)
  7. )
  8. func ParseKubernetesVolumeSource(source string) string {
  9. groups := k8sVolumeDir.FindStringSubmatch(source)
  10. if len(groups) != 4 {
  11. return ""
  12. }
  13. provisioner, volume := groups[2], groups[3]
  14. switch provisioner {
  15. case "secret", "configmap", "empty-dir", "projected":
  16. return ""
  17. }
  18. return volume
  19. }