Fix DaemonSet status update retry

It's easy to get update conflict when processing a DaemonSet
continuously. storeDaemonSetStatus had a retry logic that it gets the
resource from apiserver to update the DaemonSet with the latest resource
version. However, it never really retried because of a wrong check and
always made an useless get call. This patch fixes the logic to allow
the function retry once on update error.
This commit is contained in:
Quan Tian
2021-02-24 19:21:36 +08:00
parent 4fccba9e06
commit 60bb2a3a6f
2 changed files with 82 additions and 1 deletions

View File

@@ -1069,7 +1069,7 @@ func storeDaemonSetStatus(dsClient unversionedapps.DaemonSetInterface, ds *apps.
toUpdate := ds.DeepCopy()
var updateErr, getErr error
for i := 0; i < StatusUpdateRetries; i++ {
for i := 0; ; i++ {
if updateObservedGen {
toUpdate.Status.ObservedGeneration = ds.Generation
}
@@ -1085,6 +1085,10 @@ func storeDaemonSetStatus(dsClient unversionedapps.DaemonSetInterface, ds *apps.
return nil
}
// Stop retrying if we exceed statusUpdateRetries - the DaemonSet will be requeued with a rate limit.
if i >= StatusUpdateRetries {
break
}
// Update the set with the latest resource version for the next poll
if toUpdate, getErr = dsClient.Get(context.TODO(), ds.Name, metav1.GetOptions{}); getErr != nil {
// If the GET fails we can't trust status.Replicas anymore. This error