mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-01 18:58:18 +00:00
garbagecollector: add initialSyncTimeout for Run
Signed-off-by: haorenfsa <haorenfsa@gmail.com>
This commit is contained in:
@@ -129,7 +129,7 @@ func (gc *GarbageCollector) resyncMonitors(logger klog.Logger, deletableResource
|
||||
}
|
||||
|
||||
// Run starts garbage collector workers.
|
||||
func (gc *GarbageCollector) Run(ctx context.Context, workers int) {
|
||||
func (gc *GarbageCollector) Run(ctx context.Context, workers int, initialSyncTimeout time.Duration) {
|
||||
defer utilruntime.HandleCrash()
|
||||
defer gc.attemptToDelete.ShutDown()
|
||||
defer gc.attemptToOrphan.ShutDown()
|
||||
@@ -146,7 +146,7 @@ func (gc *GarbageCollector) Run(ctx context.Context, workers int) {
|
||||
|
||||
go gc.dependencyGraphBuilder.Run(ctx)
|
||||
|
||||
if !cache.WaitForNamedCacheSync("garbage collector", waitForStopOrTimeout(ctx.Done(), 30*time.Second), func() bool {
|
||||
if !cache.WaitForNamedCacheSync("garbage collector", waitForStopOrTimeout(ctx.Done(), initialSyncTimeout), func() bool {
|
||||
return gc.dependencyGraphBuilder.IsSynced(logger)
|
||||
}) {
|
||||
logger.Info("Garbage collector: all resource monitors could not be synced, proceeding anyways")
|
||||
|
||||
@@ -124,7 +124,7 @@ func TestGarbageCollectorConstruction(t *testing.T) {
|
||||
}
|
||||
assert.Len(t, gc.dependencyGraphBuilder.monitors, 1)
|
||||
|
||||
go gc.Run(tCtx, 1)
|
||||
go gc.Run(tCtx, 1, 5*time.Second)
|
||||
|
||||
err = gc.resyncMonitors(logger, twoResources)
|
||||
if err != nil {
|
||||
@@ -914,7 +914,8 @@ func TestGarbageCollectorSync(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
go gc.Run(tCtx, 1)
|
||||
syncPeriod := 200 * time.Millisecond
|
||||
go gc.Run(tCtx, 1, syncPeriod)
|
||||
// The pseudo-code of GarbageCollector.Sync():
|
||||
// GarbageCollector.Sync(client, period, stopCh):
|
||||
// wait.Until() loops with `period` until the `stopCh` is closed :
|
||||
@@ -929,7 +930,7 @@ func TestGarbageCollectorSync(t *testing.T) {
|
||||
// The 1s sleep in the test allows GetDeletableResources and
|
||||
// gc.resyncMonitors to run ~5 times to ensure the changes to the
|
||||
// fakeDiscoveryClient are picked up.
|
||||
go gc.Sync(tCtx, fakeDiscoveryClient, 200*time.Millisecond)
|
||||
go gc.Sync(tCtx, fakeDiscoveryClient, syncPeriod)
|
||||
|
||||
// Wait until the sync discovers the initial resources
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
Reference in New Issue
Block a user