Skip to content

Commit

Permalink
fix error handling in DeletePVCs
Browse files Browse the repository at this point in the history
To return an error when we can't get a prime PVC rather than continue to
the next PVC.

Also refactored the code a bit to reduce cognitive complexity.

Signed-off-by: Arik Hadas <ahadas@redhat.com>
  • Loading branch information
ahadas committed Oct 19, 2023
1 parent 12d417b commit 3965063
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions pkg/controller/plan/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,11 +937,11 @@ func (r *KubeVirt) DeletePVCs(vm *plan.VMStatus) (err error) {
for _, pvc := range pvcs {
primePVC := core.PersistentVolumeClaim{}
err = r.Destination.Client.Get(context.TODO(), client.ObjectKey{Namespace: r.Plan.Spec.TargetNamespace, Name: fmt.Sprintf("prime-%s", string(pvc.UID))}, &primePVC)
if err != nil && k8serr.IsNotFound(err) {
err = nil
}
if err != nil {
if k8serr.IsNotFound(err) {
err = nil
}
continue
return
}
// Best effort deletion
err = r.DeleteObject(&primePVC, vm, "Deleted prime PVC.", "pvc")
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/plan/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ func (r *Migration) Cancel() (err error) {
}

func (r *Migration) cleanUpPopulatorPVCs(vm *plan.VMStatus) (err error) {
err = r.kubevirt.DeletePVCs(vm)
if r.builder.SupportsVolumePopulators() {
err = r.kubevirt.DeletePVCs(vm)
}
return
}

Expand All @@ -435,11 +437,9 @@ func (r *Migration) cleanup(vm *plan.VMStatus) (err error) {
if err != nil {
return
}
if r.builder.SupportsVolumePopulators() {
err = r.cleanUpPopulatorPVCs(vm)
if err != nil {
return
}
err = r.cleanUpPopulatorPVCs(vm)
if err != nil {
return
}
}
err = r.deleteImporterPods(vm)
Expand Down

0 comments on commit 3965063

Please sign in to comment.