Skip to content

Commit

Permalink
vsphere: load hosts per source provider
Browse files Browse the repository at this point in the history
When looking for the configuration of an ESXi host that a certain VM
resides on, we query all the hosts in the namespace and then looking for
the host by its MOR (Managed Object Reference). This almost always works
but it could be wrong when there are several providers within the same
namespace that refer to the same host. This is more likely to happen
during tests where we define two providers with different propreties for
the same vSphere environment. Therefore, adding another check that
ensures the host refers to the provider which is the source provider on
the plan of the migrated VM, otherwise skip that host.

Signed-off-by: Arik Hadas <[email protected]>
  • Loading branch information
ahadas committed Jun 10, 2024
1 parent 7c2ed78 commit eaecc53
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/controller/plan/adapter/vsphere/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ go_library(
"//pkg/lib/condition",
"//pkg/lib/error",
"//pkg/lib/itinerary",
"//pkg/lib/ref",
"//pkg/settings",
"//vendor/github.com/vmware/govmomi",
"//vendor/github.com/vmware/govmomi/find",
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/plan/adapter/vsphere/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
libcnd "github.com/konveyor/forklift-controller/pkg/lib/condition"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
libitr "github.com/konveyor/forklift-controller/pkg/lib/itinerary"
libref "github.com/konveyor/forklift-controller/pkg/lib/ref"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/types"
core "k8s.io/api/core/v1"
Expand Down Expand Up @@ -787,6 +788,10 @@ func (r *Builder) loadHosts() (err error) {
for i := range list.Items {
host := &list.Items[i]
ref := host.Spec.Ref
if !libref.Equals(&host.Spec.Provider, &r.Plan.Spec.Provider.Source) {
continue
}

if !host.Status.HasCondition(libcnd.Ready) {
continue
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/lib/ref/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,19 @@ func RefSet(ref *v1.ObjectReference) bool {

// Equals comparison.
// May be used with `nil` pointers.
func Equals(refA, refB *v1.ObjectReference) bool {
func DeepEquals(refA, refB *v1.ObjectReference) bool {
if refA == nil || refB == nil {
return false
}

return reflect.DeepEqual(refA, refB)
}

// Determind if both refs have the same name and namespace
func Equals(refA, refB *v1.ObjectReference) bool {
if refA == nil || refB == nil {
return refA == refB
}

return refA.Name == refB.Name && refA.Namespace == refB.Namespace
}

0 comments on commit eaecc53

Please sign in to comment.