From 88377803cc8e4089d9a75b46f73f412c9212808c Mon Sep 17 00:00:00 2001 From: Martin Necas Date: Sat, 23 Nov 2024 17:11:00 +0100 Subject: [PATCH 1/2] MTV-1693 | Ignore missing PVC prime Issue: The migration fails on cluster with 4.14 CNV CDI. The 4.14 CNV CDI does not use prime PVC but uses the DV id. Error: ``` persistentvolumeclaims prime-b9d0f99b-4e02-469e-83e2-74dbb186531b not found ``` Fix: Try to fetch the prime pvc but if it fails use the original name and ignore error. This way it will be backwards compatible and support the new prime PVC case. Ref: https://issues.redhat.com/browse/MTV-1693 Signed-off-by: Martin Necas --- pkg/controller/plan/migration.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/pkg/controller/plan/migration.go b/pkg/controller/plan/migration.go index 5d06b92ec..4ef55f4cb 100644 --- a/pkg/controller/plan/migration.go +++ b/pkg/controller/plan/migration.go @@ -27,6 +27,7 @@ import ( "github.com/konveyor/forklift-controller/pkg/settings" batchv1 "k8s.io/api/batch/v1" core "k8s.io/api/core/v1" + k8serr "k8s.io/apimachinery/pkg/api/errors" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" @@ -1622,23 +1623,27 @@ func (r *Migration) updateCopyProgress(vm *plan.VMStatus, step *plan.Step) (err path.Join(dv.Namespace, dv.Name)) continue } - primePvc := &core.PersistentVolumeClaim{} err = r.Destination.Client.Get(context.TODO(), types.NamespacedName{ Namespace: r.Plan.Spec.TargetNamespace, Name: fmt.Sprintf("prime-%s", pvc.UID), - }, primePvc) + }, pvc) if err != nil { - log.Error( - err, - "Could not get prime PVC for DataVolume.", - "vm", - vm.String(), - "dv", - path.Join(dv.Namespace, dv.Name)) - continue + if k8serr.IsNotFound(err) { + log.Info("Could not find prime PVC") + // Ignore error + err = nil + } else { + log.Error( + err, + "Could not get prime PVC for DataVolume.", + "vm", + vm.String(), + "dv", + path.Join(dv.Namespace, dv.Name)) + continue + } } - - importer, found, kErr = r.kubevirt.GetImporterPod(*primePvc) + importer, found, kErr = r.kubevirt.GetImporterPod(*pvc) } if kErr != nil { From 811a5b517d6a72f7bbcedf2a3e5ac0ce8928cabc Mon Sep 17 00:00:00 2001 From: Martin Necas Date: Sat, 23 Nov 2024 10:55:25 +0100 Subject: [PATCH 2/2] MTV-1695 | Add missing NIC for opaque network Issue: When user has NSXT managed network it is represented as opaque network and the VM has opaque nic. Fix: Add opaque nic model mapping to inventory Ref: https://issues.redhat.com/browse/MTV-1695 Signed-off-by: Martin Necas --- .../plan/adapter/vsphere/builder.go | 2 +- .../provider/container/vsphere/collector.go | 22 ++++++++++++++++++- .../provider/container/vsphere/model.go | 6 +++++ .../provider/model/vsphere/model.go | 1 + .../provider/web/vsphere/network.go | 2 ++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pkg/controller/plan/adapter/vsphere/builder.go b/pkg/controller/plan/adapter/vsphere/builder.go index 86dffca4d..8b8e77610 100644 --- a/pkg/controller/plan/adapter/vsphere/builder.go +++ b/pkg/controller/plan/adapter/vsphere/builder.go @@ -578,7 +578,7 @@ func (r *Builder) mapNetworks(vm *model.VM, object *cnv.VirtualMachineSpec) (err needed := []vsphere.NIC{} for _, nic := range vm.NICs { switch network.Variant { - case vsphere.NetDvPortGroup: + case vsphere.NetDvPortGroup, vsphere.OpaqueNetwork: if nic.Network.ID == network.Key { needed = append(needed, nic) } diff --git a/pkg/controller/provider/container/vsphere/collector.go b/pkg/controller/provider/container/vsphere/collector.go index f7df8e7e5..6f6a759f8 100644 --- a/pkg/controller/provider/container/vsphere/collector.go +++ b/pkg/controller/provider/container/vsphere/collector.go @@ -42,6 +42,7 @@ const ( ComputeResource = "ComputeResource" Host = "HostSystem" Network = "Network" + OpaqueNetwork = "OpaqueNetwork" DVPortGroup = "DistributedVirtualPortgroup" DVSwitch = "VmwareDistributedVirtualSwitch" Datastore = "Datastore" @@ -83,7 +84,8 @@ const ( fThumbprint = "summary.config.sslThumbprint" fMgtServerIp = "summary.managementServerIp" // Network - fTag = "tag" + fTag = "tag" + fSummary = "summary" // PortGroup fDVSwitch = "config.distributedVirtualSwitch" fKey = "key" @@ -671,6 +673,15 @@ func (r *Collector) propertySpec() []types.PropertySpec { fTag, }, }, + { + Type: OpaqueNetwork, + PathSet: []string{ + fName, + fParent, + fTag, + fSummary, + }, + }, { Type: DVPortGroup, PathSet: []string{ @@ -823,6 +834,15 @@ func (r *Collector) selectAdapter(u types.ObjectUpdate) (Adapter, bool) { }, }, } + case OpaqueNetwork: + adapter = &NetworkAdapter{ + model: model.Network{ + Base: model.Base{ + Variant: model.OpaqueNetwork, + ID: u.Obj.Value, + }, + }, + } case DVPortGroup: adapter = &NetworkAdapter{ model: model.Network{ diff --git a/pkg/controller/provider/container/vsphere/model.go b/pkg/controller/provider/container/vsphere/model.go index 2de398c2e..b5e1eec59 100644 --- a/pkg/controller/provider/container/vsphere/model.go +++ b/pkg/controller/provider/container/vsphere/model.go @@ -390,6 +390,10 @@ func (v *NetworkAdapter) Apply(u types.ObjectUpdate) { } case fDVSwitch: v.model.DVSwitch = v.Ref(p.Val) + case fSummary: + if s, cast := p.Val.(types.OpaqueNetworkSummary); cast { + v.model.Key = s.OpaqueNetworkId + } } } } @@ -704,6 +708,8 @@ func (v *VmAdapter) Apply(u types.ObjectUpdate) { } case *types.VirtualEthernetCardDistributedVirtualPortBackingInfo: network = backing.Port.PortgroupKey + case *types.VirtualEthernetCardOpaqueNetworkBackingInfo: + network = backing.OpaqueNetworkId } devList = append( diff --git a/pkg/controller/provider/model/vsphere/model.go b/pkg/controller/provider/model/vsphere/model.go index 46db9be92..f8ae2ebf6 100644 --- a/pkg/controller/provider/model/vsphere/model.go +++ b/pkg/controller/provider/model/vsphere/model.go @@ -10,6 +10,7 @@ const ( // Network. NetStandard = "Standard" NetDvPortGroup = "DvPortGroup" + OpaqueNetwork = "OpaqueNetwork" NetDvSwitch = "DvSwitch" // Cluster. ComputeResource = "ComputeResource" diff --git a/pkg/controller/provider/web/vsphere/network.go b/pkg/controller/provider/web/vsphere/network.go index 00b234d01..65f12e23f 100644 --- a/pkg/controller/provider/web/vsphere/network.go +++ b/pkg/controller/provider/web/vsphere/network.go @@ -191,6 +191,8 @@ func (r *Network) With(m *model.Network) { case model.NetDvPortGroup: r.DVSwitch = &m.DVSwitch r.Key = m.Key + case model.OpaqueNetwork: + r.Key = m.Key case model.NetDvSwitch: r.Host = m.Host }