Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check claimName on DV status #541

Merged
merged 1 commit into from
Aug 15, 2023
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
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