Skip to content

Commit

Permalink
tests: retry object updates in testhelper
Browse files Browse the repository at this point in the history
  • Loading branch information
koct9i committed Oct 25, 2024
1 parent 638a5d8 commit 8adcefc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/testutil/testhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8adcefc

Please sign in to comment.