Skip to content

Commit a78d8f4

Browse files
committed
CreateOrUpdate call CreateOrUpdateWithRetries with 3 default retries when err is conflict.
1 parent 69ce063 commit a78d8f4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tests/e2e/lib/dpa_helpers.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"log"
1111
"reflect"
1212
"strings"
13+
"time"
1314

1415
"github.com/openshift/oadp-operator/pkg/common"
1516

@@ -139,6 +140,9 @@ func (v *DpaCustomResource) GetNoErr() *oadpv1alpha1.DataProtectionApplication {
139140
}
140141

141142
func (v *DpaCustomResource) CreateOrUpdate(spec *oadpv1alpha1.DataProtectionApplicationSpec) error {
143+
return v.CreateOrUpdateWithRetries(spec, 3)
144+
}
145+
func (v *DpaCustomResource) CreateOrUpdateWithRetries(spec *oadpv1alpha1.DataProtectionApplicationSpec, retries int) error {
142146
cr, err := v.Get()
143147
if apierrors.IsNotFound(err) {
144148
v.Build(v.backupRestoreType)
@@ -149,7 +153,15 @@ func (v *DpaCustomResource) CreateOrUpdate(spec *oadpv1alpha1.DataProtectionAppl
149153
return err
150154
}
151155
cr.Spec = *spec
152-
return v.Client.Update(context.Background(), cr)
156+
if err := v.Client.Update(context.Background(), cr); err != nil {
157+
if apierrors.IsConflict(err) && retries > 0 {
158+
log.Println("conflict detected during DPA CreateOrUpdate, retrying for ", retries, " more times")
159+
time.Sleep(time.Second * 2)
160+
return v.CreateOrUpdateWithRetries(spec, retries-1)
161+
}
162+
return err
163+
}
164+
return nil
153165
}
154166

155167
func (v *DpaCustomResource) Delete() error {

0 commit comments

Comments
 (0)