From 74bfa6aaccb5c594d618bd973f1a43a5239488bc Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Fri, 11 Oct 2024 14:50:48 +0200 Subject: [PATCH] Improve ReconcileDependencies for VM Operator to handle concurrency on availabityZone changes --- test/framework/vmoperator/vmoperator.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/test/framework/vmoperator/vmoperator.go b/test/framework/vmoperator/vmoperator.go index 7a7c3e8a40..6c5330470f 100644 --- a/test/framework/vmoperator/vmoperator.go +++ b/test/framework/vmoperator/vmoperator.go @@ -243,7 +243,7 @@ func ReconcileDependencies(ctx context.Context, c client.Client, dependenciesCon }, } - _ = wait.PollUntilContextTimeout(ctx, 250*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (bool, error) { + _ = wait.PollUntilContextTimeout(ctx, 1*time.Second, 20*time.Second, true, func(ctx context.Context) (bool, error) { retryError = nil if err := c.Get(ctx, client.ObjectKeyFromObject(availabilityZone), availabilityZone); err != nil { if !apierrors.IsNotFound(err) { @@ -256,23 +256,24 @@ func ReconcileDependencies(ctx context.Context, c client.Client, dependenciesCon } log.Info("Created vm-operator AvailabilityZone", "AvailabilityZone", klog.KObj(availabilityZone)) } + + if _, ok := availabilityZone.Spec.Namespaces[config.Namespace]; !ok { + availabilityZone.Spec.Namespaces[config.Namespace] = topologyv1.NamespaceInfo{ + PoolMoId: resourcePool.Reference().Value, + FolderMoId: folder.Reference().Value, + } + if err := c.Update(ctx, availabilityZone); err != nil { + retryError = errors.Wrapf(err, "failed to update AvailabilityZone %s", availabilityZone.Name) + return false, nil + } + log.Info("Update vm-operator AvailabilityZone", "AvailabilityZone", klog.KObj(availabilityZone)) + } return true, nil }) if retryError != nil { return retryError } - if _, ok := availabilityZone.Spec.Namespaces[config.Namespace]; !ok { - availabilityZone.Spec.Namespaces[config.Namespace] = topologyv1.NamespaceInfo{ - PoolMoId: resourcePool.Reference().Value, - FolderMoId: folder.Reference().Value, - } - if err := c.Update(ctx, availabilityZone); err != nil { - return errors.Wrapf(err, "failed to update AvailabilityZone %s", availabilityZone.Name) - } - log.Info("Update vm-operator AvailabilityZone", "AvailabilityZone", klog.KObj(availabilityZone)) - } - // Create vm-operator Secret in K8s // This secret contains credentials to access vCenter the vm-operator acts on. secret := &corev1.Secret{