Skip to content

Commit

Permalink
Do not fall back to using filenames for PVC disk backup (#724)
Browse files Browse the repository at this point in the history
When recording PVC disk data for the backup, we added code that first
checks disks by their filenames first before falling back to using
UUIDs.  This was done to support partial (disk only restore).

Since partial restore no longer relies on the PVC disk data, we no
longer need to do this.  The current code also has a side effect of
not handling disks restored with a new PVC name.

This effectively reverts the commit: c3a0c36.
  • Loading branch information
aruneshpa authored Sep 25, 2024
1 parent 55e3bbf commit 3229d9d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 46 deletions.
30 changes: 2 additions & 28 deletions pkg/providers/vsphere/virtualmachine/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"maps"
"path"
"strconv"
"strings"

Expand Down Expand Up @@ -419,36 +418,10 @@ func getDesiredDiskDataForBackup(
classicDiskData []vmopbackup.ClassicDiskData
)

// Vendor's partial restore (e.g. single disk) method may create a new,
// non-FCD disk. The restored disk has new UUID and lives the the VM's
// directory, not the fcd/ directory. Given that FCD disk names are unique,
// we consult the backup data to compare using `FileName` before `Uuid`.
pvcDiskDataPrevious := make(map[string]vmopbackup.PVCDiskData)
curBackup, ok := extraConfig.GetString(vmopv1.PVCDiskDataExtraConfigKey)
if ok {
decoded, err := pkgutil.TryToDecodeBase64Gzip([]byte(curBackup))
if err != nil {
return "", "", err
}

var data []vmopbackup.PVCDiskData
dec := json.NewDecoder(strings.NewReader(decoded))
if err = dec.Decode(&data); err != nil {
return "", "", err
}

for _, pvc := range data {
pvcDiskDataPrevious[path.Base(pvc.FileName)] = pvc
}
}

for _, device := range deviceList.SelectByType((*vimtypes.VirtualDisk)(nil)) {
if disk, ok := device.(*vimtypes.VirtualDisk); ok {
if b, ok := disk.Backing.(*vimtypes.VirtualDiskFlatVer2BackingInfo); ok {
if disk, ok := pvcDiskDataPrevious[path.Base(b.FileName)]; ok {
disk.FileName = b.FileName
pvcDiskData = append(pvcDiskData, disk)
} else if pvc, ok := opts.DiskUUIDToPVC[b.Uuid]; ok {
if pvc, ok := opts.DiskUUIDToPVC[b.Uuid]; ok {
pvcDiskData = append(pvcDiskData, vmopbackup.PVCDiskData{
FileName: b.FileName,
PVCName: pvc.Name,
Expand All @@ -473,6 +446,7 @@ func getDesiredDiskDataForBackup(
}

// Return an empty string to skip backup if PVC disk data is unchanged.
curBackup, _ := extraConfig.GetString(vmopv1.PVCDiskDataExtraConfigKey)
if pvcDiskDataBackup == curBackup {
pvcDiskDataBackup = ""
}
Expand Down
18 changes: 0 additions & 18 deletions pkg/providers/vsphere/virtualmachine/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"

"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/simulator"
"github.com/vmware/govmomi/vim25/mo"
vimtypes "github.com/vmware/govmomi/vim25/types"

Expand Down Expand Up @@ -689,22 +687,6 @@ func backupTests() {
verifyBackupDataInExtraConfig(ctx, vcVM, vmopv1.BackupVersionExtraConfigKey, vT2, false)
Expect(vmCtx.VM.Annotations[vmopv1.VirtualMachineBackupVersionAnnotation]).To(Equal(vT2))
}

By("detect disk file backing change", func() {
vm := simulator.Map.Get(vcVM.Reference()).(*simulator.VirtualMachine)
deviceList := object.VirtualDeviceList(vm.Config.Hardware.Device)

for _, device := range deviceList.SelectByType((*vimtypes.VirtualDisk)(nil)) {
disk := device.(*vimtypes.VirtualDisk)
if b, ok := disk.Backing.(*vimtypes.VirtualDiskFlatVer2BackingInfo); ok {
b.Uuid = uuid.NewString()
break
}
}

Expect(virtualmachine.BackupVirtualMachine(backupOpts)).To(Succeed())
verifyBackupDataInExtraConfig(ctx, vcVM, vmopv1.PVCDiskDataExtraConfigKey, string(diskDataJSON), true)
})
})
})
})
Expand Down

0 comments on commit 3229d9d

Please sign in to comment.