@@ -146,7 +146,7 @@ func (p *BackupPlugin) Execute(
146146 p .Log .Infof ("[vm-backup] Generated operation ID: %s" , operationID )
147147
148148 // Get the first PVC with skip volume policy for SourcePVC (kubevirt datamover trigger)
149- sourcePVC , err := p .getFirstKubevirtPVC (vm , backup )
149+ sourcePVC , err := p .getFirstKubevirtPVC (vm , backup , vh )
150150 if err != nil {
151151 return nil , nil , "" , nil , fmt .Errorf ("failed to get source PVC: %w" , err )
152152 }
@@ -305,11 +305,8 @@ func CheckPreconditions(vm *kvcore.VirtualMachine, backup *velerov1.Backup, log
305305 }
306306
307307 // Check 4: Volume policy check
308- // - At least one PVC must have "skip " action (triggers kubevirt datamover)
308+ // - At least one PVC must have "custom " action with "datamover=kubevirt" parameter (triggers kubevirt datamover)
309309 // - No PVC can have "snapshot" action (would conflict with kubevirt datamover)
310- // TODO(https://github.com/migtools/kubevirt-datamover-plugin/issues/4): Once upstream
311- // Velero changes are merged, update this to check for "custom" action type and inspect
312- // the action parameters map to verify it's for kubevirt.
313310 hasKubevirtPolicy , hasConflictingPolicy , err := checkVolumePolicies (vm , backup , log , vh )
314311 if err != nil {
315312 return false , "" , fmt .Errorf ("failed to check volume policies: %w" , err )
@@ -416,7 +413,7 @@ func checkVolumePolicies(vm *kvcore.VirtualMachine, backup *velerov1.Backup, log
416413// Velero changes merge, update this to return the first PVC with "custom" action type
417414// and kubevirt-specific parameter set. The volumehelper API will need to expose the
418415// actual action type (not just shouldSnapshot boolean) for this check.
419- func (p * BackupPlugin ) getFirstKubevirtPVC (vm * kvcore.VirtualMachine , backup * velerov1.Backup ) (* corev1.PersistentVolumeClaim , error ) {
416+ func (p * BackupPlugin ) getFirstKubevirtPVC (vm * kvcore.VirtualMachine , backup * velerov1.Backup , vh vhutil. VolumeHelper ) (* corev1.PersistentVolumeClaim , error ) {
420417 pvcNames := controllercommon .GetVolumesForVm (vm )
421418 if len (pvcNames ) == 0 {
422419 return nil , fmt .Errorf ("no PVCs found for VirtualMachine %s/%s" , vm .Namespace , vm .Name )
@@ -427,11 +424,6 @@ func (p *BackupPlugin) getFirstKubevirtPVC(vm *kvcore.VirtualMachine, backup *ve
427424 return nil , fmt .Errorf ("failed to get core client: %w" , err )
428425 }
429426
430- crClient , err := clients .CRClient ()
431- if err != nil {
432- return nil , fmt .Errorf ("failed to get controller-runtime client: %w" , err )
433- }
434-
435427 for _ , pvcName := range pvcNames {
436428 pvc , err := coreClient .PersistentVolumeClaims (vm .Namespace ).Get (context .Background (), pvcName , metav1.GetOptions {})
437429 if err != nil {
@@ -451,20 +443,18 @@ func (p *BackupPlugin) getFirstKubevirtPVC(vm *kvcore.VirtualMachine, backup *ve
451443 }
452444 pvcUnstructured := & unstructured.Unstructured {Object : pvcMap }
453445
454- // Check if this PVC has snapshot policy
455- shouldSnapshot , err := volumehelper . ShouldPerformSnapshotWithBackup (
446+ // Check if this PVC has custom kubevirt datamover policy
447+ shouldUseKubevirtDm , err := vh . ShouldPerformCustomAction (
456448 pvcUnstructured ,
457449 kuberesource .PersistentVolumeClaims ,
458- * backup ,
459- crClient ,
460- p .Log ,
450+ kubevirtCustomPolicy ,
461451 )
462452 if err != nil {
463453 return nil , fmt .Errorf ("failed to check volume policy for PVC %s: %w" , pvcName , err )
464454 }
465455
466- // Return first PVC without snapshot policy
467- if ! shouldSnapshot {
456+ // Return first PVC matching kubevirt dm custom policy action
457+ if shouldUseKubevirtDm {
468458 return pvc , nil
469459 }
470460 }
0 commit comments