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:
parent
11ba5f5ef6
commit
9aa1024097
|
|
@ -177,7 +177,9 @@ func (u *RetryingCriticalAnnotationUpdater) UpdateCriticalAnnotations(ctx contex
|
||||||
err := retry.OnError(retry.DefaultRetry, resource.IsAPIError, func() error {
|
err := retry.OnError(retry.DefaultRetry, resource.IsAPIError, func() error {
|
||||||
err := u.client.Update(ctx, o)
|
err := u.client.Update(ctx, o)
|
||||||
if kerrors.IsConflict(err) {
|
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)
|
meta.AddAnnotations(o, a)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -413,6 +413,26 @@ func TestRetryingCriticalAnnotationUpdater(t *testing.T) {
|
||||||
o: &fake.Managed{},
|
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": {
|
"Success": {
|
||||||
reason: "We should return without error if we successfully update our annotations",
|
reason: "We should return without error if we successfully update our annotations",
|
||||||
c: &test.MockClient{
|
c: &test.MockClient{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue