From 5bb3c1ccbce3a79fb515ff2967c9388301c51093 Mon Sep 17 00:00:00 2001 From: Martin Necas Date: Tue, 17 Dec 2024 08:01:28 +0100 Subject: [PATCH] MTV-1775 | Fix not finished task NPE Issue: If the snapshot creation task did not finish the controller fails with NPE. This happens due to the taks not returning the result and we are trying to typcase that result (nil) to the ManagedObject. Fix: Add check if the task finished or retry. Signed-off-by: Martin Necas --- pkg/controller/plan/adapter/vsphere/client.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/controller/plan/adapter/vsphere/client.go b/pkg/controller/plan/adapter/vsphere/client.go index 87ec0853c..7a0e01872 100644 --- a/pkg/controller/plan/adapter/vsphere/client.go +++ b/pkg/controller/plan/adapter/vsphere/client.go @@ -251,9 +251,20 @@ func (r *Client) CheckSnapshotReady(vmRef ref.Ref, precopy planapi.Precopy, host r.Log.Info("Check Snapshot Ready", "vmRef", vmRef, "precopy", precopy) taskInfo, err := r.getTaskById(vmRef, precopy.CreateTaskId, hosts) if err != nil { - return false, snapshotId, liberr.Wrap(err) + return false, "", liberr.Wrap(err) } ready, err = r.checkTaskStatus(taskInfo) + if err != nil { + return false, "", liberr.Wrap(err) + } + if !ready { + // Task is not finished retry + return false, "", nil + } + if taskInfo.Result == nil { + // Empty result so the task did not finish retry + return false, "", nil + } snapshotId = taskInfo.Result.(types.ManagedObjectReference).Value return }