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

openstack: wait for volume to be removed #591

Merged
merged 4 commits into from
Dec 25, 2023
Merged
Changes from 1 commit
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
Next Next commit
openstack: wait for volume to be removed
Before removing the snapshot attempt to make sure the volume has been
removed

Signed-off-by: Benny Zlotnik <[email protected]>
  • Loading branch information
bennyz authored and ahadas committed Dec 25, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit c7caf192c48573df3a47307b54d72c3b96e38182
1 change: 1 addition & 0 deletions pkg/controller/plan/adapter/openstack/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:meta",
"//vendor/k8s.io/apimachinery/pkg/labels",
"//vendor/k8s.io/apimachinery/pkg/types",
"//vendor/k8s.io/apimachinery/pkg/util/wait",
"//vendor/kubevirt.io/api/core/v1:core",
"//vendor/kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1",
"//vendor/sigs.k8s.io/controller-runtime/pkg/client",
53 changes: 47 additions & 6 deletions pkg/controller/plan/adapter/openstack/client.go
Original file line number Diff line number Diff line change
@@ -3,13 +3,15 @@ package openstack
import (
"errors"
"strings"
"time"

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"
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"
"k8s.io/apimachinery/pkg/util/wait"
cdi "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
)

@@ -272,12 +274,7 @@ func (r *Client) PreTransferActions(vmRef ref.Ref) (ready bool, err error) {
r.Log.Info("the image properties are in sync, cleaning the image",
"vm", vm.Name, "image", inventoryImage.Name, "properties", inventoryImage.Properties)
originalVolumeID := inventoryImage.Properties[forkliftPropertyOriginalVolumeID].(string)
err = r.cleanup(vm, originalVolumeID)
if err != nil {
r.Log.Error(err, "cleaning the image",
"vm", vm.Name, "image", image.Name)
return
}
go r.cleanup(vm, originalVolumeID)
default:
err = liberr.New("unexpected image status")
r.Log.Error(err, "checking the image from volume",
@@ -546,6 +543,50 @@ func (r *Client) cleanup(vm *libclient.VM, originalVolumeID string) (err error)
err = nil
return
}

// Now we need to wait for the volume to be removed
condition := func() (done bool, err error) {
volume, err := r.getVolumeFromSnapshot(vm, snapshot.ID)
if err != nil {
if errors.Is(err, ResourceNotFoundError) {
done = true
err = nil
return
}
err = liberr.Wrap(err)
r.Log.Error(err, "retrieving volume from snapshot information when cleaning up",
"vm", vm.Name, "snapshotID", snapshot.ID)
return
}
switch volume.Status {
case VolumeStatusDeleting:
r.Log.Info("the volume is still being deleted, waiting...",
"vm", vm.Name, "volume", volume.Name, "snapshot", volume.SnapshotID)
default:
err = UnexpectedVolumeStatusError
r.Log.Error(err, "checking the volume",
"vm", vm.Name, "volume", volume.Name, "status", volume.Status)
return
}
return
}

// TODO add config
ahadas marked this conversation as resolved.
Show resolved Hide resolved
backoff := wait.Backoff{
Duration: 3 * time.Second,
Factor: 1.1,
Steps: 100,
}

err = wait.ExponentialBackoff(backoff, condition)
if err != nil {
err = liberr.Wrap(err)
r.Log.Error(err, "waiting for the volume to be removed",
"vm", vm.Name, "snapshotID", snapshot.ID)
err = nil
return
ahadas marked this conversation as resolved.
Show resolved Hide resolved
}

r.Log.Info("cleaning up the snapshot from volume",
"vm", vm.Name, "originalVolumeID", originalVolumeID)
err = r.removeSnapshotFromVolume(vm, originalVolumeID)