Skip to content

Commit

Permalink
Check claimName on DV status
Browse files Browse the repository at this point in the history
It seems like dv.PVC is always nil because we don't create a DV from a
PVC, this leads to failing to find the DV whenever the importer pod
fails and it will restart forever instead of 3 times

Signed-off-by: Benny Zlotnik <[email protected]>

rename DataVolume to DataVolumeWrapper

Make it slightly less confusing

Signed-off-by: Benny Zlotnik <[email protected]>
  • Loading branch information
bennyz authored and ahadas committed Aug 15, 2023
1 parent e13818f commit 91f7934
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
18 changes: 9 additions & 9 deletions pkg/controller/plan/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (r *KubeVirt) ListVMs() ([]VirtualMachine, error) {
}
vm.DataVolumes = append(
vm.DataVolumes,
DataVolume{
ExtendedDataVolume{
DataVolume: dv,
PVC: pvc,
})
Expand Down Expand Up @@ -537,7 +537,7 @@ func (r *KubeVirt) isDataVolumeExistsInList(dv *cdi.DataVolume, dataVolumeList *
}

// Return DataVolumes associated with a VM.
func (r *KubeVirt) getDVs(vm *plan.VMStatus) (dvs []DataVolume, err error) {
func (r *KubeVirt) getDVs(vm *plan.VMStatus) (edvs []ExtendedDataVolume, err error) {
dvsList := &cdi.DataVolumeList{}
err = r.Destination.Client.List(
context.TODO(),
Expand All @@ -552,10 +552,10 @@ func (r *KubeVirt) getDVs(vm *plan.VMStatus) (dvs []DataVolume, err error) {
return
}

dvs = []DataVolume{}
edvs = []ExtendedDataVolume{}
for i := range dvsList.Items {
dv := &dvsList.Items[i]
dvs = append(dvs, DataVolume{
edvs = append(edvs, ExtendedDataVolume{
DataVolume: dv,
})
}
Expand Down Expand Up @@ -1686,14 +1686,14 @@ func (r *KubeVirt) vmAllButMigrationLabels(vmRef ref.Ref) (labels map[string]str
return
}

// Represents a CDI DataVolume and add behavior.
type DataVolume struct {
// Represents a CDI DataVolume, its associated PVC, and added behavior.
type ExtendedDataVolume struct {
*cdi.DataVolume
PVC *core.PersistentVolumeClaim
}

// Get conditions.
func (r *DataVolume) Conditions() (cnd *libcnd.Conditions) {
func (r *ExtendedDataVolume) Conditions() (cnd *libcnd.Conditions) {
cnd = &libcnd.Conditions{}
for _, c := range r.Status.Conditions {
cnd.SetCondition(libcnd.Condition{
Expand All @@ -1710,7 +1710,7 @@ func (r *DataVolume) Conditions() (cnd *libcnd.Conditions) {

// Convert the Status.Progress into a
// percentage (float).
func (r *DataVolume) PercentComplete() (pct float64) {
func (r *ExtendedDataVolume) PercentComplete() (pct float64) {
s := string(r.Status.Progress)
if strings.HasSuffix(s, "%") {
s = s[:len(s)-1]
Expand All @@ -1726,7 +1726,7 @@ func (r *DataVolume) PercentComplete() (pct float64) {
// Represents Kubevirt VirtualMachine with associated DataVolumes.
type VirtualMachine struct {
*cnv.VirtualMachine
DataVolumes []DataVolume
DataVolumes []ExtendedDataVolume
}

// Determine if `this` VirtualMachine is the
Expand Down
39 changes: 17 additions & 22 deletions pkg/controller/plan/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1389,32 +1389,27 @@ func (r *Migration) updateCopyProgress(vm *plan.VMStatus, step *plan.Step) (err
var importer *core.Pod
var found bool
var kErr error
if dv.PVC == nil && !r.Plan.IsSourceProviderOCP() {

if dv.Status.ClaimName == "" {
found = false
} else {
var importerPVC core.PersistentVolumeClaim
if r.Plan.IsSourceProviderOCP() {
pvc := &core.PersistentVolumeClaim{}
err = r.Destination.Client.Get(context.TODO(), types.NamespacedName{
Namespace: r.Plan.Spec.TargetNamespace,
Name: dv.Status.ClaimName,
}, pvc)
if err != nil {
log.Error(
err,
"Could not get PVC for DataVolume.",
"vm",
vm.String(),
"dv",
path.Join(dv.Namespace, dv.Name))
continue
}
importerPVC = *pvc
} else {
importerPVC = *dv.PVC
pvc := &core.PersistentVolumeClaim{}
err = r.Destination.Client.Get(context.TODO(), types.NamespacedName{
Namespace: r.Plan.Spec.TargetNamespace,
Name: dv.Status.ClaimName,
}, pvc)
if err != nil {
log.Error(
err,
"Could not get PVC for DataVolume.",
"vm",
vm.String(),
"dv",
path.Join(dv.Namespace, dv.Name))
continue
}

importer, found, kErr = r.kubevirt.GetImporterPod(importerPVC)
importer, found, kErr = r.kubevirt.GetImporterPod(*pvc)
}

if kErr != nil {
Expand Down

0 comments on commit 91f7934

Please sign in to comment.