Unverified Commit ccef02e0 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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 ```
parents 76e9fdaa fd7a6944
...@@ -19,6 +19,7 @@ package daemon ...@@ -19,6 +19,7 @@ package daemon
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"reflect"
"sort" "sort"
"github.com/golang/glog" "github.com/golang/glog"
...@@ -346,11 +347,15 @@ func (dsc *DaemonSetsController) snapshot(ds *apps.DaemonSet, revision int64) (* ...@@ -346,11 +347,15 @@ func (dsc *DaemonSetsController) snapshot(ds *apps.DaemonSet, revision int64) (*
} }
// Handle name collisions between different history // 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{}) currDS, getErr := dsc.kubeClient.ExtensionsV1beta1().DaemonSets(ds.Namespace).Get(ds.Name, metav1.GetOptions{})
if getErr != nil { if getErr != nil {
return nil, getErr 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 { if currDS.Status.CollisionCount == nil {
currDS.Status.CollisionCount = new(int32) currDS.Status.CollisionCount = new(int32)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment