snapshots #10
@ -3,7 +3,9 @@ package v1alpha1
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -57,14 +59,19 @@ func GetVolumeMounts(container corev1.Container, targetContainer TargetContainer
|
|||||||
vm := corev1.VolumeMount{ReadOnly: true}
|
vm := corev1.VolumeMount{ReadOnly: true}
|
||||||
var longest int = 0
|
var longest int = 0
|
||||||
var sidecarPath string
|
var sidecarPath string
|
||||||
|
path = filepath.Clean(path)
|
||||||
|
splitPath := strings.Split(path, string(os.PathSeparator))
|
||||||
for _, volumeMount := range container.VolumeMounts {
|
for _, volumeMount := range container.VolumeMounts {
|
||||||
// if strings.HasPrefix(path, volumeMount.MountPath) && len(volumeMount.MountPath) > longest {
|
splitMountPath := strings.Split(volumeMount.MountPath, string(os.PathSeparator))
|
||||||
if rel, err := filepath.Rel(volumeMount.MountPath, path); err == nil && len(volumeMount.MountPath) > longest {
|
for j, pathItem := range splitMountPath {
|
||||||
longest = len(volumeMount.MountPath)
|
if j < len(splitPath) && pathItem == splitPath[j] && j > longest {
|
||||||
vm.Name = volumeMount.Name
|
longest = j
|
||||||
vm.MountPath = fmt.Sprintf("/%s%d", BACKUP_PREFIX_PATH, i)
|
vm.Name = volumeMount.Name
|
||||||
vm.SubPath = volumeMount.SubPath
|
vm.MountPath = fmt.Sprintf("/%s%d", BACKUP_PREFIX_PATH, i)
|
||||||
sidecarPath = filepath.Join(vm.MountPath, rel)
|
vm.SubPath = volumeMount.SubPath
|
||||||
|
rel, _ := filepath.Rel(volumeMount.MountPath, path)
|
||||||
|
sidecarPath = filepath.Join(vm.MountPath, rel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vms = append(vms, vm)
|
vms = append(vms, vm)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user