File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ package controller
1818
1919import (
2020 "context"
21+ "errors"
2122 "fmt"
2223 "sync"
2324 "time"
@@ -126,6 +127,9 @@ func (c *Controller) Start(stop <-chan struct{}) error {
126127 // use an IIFE to get proper lock handling
127128 // but lock outside to get proper handling of the queue shutdown
128129 c .mu .Lock ()
130+ if c .Started {
131+ return errors .New ("controller was started more than once. This is likely to be caused by being added to a manager multiple times" )
132+ }
129133
130134 c .Queue = c .MakeQueue ()
131135 defer c .Queue .ShutDown () // needs to be outside the iife so that we shutdown after the stop channel is closed
Original file line number Diff line number Diff line change @@ -162,6 +162,17 @@ var _ = Describe("controller", func() {
162162 close (stopped )
163163 Expect (ctrl .Start (stopped )).To (Equal (err ))
164164 })
165+
166+ It ("should return an error if it gets started more than once" , func () {
167+ // Use a stopped channel so Start doesn't block
168+ stopped := make (chan struct {})
169+ close (stopped )
170+ Expect (ctrl .Start (stopped )).To (BeNil ())
171+ err := ctrl .Start (stopped )
172+ Expect (err ).NotTo (BeNil ())
173+ Expect (err .Error ()).To (Equal ("controller was started more than once. This is likely to be caused by being added to a manager multiple times" ))
174+ })
175+
165176 })
166177
167178 Describe ("Watch" , func () {
You can’t perform that action at this time.
0 commit comments