kubevirt / kubevirt-velero-plugin

Plugin to Velero which automates backing up and restoring KubeVirt/CDI objects
Apache License 2.0
26 stars 26 forks source link

vm restore failing when InstanceType and Preference is set on a VM #221

Open hzproe opened 4 months ago

hzproe commented 4 months ago

What happened: Restore of VMs failing with missing Controllerrevision message

What you expected to happen: Restore of the VM working fine

How to reproduce it (as minimally and precisely as possible): Create a vm using a script like

apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: ubuntubackup namespace: default spec: running: true dataVolumeTemplates:

Additional context: Add any other context about the problem here.

Environment:

Solution:

there is a casesensitive parameter which is evaluated wrongly, see snippet below ... where I have corrected the case of the attributes happy to create a PR if you want

func (p VMBackupItemAction) addVMObjectGraph(vm kvcore.VirtualMachine, extra []velero.ResourceIdentifier) []velero.ResourceIdentifier { if vm.Spec.Instancetype != nil { switch vm.Spec.Instancetype.Kind { //TODO handle VirtualMachineClusterInstancetype //case "virtualmachineinstancetype": case "VirtualMachineInstancetype": <========== p.log.Infof("Adding instance type %s to the backup", vm.Spec.Instancetype.Name) extra = append(extra, velero.ResourceIdentifier{ GroupResource: schema.GroupResource{Group: "instancetype.kubevirt.io", Resource: "virtualmachineinstancetype"}, Namespace: vm.Namespace, Name: vm.Spec.Instancetype.Name, }) extra = append(extra, velero.ResourceIdentifier{ GroupResource: schema.GroupResource{Group: "apps", Resource: "controllerrevisions"}, Namespace: vm.Namespace, Name: vm.Spec.Instancetype.RevisionName, }) } }

    if vm.Spec.Preference != nil {
            //TODO handle VirtualMachineClusterPreference
            switch vm.Spec.Preference.Kind {
            //case "virtualmachinepreference":
              case "VirtualMachinePreference":    <==========
                    p.log.Infof("Adding preference %s to the backup", vm.Spec.Preference.Name)
                    extra = append(extra, velero.ResourceIdentifier{
                            GroupResource: schema.GroupResource{Group: "instancetype.kubevirt.io", Resource: "virtualmachinepreference"},
                            Namespace:     vm.Namespace,
                            Name:          vm.Spec.Preference.Name,
                    })
                    extra = append(extra, velero.ResourceIdentifier{
                            GroupResource: schema.GroupResource{Group: "apps", Resource: "controllerrevisions"},
                            Namespace:     vm.Namespace,
                            Name:          vm.Spec.Preference.RevisionName,
                    })
            }
    }

    return extra

}

ShellyKa13 commented 2 months ago

Hi @hzproe thanks for your report. We have a test scenario of vm with instancetype and preferences: https://github.com/kubevirt/kubevirt-velero-plugin/blob/main/tests/vm_backup_test.go#L204 Which passes with no issues in our CI. Now I still tried to run it again locally and it passed, I tried to change the case of the attributes as you suggested in your fix and with that the instancetype and preference are not included in the backup (comparing to how it is now which is included, I checked) Have you tried your solution and it worked for you?