Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Prevent manager from getting started a second time #2090

Merged
merged 1 commit into from Dec 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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