Skip to content

Commit

Permalink
Merge pull request #2090 from alvaroaleman/started
Browse files Browse the repository at this point in the history
🐛 Prevent manager from getting started a second time
  • Loading branch information
k8s-ci-robot committed Dec 11, 2022
2 parents a8c8ff5 + fa88a73 commit 222fb66
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/manager/internal.go
Expand Up @@ -409,6 +409,8 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) {
cm.Unlock()
return errors.New("manager already started")
}
cm.started = true

var ready bool
defer func() {
// Only unlock the manager if we haven't reached
Expand Down
23 changes: 23 additions & 0 deletions pkg/manager/manager_test.go
Expand Up @@ -1492,6 +1492,29 @@ var _ = Describe("manger.Manager", func() {
Expect(err).NotTo(HaveOccurred())
Expect(m.Add(&failRec{})).To(HaveOccurred())
})

It("should fail if attempted to start a second time", func() {
m, err := New(cfg, Options{})
Expect(err).NotTo(HaveOccurred())

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
defer GinkgoRecover()
Expect(m.Start(ctx)).NotTo(HaveOccurred())
}()
// Wait for the Manager to start
Eventually(func() bool {
mgr, ok := m.(*controllerManager)
Expect(ok).To(BeTrue())
return mgr.runnables.Caches.Started()
}).Should(BeTrue())

err = m.Start(ctx)
Expect(err).ToNot(BeNil())
Expect(err.Error()).To(Equal("manager already started"))

})
})
Describe("SetFields", func() {
It("should inject field values", func() {
Expand Down

0 comments on commit 222fb66

Please sign in to comment.