FindOverlappingVolume looks an artifact path, checks if it overlaps with any user specified volumeMounts in the template, and returns the deepest volumeMount (if any). A return value of nil indicates the path is not under any volumeMount.
(tmpl *wfv1.Template, path string)
| 24 | // user specified volumeMounts in the template, and returns the deepest volumeMount |
| 25 | // (if any). A return value of nil indicates the path is not under any volumeMount. |
| 26 | func FindOverlappingVolume(tmpl *wfv1.Template, path string) *apiv1.VolumeMount { |
| 27 | volumeMounts := tmpl.GetVolumeMounts() |
| 28 | sort.Slice(volumeMounts, func(i, j int) bool { |
| 29 | return len(volumeMounts[i].MountPath) > len(volumeMounts[j].MountPath) |
| 30 | }) |
| 31 | for _, mnt := range volumeMounts { |
| 32 | normalizedMountPath := strings.TrimRight(mnt.MountPath, "/") |
| 33 | if path == normalizedMountPath || isSubPath(path, normalizedMountPath) { |
| 34 | return &mnt |
| 35 | } |
| 36 | } |
| 37 | return nil |
| 38 | } |
| 39 | |
| 40 | func isSubPath(path string, normalizedMountPath string) bool { |
| 41 | return strings.HasPrefix(path, normalizedMountPath+"/") |