@@ -29,6 +29,7 @@ import (
29
29
. "github.com/onsi/gomega"
30
30
"github.com/prometheus/client_golang/prometheus"
31
31
dto "github.com/prometheus/client_model/go"
32
+ "go.uber.org/goleak"
32
33
appsv1 "k8s.io/api/apps/v1"
33
34
corev1 "k8s.io/api/core/v1"
34
35
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -1217,7 +1218,9 @@ var _ = Describe("controller", func() {
1217
1218
cfg , err := testenv .Start ()
1218
1219
Expect (err ).NotTo (HaveOccurred ())
1219
1220
m , err := manager .New (cfg , manager.Options {
1220
- LeaderElection : true ,
1221
+ LeaderElection : true ,
1222
+ LeaderElectionID : "some-leader-election-id" ,
1223
+ LeaderElectionNamespace : "default" ,
1221
1224
})
1222
1225
Expect (err ).NotTo (HaveOccurred ())
1223
1226
@@ -1316,6 +1319,50 @@ var _ = Describe("controller", func() {
1316
1319
1317
1320
Eventually (didWatchStart .Load ).Should (BeTrue (), "watch should be started if it is added after Warmup" )
1318
1321
})
1322
+
1323
+ DescribeTable ("should not leak goroutines when manager is stopped with warmup runnable" ,
1324
+ func (leaderElection bool ) {
1325
+ ctx , cancel := context .WithCancel (context .Background ())
1326
+ defer cancel ()
1327
+
1328
+ ctrl .CacheSyncTimeout = time .Second
1329
+
1330
+ By ("Creating a manager" )
1331
+ testenv = & envtest.Environment {}
1332
+ cfg , err := testenv .Start ()
1333
+ Expect (err ).NotTo (HaveOccurred ())
1334
+ m , err := manager .New (cfg , manager.Options {
1335
+ LeaderElection : leaderElection ,
1336
+ LeaderElectionID : "some-leader-election-id" ,
1337
+ LeaderElectionNamespace : "default" ,
1338
+ })
1339
+ Expect (err ).NotTo (HaveOccurred ())
1340
+
1341
+ ctrl .startWatches = []source.TypedSource [reconcile.Request ]{
1342
+ source .Func (func (ctx context.Context , _ workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1343
+ <- ctx .Done ()
1344
+ return nil
1345
+ }),
1346
+ }
1347
+ Expect (m .Add (ctrl )).To (Succeed ())
1348
+
1349
+ // ignore needs to go after the testenv.Start() call to ignore the apiserver
1350
+ // process
1351
+ currentGRs := goleak .IgnoreCurrent ()
1352
+ go func () {
1353
+ defer GinkgoRecover ()
1354
+ Expect (m .Start (ctx )).To (Succeed ())
1355
+ }()
1356
+
1357
+ <- m .Elected ()
1358
+ By ("stopping the manager via context" )
1359
+ cancel ()
1360
+
1361
+ Eventually (func () error { return goleak .Find (currentGRs ) }).Should (Succeed ())
1362
+ },
1363
+ Entry ("manager with leader election enabled" , true ),
1364
+ Entry ("manager without leader election enabled" , false ),
1365
+ )
1319
1366
})
1320
1367
1321
1368
Describe ("Warmup with warmup disabled" , func () {
0 commit comments