snapshots #10

Merged
jandre merged 69 commits from snapshots into master 2023-04-24 06:49:52 +00:00
Showing only changes of commit 1b31b497a0 - Show all commits

View File

@ -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)