Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions tests/e2e/lib/virt_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ var virtualMachineBackupTrackerGvr = schema.GroupVersionResource{

// virtualMachineBackupGvr is the per-backup VirtualMachineBackup (VMB) resource — distinct
// from VirtualMachineBackupTracker (VMBT, tracked via virtualMachineBackupTrackerGvr above),
// which persists checkpoint state across backups. VMB.Status.Type reports "full" or
// "incremental" for a single completed backup.
// which persists checkpoint state across backups. VMB status.includedVolumes[].type reports "Full" or "Incremental"
// for a single completed backup.
var virtualMachineBackupGvr = schema.GroupVersionResource{
Group: "backup.kubevirt.io",
Resource: "virtualmachinebackups",
Expand Down Expand Up @@ -1662,8 +1662,15 @@ func (v *VirtOperator) CheckVMBackupTrackerExists(namespace string) (bool, error
}

// GetVMBBackupType finds the VirtualMachineBackup in namespace whose
// annotationDataUploadName annotation matches dataUploadName, and returns its
// status.type ("full"/"incremental") and status.checkpointName.
// annotationDataUploadName annotation matches dataUploadName, and returns the
// backup type ("Full"/"Incremental") derived from status.includedVolumes[].type
// plus status.checkpointName.
//
// KubeVirt dropped the whole-backup status.type field in favour of the
// per-volume type. This mirrors kubevirt-datamover-controller, which records
// one type per checkpoint: "Incremental" if any included volume is incremental
// (so the checkpoint's parent chain is preserved), "Full" only if every volume
// is full.
func (v *VirtOperator) GetVMBBackupType(namespace, dataUploadName string) (backupType, checkpointName string, err error) {
list, err := v.Dynamic.Resource(virtualMachineBackupGvr).Namespace(namespace).List(context.Background(), metav1.ListOptions{})
if err != nil {
Expand All @@ -1673,13 +1680,26 @@ func (v *VirtOperator) GetVMBBackupType(namespace, dataUploadName string) (backu
if vmb.GetAnnotations()[annotationDataUploadName] != dataUploadName {
continue
}
found := false
backupType, found, err = unstructured.NestedString(vmb.Object, "status", "type")
volumes, found, err := unstructured.NestedSlice(vmb.Object, "status", "includedVolumes")
if err != nil {
return "", "", fmt.Errorf("failed to read status.type from VirtualMachineBackup %s/%s: %w", namespace, vmb.GetName(), err)
}
if !found {
return "", "", fmt.Errorf("VirtualMachineBackup %s/%s has no status.type yet", namespace, vmb.GetName())
return "", "", fmt.Errorf("failed to read status.includedVolumes from VirtualMachineBackup %s/%s: %w", namespace, vmb.GetName(), err)
}
if !found || len(volumes) == 0 {
return "", "", fmt.Errorf("VirtualMachineBackup %s/%s has no status.includedVolumes yet", namespace, vmb.GetName())
}
backupType = "Full"
for _, vol := range volumes {
volMap, _ := vol.(map[string]interface{})
volType, _ := volMap["type"].(string)
switch {
case volType == "":
return "", "", fmt.Errorf("VirtualMachineBackup %s/%s has an included volume with no type yet", namespace, vmb.GetName())
case strings.EqualFold(volType, "Incremental"):
backupType = "Incremental"
case strings.EqualFold(volType, "Full"):
default:
return "", "", fmt.Errorf("VirtualMachineBackup %s/%s has an included volume with unknown type %q", namespace, vmb.GetName(), volType)
}
}
foundCheckpoint := false
checkpointName, foundCheckpoint, err = unstructured.NestedString(vmb.Object, "status", "checkpointName")
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/virt_backup_restore_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,13 +934,13 @@ var _ = ginkgo.Describe("VM backup and restore tests", ginkgo.Ordered, func() {
actualBackupType, _, err = v.GetVMBBackupType(incSeqNamespace, dataUploadName)
return err
}, 5*time.Minute, time.Second*5).Should(gomega.Succeed(), "failed to get VirtualMachineBackup status for DataUpload %s", dataUploadName)
// VirtualMachineBackup.status.type is PascalCase (virt-controller's own
// VirtualMachineBackup status.includedVolumes[].type is PascalCase (virt-controller's own
// convention, e.g. "Full"/"Incremental"), while the DataUpload's
// expected-backup-type annotation is lowercase (kubevirt-datamover-controller's
// convention, e.g. "full"/"incremental") -- normalize case before comparing
// these two independently-maintained values.
actualBackupType = strings.ToLower(actualBackupType)
gomega.Expect(actualBackupType).To(gomega.Equal(expectedType), "actual VirtualMachineBackup.Status.Type")
gomega.Expect(actualBackupType).To(gomega.Equal(expectedType), "actual VirtualMachineBackup backup type (status.includedVolumes[].type)")
gomega.Expect(actualBackupType).To(gomega.Equal(strings.ToLower(expectedBackupType)), "expected vs. actual backup type must not mismatch")
})
}
Expand Down Expand Up @@ -1066,7 +1066,7 @@ var _ = ginkgo.Describe("VM backup and restore tests", ginkgo.Ordered, func() {

// verifyBackupType returns a runKubevirtDMBackup callback that hard-asserts
// both the DataUpload's expected-backup-type annotation and the
// VirtualMachineBackup's actual Status.Type match expectedType -- mirrors
// VirtualMachineBackup's actual backup type (status.includedVolumes[].type) match expectedType -- mirrors
// the check already done inline in runSequenceBackup above, factored out
// since the incremental-restore test below needs the same check twice
// (full, then incremental) and getting this wrong would silently
Expand All @@ -1083,7 +1083,7 @@ var _ = ginkgo.Describe("VM backup and restore tests", ginkgo.Ordered, func() {
return err
}, 5*time.Minute, time.Second*5).Should(gomega.Succeed(), "failed to get VirtualMachineBackup status for DataUpload %s", dataUploadName)
actualBackupType = strings.ToLower(actualBackupType)
gomega.Expect(actualBackupType).To(gomega.Equal(expectedType), "actual VirtualMachineBackup.Status.Type for DataUpload %s", dataUploadName)
gomega.Expect(actualBackupType).To(gomega.Equal(expectedType), "actual VirtualMachineBackup backup type (status.includedVolumes[].type) for DataUpload %s", dataUploadName)
}
}

Expand Down