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.
  • Loading branch information
ahadas committed Jun 16, 2024
1 parent a444a22 commit 633864c
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 41 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/forklift/v1beta1/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type HostList struct {
Items []Host `json:"items"`
}

type HostsFunc func() (map[string]*Host, error)

func init() {
SchemeBuilder.Register(&Host{}, &HostList{})
}
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
6 changes: 3 additions & 3 deletions pkg/controller/plan/adapter/base/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,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 api.HostsFunc) (string, error)
// Remove all warm migration snapshots.
RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy) error
RemoveSnapshots(vmRef ref.Ref, precopies []planapi.Precopy, hostsFunc api.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 api.HostsFunc) (err error)
// Close connections to the provider API.
Close()
// Finalize migrations
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 @@ -4,6 +4,7 @@ import (
"context"
"time"

"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
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"
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 v1beta1.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 v1beta1.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 v1beta1.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 @@ -5,6 +5,7 @@ import (
"strings"
"time"

"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
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"
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 v1beta1.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 v1beta1.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 v1beta1.HostsFunc) error {
return nil
}

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 @@ -6,6 +6,7 @@ import (
"time"

"github.com/go-logr/logr"
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
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"
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 v1beta1.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 v1beta1.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 v1beta1.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 @@ -8,6 +8,7 @@ import (
"sync"
"time"

"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
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"
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 v1beta1.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 v1beta1.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 v1beta1.HostsFunc) (err error) {
n := len(precopies)
previous := ""
current := precopies[n-1].Snapshot
Expand Down
Loading

0 comments on commit 633864c

Please sign in to comment.