Fix retry in update critical annotations

- A successful get after a conflict should not hide the conflict
error and prevent retries.

Signed-off-by: Hasan Turken <turkenh@gmail.com>
This commit is contained in:
Hasan Turken 2023-11-02 12:05:19 +03:00
parent 11ba5f5ef6
commit 9aa1024097
No known key found for this signature in database
GPG Key ID: EE8BB9CB12F58415
2 changed files with 23 additions and 1 deletions

View File

@ -177,7 +177,9 @@ func (u *RetryingCriticalAnnotationUpdater) UpdateCriticalAnnotations(ctx contex
err := retry.OnError(retry.DefaultRetry, resource.IsAPIError, func() error {
err := u.client.Update(ctx, o)
if kerrors.IsConflict(err) {
err = u.client.Get(ctx, types.NamespacedName{Name: o.GetName()}, o)
if getErr := u.client.Get(ctx, types.NamespacedName{Name: o.GetName()}, o); getErr != nil {
return getErr
}
meta.AddAnnotations(o, a)
}
return err

View File

@ -413,6 +413,26 @@ func TestRetryingCriticalAnnotationUpdater(t *testing.T) {
o: &fake.Managed{},
},
},
"SuccessfulGetAfterAConflict": {
reason: "A successful get after a conflict should not hide the conflict error and prevent retries",
c: &test.MockClient{
MockGet: test.NewMockGetFn(nil, setLabels),
MockUpdate: test.NewMockUpdateFn(kerrors.NewConflict(schema.GroupResource{
Group: "foo.com",
Resource: "bars",
}, "abc", errBoom)),
},
args: args{
o: &fake.Managed{},
},
want: want{
err: errors.Wrap(kerrors.NewConflict(schema.GroupResource{
Group: "foo.com",
Resource: "bars",
}, "abc", errBoom), errUpdateCriticalAnnotations),
o: objectReturnedByGet,
},
},
"Success": {
reason: "We should return without error if we successfully update our annotations",
c: &test.MockClient{