Merge pull request #67461 from janetkuo/ds-collision-count

Automatic merge from submit-queue (batch tested with PRs 67461, 67464, 67416). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Avoid unnecessary DaemonSet collisionCount bump

**What this PR does / why we need it**: Sometimes DaemonSet controller will bump its collisionCount more than necessary when the collisionCount of the DaemonSet in the cache store hasn't been updated. This won't affect users, as collisionCount is only used for creating unique hash and the number doesn't matter as long as it changes. This fix avoids the unnecessary collisionCount updates and de-flakes the DaemonSet test for collisionCount. 

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #67273

**Special notes for your reviewer**: @kubernetes/sig-apps-pr-reviews 

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2018-08-15 20:09:05 -07:00 committed by GitHub
commit ccef02e04f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ package daemon
import (
"bytes"
"fmt"
"reflect"
"sort"
"github.com/golang/glog"
@ -346,11 +347,15 @@ func (dsc *DaemonSetsController) snapshot(ds *apps.DaemonSet, revision int64) (*
}
// Handle name collisions between different history
// TODO: Is it okay to get from dsLister?
// Get the latest DaemonSet from the API server to make sure collision count is only increased when necessary
currDS, getErr := dsc.kubeClient.ExtensionsV1beta1().DaemonSets(ds.Namespace).Get(ds.Name, metav1.GetOptions{})
if getErr != nil {
return nil, getErr
}
// If the collision count used to compute hash was in fact stale, there's no need to bump collision count; retry again
if !reflect.DeepEqual(currDS.Status.CollisionCount, ds.Status.CollisionCount) {
return nil, fmt.Errorf("found a stale collision count (%d, expected %d) of DaemonSet %q while processing; will retry until it is updated", ds.Status.CollisionCount, currDS.Status.CollisionCount, ds.Name)
}
if currDS.Status.CollisionCount == nil {
currDS.Status.CollisionCount = new(int32)
}