Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controller

import (
"context"
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -126,6 +127,9 @@ func (c *Controller) Start(stop <-chan struct{}) error {
// use an IIFE to get proper lock handling
// but lock outside to get proper handling of the queue shutdown
c.mu.Lock()
if c.Started {
return errors.New("controller was started more than once. This is likely to be caused by being added to a manager multiple times")
}

c.Queue = c.MakeQueue()
defer c.Queue.ShutDown() // needs to be outside the iife so that we shutdown after the stop channel is closed
Expand Down
11 changes: 11 additions & 0 deletions pkg/internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ var _ = Describe("controller", func() {
close(stopped)
Expect(ctrl.Start(stopped)).To(Equal(err))
})

It("should return an error if it gets started more than once", func() {
// Use a stopped channel so Start doesn't block
stopped := make(chan struct{})
close(stopped)
Expect(ctrl.Start(stopped)).To(BeNil())
err := ctrl.Start(stopped)
Expect(err).NotTo(BeNil())
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"))
})

})

Describe("Watch", func() {
Expand Down