Skip to content

Commit

Permalink
vsphere: perform CBT operations on hosts when needed
Browse files Browse the repository at this point in the history
Previously, when running warm migrations from a vSphere provider with
vCenter as its SDK endpoint, we ran create-snapshot, set-checkpoints and
remove-snapshots on vCenter, even when there was a network defined for
an ESXi host. That cause CDI to fail: the identifier of a snapshot that
was recievd from vCenter was different than the identifier of the same
snapshot in ESXi and therefore CDI, that interacts with ESXi hosts in
this scenario, failed to find the snapshot.

Now, when running CBT operations we check whether the disk(s) will be
transferred from vCenter or ESXi, and perform the aforementioned CBT
operations on the corresponding component.

Signed-off-by: Arik Hadas <[email protected]>
  • Loading branch information
ahadas committed Jun 19, 2024
1 parent dd60f13 commit 7661eca
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 41 deletions.
1 change: 1 addition & 0 deletions pkg/controller/plan/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ go_library(
"//pkg/controller/plan/handler",
"//pkg/controller/plan/scheduler",
"//pkg/controller/provider/web",
"//pkg/controller/provider/web/vsphere",
"//pkg/controller/validation",
"//pkg/lib/client/openshift",
"//pkg/lib/condition",
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/plan/adapter/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_library(
"//pkg/apis/forklift/v1beta1/plan",
"//pkg/apis/forklift/v1beta1/ref",
"//pkg/controller/plan/context",
"//pkg/controller/plan/util",
"//pkg/lib/error",
"//vendor/k8s.io/api/core/v1:core",
"//vendor/kubevirt.io/api/core/v1:core",
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/plan/adapter/base/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
planapi "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/plan"
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/ref"
plancontext "github.com/konveyor/forklift-controller/pkg/controller/plan/context"
"github.com/konveyor/forklift-controller/pkg/controller/plan/util"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
core "k8s.io/api/core/v1"
cnv "kubevirt.io/api/core/v1"
Expand Down Expand Up @@ -103,13 +104,13 @@ type Client interface {
// Return whether the source VM is powered off.
PoweredOff(vmRef ref.Ref) (bool, error)
// Create a snapshot of the source VM.
CreateSnapshot(vmRef ref.Ref) (string, error)
CreateSnapshot(vmRef ref.Ref, hostsFunc util.HostsFunc) (string, error)
// Remove all warm migration snapshots.
RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy) error
RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy, hostsFunc util.HostsFunc) error
// Check if a snapshot is ready to transfer.
CheckSnapshotReady(vmRef ref.Ref, snapshot string) (ready bool, err error)
// Set DataVolume checkpoints.
SetCheckpoints(vmRef ref.Ref, precopies []planapi.Precopy, datavolumes []cdi.DataVolume, final bool) (err error)
SetCheckpoints(vmRef ref.Ref, precopies []planapi.Precopy, datavolumes []cdi.DataVolume, final bool, hostsFunc util.HostsFunc) (err error)
// Close connections to the provider API.
Close()
// Finalize migrations
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/plan/adapter/ocp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_library(
"//pkg/apis/forklift/v1beta1/ref",
"//pkg/controller/plan/adapter/base",
"//pkg/controller/plan/context",
"//pkg/controller/plan/util",
"//pkg/controller/provider/web",
"//pkg/lib/client/openshift",
"//pkg/lib/error",
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/plan/adapter/ocp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
planapi "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/plan"
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/ref"
plancontext "github.com/konveyor/forklift-controller/pkg/controller/plan/context"
"github.com/konveyor/forklift-controller/pkg/controller/plan/util"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
"github.com/konveyor/forklift-controller/pkg/settings"
core "k8s.io/api/core/v1"
Expand Down Expand Up @@ -34,7 +35,7 @@ func (r *Client) Close() {
}

// CreateSnapshot implements base.Client
func (r *Client) CreateSnapshot(vmRef ref.Ref) (string, error) {
func (r *Client) CreateSnapshot(vmRef ref.Ref, hostsFunc util.HostsFunc) (string, error) {
return "", nil
}

Expand Down Expand Up @@ -123,12 +124,12 @@ func (r *Client) PoweredOff(vmRef ref.Ref) (bool, error) {
}

// RemoveSnapshots implements base.Client
func (r *Client) RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy) error {
func (r *Client) RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy, hostsFunc util.HostsFunc) error {
return nil
}

// SetCheckpoints implements base.Client
func (r *Client) SetCheckpoints(vmRef ref.Ref, precopies []planapi.Precopy, datavolumes []cdi.DataVolume, final bool) (err error) {
func (r *Client) SetCheckpoints(vmRef ref.Ref, precopies []planapi.Precopy, datavolumes []cdi.DataVolume, final bool, hostsFunc util.HostsFunc) (err error) {
return nil
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/plan/adapter/openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
planapi "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/plan"
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/ref"
plancontext "github.com/konveyor/forklift-controller/pkg/controller/plan/context"
"github.com/konveyor/forklift-controller/pkg/controller/plan/util"
model "github.com/konveyor/forklift-controller/pkg/controller/provider/web/openstack"
libclient "github.com/konveyor/forklift-controller/pkg/lib/client/openstack"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
Expand Down Expand Up @@ -109,12 +110,12 @@ func (r *Client) PoweredOff(vmRef ref.Ref) (off bool, err error) {
}

// Create a snapshot of the source VM.
func (r *Client) CreateSnapshot(vmRef ref.Ref) (imageID string, err error) {
func (r *Client) CreateSnapshot(vmRef ref.Ref, hostsFunc util.HostsFunc) (imageID string, err error) {
return
}

// Remove all warm migration snapshots.
func (r *Client) RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy) (err error) {
func (r *Client) RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy, hostsFunc util.HostsFunc) (err error) {
return
}

Expand All @@ -124,7 +125,7 @@ func (r *Client) CheckSnapshotReady(vmRef ref.Ref, imageID string) (ready bool,
}

// Set DataVolume checkpoints.
func (r *Client) SetCheckpoints(vmRef ref.Ref, precopies []planapi.Precopy, datavolumes []cdi.DataVolume, final bool) error {
func (r *Client) SetCheckpoints(vmRef ref.Ref, precopies []planapi.Precopy, datavolumes []cdi.DataVolume, final bool, hostsFunc util.HostsFunc) error {
return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/controller/plan/adapter/ova/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_library(
"//pkg/apis/forklift/v1beta1/ref",
"//pkg/controller/plan/adapter/base",
"//pkg/controller/plan/context",
"//pkg/controller/plan/util",
"//pkg/controller/provider/model/ova",
"//pkg/controller/provider/web",
"//pkg/controller/provider/web/base",
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/plan/adapter/ova/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
planapi "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/plan"
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/ref"
plancontext "github.com/konveyor/forklift-controller/pkg/controller/plan/context"
"github.com/konveyor/forklift-controller/pkg/controller/plan/util"
libweb "github.com/konveyor/forklift-controller/pkg/lib/inventory/web"
core "k8s.io/api/core/v1"
cdi "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
Expand Down Expand Up @@ -45,12 +46,12 @@ func (r *Client) connect() (err error) {
}

// Create a VM snapshot and return its ID.
func (r *Client) CreateSnapshot(vmRef ref.Ref) (snapshot string, err error) {
func (r *Client) CreateSnapshot(vmRef ref.Ref, hostsFunc util.HostsFunc) (snapshot string, err error) {
return
}

// Remove all warm migration snapshots.
func (r *Client) RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy) (err error) {
func (r *Client) RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy, hostsFunc util.HostsFunc) (err error) {
return
}

Expand All @@ -60,7 +61,7 @@ func (r *Client) CheckSnapshotReady(vmRef ref.Ref, snapshot string) (ready bool,
}

// Set DataVolume checkpoints.
func (r *Client) SetCheckpoints(vmRef ref.Ref, precopies []planapi.Precopy, datavolumes []cdi.DataVolume, final bool) (err error) {
func (r *Client) SetCheckpoints(vmRef ref.Ref, precopies []planapi.Precopy, datavolumes []cdi.DataVolume, final bool, hostsFunc util.HostsFunc) (err error) {
return
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/plan/adapter/ovirt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
planapi "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/plan"
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/ref"
plancontext "github.com/konveyor/forklift-controller/pkg/controller/plan/context"
"github.com/konveyor/forklift-controller/pkg/controller/plan/util"
"github.com/konveyor/forklift-controller/pkg/controller/provider/container/ovirt"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web"
model "github.com/konveyor/forklift-controller/pkg/controller/provider/web/ovirt"
Expand Down Expand Up @@ -39,7 +40,7 @@ type Client struct {
}

// Create a VM snapshot and return its ID.
func (r *Client) CreateSnapshot(vmRef ref.Ref) (snapshot string, err error) {
func (r *Client) CreateSnapshot(vmRef ref.Ref, hostsFunc util.HostsFunc) (snapshot string, err error) {
_, vmService, err := r.getVM(vmRef)
if err != nil {
err = liberr.Wrap(err)
Expand Down Expand Up @@ -74,7 +75,7 @@ func (r *Client) CreateSnapshot(vmRef ref.Ref) (snapshot string, err error) {
}

// Remove all warm migration snapshots.
func (r *Client) RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy) (err error) {
func (r *Client) RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy, hostsFunc util.HostsFunc) (err error) {
// Snapshot removal is done in Finalize to avoid race conditions
return
}
Expand Down Expand Up @@ -110,7 +111,7 @@ func (r *Client) CheckSnapshotReady(vmRef ref.Ref, snapshot string) (ready bool,
}

// Set DataVolume checkpoints.
func (r *Client) SetCheckpoints(vmRef ref.Ref, precopies []planapi.Precopy, datavolumes []cdi.DataVolume, final bool) (err error) {
func (r *Client) SetCheckpoints(vmRef ref.Ref, precopies []planapi.Precopy, datavolumes []cdi.DataVolume, final bool, hostsFunc util.HostsFunc) (err error) {
n := len(precopies)
previous := ""
current := precopies[n-1].Snapshot
Expand Down
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 @@ -18,6 +18,7 @@ go_library(
"//pkg/apis/forklift/v1beta1/ref",
"//pkg/controller/plan/adapter/base",
"//pkg/controller/plan/context",
"//pkg/controller/plan/util",
"//pkg/controller/provider/container/vsphere",
"//pkg/controller/provider/model/vsphere",
"//pkg/controller/provider/web",
Expand Down
Loading

0 comments on commit 7661eca

Please sign in to comment.