From a70b92c23ecfaea2ced7da159dd65c2f1a68add2 Mon Sep 17 00:00:00 2001 From: Benny Zlotnik Date: Tue, 26 Mar 2024 18:47:49 +0200 Subject: [PATCH] openstack: attempt to fix race The status of the snapshot might not be synced in the inventory. Check the status is up-to-date before proceeding Signed-off-by: Benny Zlotnik --- pkg/controller/plan/adapter/openstack/client.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/controller/plan/adapter/openstack/client.go b/pkg/controller/plan/adapter/openstack/client.go index 2d03f1939..5603133bc 100644 --- a/pkg/controller/plan/adapter/openstack/client.go +++ b/pkg/controller/plan/adapter/openstack/client.go @@ -804,11 +804,17 @@ func (r *Client) ensureVmSnapshot(vm *libclient.VM) (ready bool, err error) { "vm", vm.Name, "image", vmSnapshotImage.Name, "imageID", vmSnapshotImage.ID) ready = true if _, ok := vm.Image["id"]; ok { + r.Log.Info("the VM is image based, checking the image properties", "vm", vm.Name, "snapshot", vmSnapshotImage.Name) ready, err = r.ensureImageUpToDate(vm, vmSnapshotImage, vmTypeImageBased) if err != nil { r.Log.Error(err, "checking the VM snapshot image properties", "vm", vm.Name, "image", vmSnapshotImage.Name) return } + + if !ready { + r.Log.Info("the VM snapshot image properties are not in sync, skipping...", "vm", vm.Name, "image", vmSnapshotImage.Name) + return + } } return case ImageStatusImporting, ImageStatusQueued, ImageStatusUploading, ImageStatusSaving: @@ -855,6 +861,8 @@ func (r *Client) ensureImagesFromVolumesReady(vm *libclient.VM) (ready bool, err if !ready { return false, nil } + r.Log.Info("the image is ready in the inventory", + "vm", vm.Name, "image", image.Name, "properties", image.Properties) go func() { // executing this in a non-blocking mode @@ -943,6 +951,12 @@ func (r *Client) ensureImageUpToDate(vm *libclient.VM, image *libclient.Image, v return } + if inventoryImage.Status != string(image.Status) { + r.Log.Info("image status is not in sync, waiting...", + "vm", vm.Name, "image", inventoryImage.Name, "status", inventoryImage.Status) + return + } + switch vmType { case vmTypeImageBased: _, upToDate = inventoryImage.Properties[forkliftPropertyOriginalImageID]