File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ import (
42
42
"sigs.k8s.io/controller-runtime/pkg/handler"
43
43
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/internal/controller/metrics"
44
44
"sigs.k8s.io/controller-runtime/pkg/internal/log"
45
+ "sigs.k8s.io/controller-runtime/pkg/manager"
45
46
"sigs.k8s.io/controller-runtime/pkg/predicate"
46
47
"sigs.k8s.io/controller-runtime/pkg/reconcile"
47
48
"sigs.k8s.io/controller-runtime/pkg/source"
@@ -345,6 +346,30 @@ var _ = Describe("controller", func() {
345
346
Expect (err .Error ()).To (Equal ("can not restart a stopped controller, you should create a new one" ))
346
347
})
347
348
349
+ It ("should be possible to cancel the controller using NewCancelRunnable" , func () {
350
+ stoppedChan := make (chan struct {})
351
+ cancellableController , cancel := manager .NewCancelRunnable (ctrl )
352
+
353
+ go func () {
354
+ defer close (stoppedChan )
355
+ defer GinkgoRecover ()
356
+ Expect (cancellableController .Start (context .Background ())).NotTo (HaveOccurred ())
357
+ }()
358
+
359
+ var started bool
360
+ for ! started {
361
+ func () {
362
+ ctrl .mu .Lock ()
363
+ defer ctrl .mu .Unlock ()
364
+ started = ctrl .Started
365
+ }()
366
+ }
367
+
368
+ cancel ()
369
+
370
+ <- stoppedChan
371
+ Eventually (ctrl .Stopped ).Should (BeTrue ())
372
+ })
348
373
})
349
374
350
375
Describe ("Processing queue items from a Controller" , func () {
You can’t perform that action at this time.
0 commit comments