Merge pull request #54704 from dims/try-clean-up-stores
Automatic merge from submit-queue (batch tested with PRs 53796, 54666, 54516, 54625, 54704). 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>. Fix TestCRD Flake **What this PR does / why we need it**: The DestroyFunc functions returned by generic.NewRawStorage is never called when we do a StartTestServer() in the test suite. For a quick hack for now, added TrackStorageCleanup/RegisterStorageCleanup and CleanupStorage. Note that unless TrackStorageCleanup is called (which is called only from the test suite) the other two methods are no-ops essentially. So no change in behavior at runtime. This vastly brings down the number of goroutines that are left behind when this test is executed and should reduce if not eliminate the flakiness of TestCRD **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ``` Kubernetes-commit: d7567cd6c7599dd6701890a4cb5575fe959c948d
This commit is contained in:
commit
c68ef826a7
|
@ -65,6 +65,42 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
|
|||
d()
|
||||
}
|
||||
|
||||
// TODO : Remove RegisterStorageCleanup below when PR
|
||||
// https://github.com/kubernetes/kubernetes/pull/50690
|
||||
// merges as that shuts down storage properly
|
||||
RegisterStorageCleanup(destroyFunc)
|
||||
|
||||
return cacher, destroyFunc
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : Remove all the code below when PR
|
||||
// https://github.com/kubernetes/kubernetes/pull/50690
|
||||
// merges as that shuts down storage properly
|
||||
// HACK ALERT : Track the destroy methods to call them
|
||||
// from the test harness. TrackStorageCleanup will be called
|
||||
// only from the test harness, so Register/Cleanup will be
|
||||
// no-op at runtime.
|
||||
|
||||
var cleanup []func() = nil
|
||||
|
||||
func TrackStorageCleanup() {
|
||||
cleanup = make([]func(), 0)
|
||||
}
|
||||
|
||||
func RegisterStorageCleanup(fn func()) {
|
||||
if cleanup == nil {
|
||||
return
|
||||
}
|
||||
cleanup = append(cleanup, fn)
|
||||
}
|
||||
|
||||
func CleanupStorage() {
|
||||
if cleanup == nil {
|
||||
return
|
||||
}
|
||||
for _, d := range cleanup {
|
||||
d()
|
||||
}
|
||||
cleanup = nil
|
||||
}
|
||||
|
|
|
@ -649,6 +649,12 @@ func (c *Cacher) isStopped() bool {
|
|||
}
|
||||
|
||||
func (c *Cacher) Stop() {
|
||||
// TODO : Do not check for isStopped (and return) when PR
|
||||
// https://github.com/kubernetes/kubernetes/pull/50690
|
||||
// merges as that shuts down storage properly
|
||||
if c.isStopped() {
|
||||
return
|
||||
}
|
||||
c.stopLock.Lock()
|
||||
c.stopped = true
|
||||
c.stopLock.Unlock()
|
||||
|
|
Loading…
Reference in New Issue