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
18
18
19
19
import (
20
20
"context"
21
+ "errors"
21
22
"fmt"
22
23
"sync"
23
24
"time"
@@ -126,6 +127,9 @@ func (c *Controller) Start(stop <-chan struct{}) error {
126
127
// use an IIFE to get proper lock handling
127
128
// but lock outside to get proper handling of the queue shutdown
128
129
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
+ }
129
133
130
134
c .Queue = c .MakeQueue ()
131
135
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() {
162
162
close (stopped )
163
163
Expect (ctrl .Start (stopped )).To (Equal (err ))
164
164
})
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
+
165
176
})
166
177
167
178
Describe ("Watch" , func () {
You can’t perform that action at this time.
0 commit comments