From 8adcefc626f06f1cce7076be98432a931ae52b44 Mon Sep 17 00:00:00 2001 From: Konstantin Khlebnikov Date: Wed, 23 Oct 2024 15:09:50 +0200 Subject: [PATCH] tests: retry object updates in testhelper --- pkg/testutil/testhelper.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/testutil/testhelper.go b/pkg/testutil/testhelper.go index e3f2e7ba..2ebc993b 100644 --- a/pkg/testutil/testhelper.go +++ b/pkg/testutil/testhelper.go @@ -15,6 +15,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + "k8s.io/client-go/util/retry" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" @@ -165,10 +166,11 @@ func DeployObject(h *TestHelper, object client.Object) { func UpdateObject(h *TestHelper, emptyObject, newObject client.Object) { k8sCli := h.GetK8sClient() - GetObject(h, newObject.GetName(), emptyObject) - - newObject.SetResourceVersion(emptyObject.GetResourceVersion()) - err := k8sCli.Update(context.Background(), newObject) + err := retry.RetryOnConflict(retry.DefaultRetry, func() error { + GetObject(h, newObject.GetName(), emptyObject) + newObject.SetResourceVersion(emptyObject.GetResourceVersion()) + return k8sCli.Update(context.Background(), newObject) + }) require.NoError(h.t, err) } func UpdateObjectStatus(h *TestHelper, newObject client.Object) {