Update first in RetryOnConflict

Signed-off-by: Rishi Kumar Ray <rishi.ray@knoldus.com>
This commit is contained in:
Rishi Kumar Ray 2022-01-26 14:33:24 +05:30
parent 3d7770332b
commit 893fbefa50
1 changed files with 12 additions and 4 deletions

View File

@ -271,10 +271,18 @@ func (c *Controller) updateAppliedCondition(work *workv1alpha1.Work, status meta
}
return retry.RetryOnConflict(retry.DefaultRetry, func() (err error) {
if err = c.Get(context.TODO(), client.ObjectKey{Namespace: work.Namespace, Name: work.Name}, work); err != nil {
return err
}
meta.SetStatusCondition(&work.Status.Conditions, newWorkAppliedCondition)
return c.Status().Update(context.TODO(), work)
updateErr := c.Status().Update(context.TODO(), work)
if updateErr == nil {
return nil
}
updated := &workv1alpha1.Work{}
if err = c.Get(context.TODO(), client.ObjectKey{Namespace: work.Namespace, Name: work.Name}, updated); err == nil {
// make a copy, so we don't mutate the shared cache
work = updated.DeepCopy()
} else {
klog.Errorf("failed to get updated work %s/%s: %v", work.Namespace, work.Name, err)
}
return updateErr
})
}