Skip to content

Commit 87ca404

Browse files
committed
garbagecollector: add initialSyncTimeout for Run
Signed-off-by: haorenfsa <[email protected]>
1 parent d4fdfaf commit 87ca404

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

cmd/kube-controller-manager/app/core.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,12 @@ func startGarbageCollectorController(ctx context.Context, controllerContext Cont
698698

699699
// Start the garbage collector.
700700
workers := int(controllerContext.ComponentConfig.GarbageCollectorController.ConcurrentGCSyncs)
701-
go garbageCollector.Run(ctx, workers)
701+
const syncPeriod = 30 * time.Second
702+
go garbageCollector.Run(ctx, workers, syncPeriod)
702703

703704
// Periodically refresh the RESTMapper with new discovery information and sync
704705
// the garbage collector.
705-
go garbageCollector.Sync(ctx, discoveryClient, 30*time.Second)
706+
go garbageCollector.Sync(ctx, discoveryClient, syncPeriod)
706707

707708
return garbageCollector, true, nil
708709
}

pkg/controller/garbagecollector/garbagecollector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (gc *GarbageCollector) resyncMonitors(logger klog.Logger, deletableResource
129129
}
130130

131131
// Run starts garbage collector workers.
132-
func (gc *GarbageCollector) Run(ctx context.Context, workers int) {
132+
func (gc *GarbageCollector) Run(ctx context.Context, workers int, initialSyncTimeout time.Duration) {
133133
defer utilruntime.HandleCrash()
134134
defer gc.attemptToDelete.ShutDown()
135135
defer gc.attemptToOrphan.ShutDown()
@@ -146,7 +146,7 @@ func (gc *GarbageCollector) Run(ctx context.Context, workers int) {
146146

147147
go gc.dependencyGraphBuilder.Run(ctx)
148148

149-
if !cache.WaitForNamedCacheSync("garbage collector", waitForStopOrTimeout(ctx.Done(), 30*time.Second), func() bool {
149+
if !cache.WaitForNamedCacheSync("garbage collector", waitForStopOrTimeout(ctx.Done(), initialSyncTimeout), func() bool {
150150
return gc.dependencyGraphBuilder.IsSynced(logger)
151151
}) {
152152
logger.Info("Garbage collector: all resource monitors could not be synced, proceeding anyways")

pkg/controller/garbagecollector/garbagecollector_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func TestGarbageCollectorConstruction(t *testing.T) {
124124
}
125125
assert.Len(t, gc.dependencyGraphBuilder.monitors, 1)
126126

127-
go gc.Run(tCtx, 1)
127+
go gc.Run(tCtx, 1, 5*time.Second)
128128

129129
err = gc.resyncMonitors(logger, twoResources)
130130
if err != nil {
@@ -914,7 +914,8 @@ func TestGarbageCollectorSync(t *testing.T) {
914914
t.Fatal(err)
915915
}
916916

917-
go gc.Run(tCtx, 1)
917+
syncPeriod := 200 * time.Millisecond
918+
go gc.Run(tCtx, 1, syncPeriod)
918919
// The pseudo-code of GarbageCollector.Sync():
919920
// GarbageCollector.Sync(client, period, stopCh):
920921
// wait.Until() loops with `period` until the `stopCh` is closed :
@@ -929,7 +930,7 @@ func TestGarbageCollectorSync(t *testing.T) {
929930
// The 1s sleep in the test allows GetDeletableResources and
930931
// gc.resyncMonitors to run ~5 times to ensure the changes to the
931932
// fakeDiscoveryClient are picked up.
932-
go gc.Sync(tCtx, fakeDiscoveryClient, 200*time.Millisecond)
933+
go gc.Sync(tCtx, fakeDiscoveryClient, syncPeriod)
933934

934935
// Wait until the sync discovers the initial resources
935936
time.Sleep(1 * time.Second)

test/integration/garbagecollector/garbage_collector_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func setupWithServer(t *testing.T, result *kubeapiservertesting.TestServer, work
301301
// mapper, but we'll deal with it for now.
302302
restMapper.Reset()
303303
}, syncPeriod, tCtx.Done())
304-
go gc.Run(tCtx, workers)
304+
go gc.Run(tCtx, workers, syncPeriod)
305305
go gc.Sync(tCtx, clientSet.Discovery(), syncPeriod)
306306
}
307307

@@ -1371,6 +1371,8 @@ func TestCascadingDeleteOnCRDConversionFailure(t *testing.T) {
13711371
}
13721372

13731373
ctx.startGC(5)
1374+
// make sure gc.Sync finds the new CRD and starts monitoring it
1375+
time.Sleep(ctx.syncPeriod + 1*time.Second)
13741376

13751377
rcClient := clientSet.CoreV1().ReplicationControllers(ns.Name)
13761378
podClient := clientSet.CoreV1().Pods(ns.Name)

test/integration/util/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func CreateGCController(ctx context.Context, tb ktesting.TB, restConfig restclie
219219
go wait.Until(func() {
220220
restMapper.Reset()
221221
}, syncPeriod, ctx.Done())
222-
go gc.Run(ctx, 1)
222+
go gc.Run(ctx, 1, syncPeriod)
223223
go gc.Sync(ctx, clientSet.Discovery(), syncPeriod)
224224
}
225225
return startGC

0 commit comments

Comments
 (0)