Skip to content

Commit e561bb9

Browse files
committed
Fixup
1 parent 22d9893 commit e561bb9

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

pkg/builder/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
)
4141

4242
// Supporting mocking out functions for testing.
43-
var newController = controller.New
43+
var newController = controller.NewUnmanaged
4444
var getGvk = apiutil.GVKForObject
4545

4646
// project represents other forms that the we can use to

pkg/builder/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (l *testLogger) WithName(name string) logr.LogSink {
7979

8080
var _ = Describe("application", func() {
8181
BeforeEach(func() {
82-
newController = controller.New
82+
newController = controller.NewUnmanaged
8383
})
8484

8585
noop := reconcile.Func(func(context.Context, reconcile.Request) (reconcile.Result, error) {

pkg/controller/controller.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,21 @@ type Controller interface {
8181
GetLogger() logr.Logger
8282
}
8383

84-
// New returns a new Controller based on the Manager, the caller is responsible
85-
// for adding the controller to the manager as a Runnable.
84+
// New returns a new Controller registered with the Manager. The Manager will ensure that shared Caches have
85+
// been synced before the Controller is Started.
8686
func New(name string, mgr manager.Manager, options Options) (Controller, error) {
87+
c, err := NewUnmanaged(name, mgr, options)
88+
if err != nil {
89+
return nil, err
90+
}
91+
92+
// Add the controller as a Manager components
93+
return c, mgr.Add(c)
94+
}
95+
96+
// NewUnmanaged returns a new Controller based on the Manager, the caller is responsible
97+
// for adding the controller to the manager as a Runnable.
98+
func NewUnmanaged(name string, mgr manager.Manager, options Options) (Controller, error) {
8799
if options.Reconciler == nil {
88100
return nil, fmt.Errorf("must specify Reconciler")
89101
}

pkg/controller/controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ var _ = Describe("controller.Controller", func() {
7575
It("should not leak goroutines when stopped", func() {
7676
currentGRs := goleak.IgnoreCurrent()
7777

78-
ctx, cancel := context.WithCancel(context.Background())
7978
watchChan := make(chan event.GenericEvent, 1)
8079
watch := &source.Channel{Source: watchChan}
8180
watchChan <- event.GenericEvent{Object: &corev1.Pod{}}
@@ -102,20 +101,21 @@ var _ = Describe("controller.Controller", func() {
102101
Expect(c.Watch(watch, &handler.EnqueueRequestForObject{})).To(Succeed())
103102
Expect(err).NotTo(HaveOccurred())
104103

104+
ctx, cancel := context.WithCancel(context.Background())
105105
go func() {
106106
defer GinkgoRecover()
107107
Expect(m.Start(ctx)).To(Succeed())
108108
close(controllerFinished)
109109
}()
110110

111-
<-reconcileStarted
111+
Eventually(reconcileStarted).Should(BeClosed())
112112
cancel()
113-
<-controllerFinished
113+
Eventually(controllerFinished).Should(BeClosed())
114114

115115
// force-close keep-alive connections. These'll time anyway (after
116116
// like 30s or so) but force it to speed up the tests.
117117
clientTransport.CloseIdleConnections()
118-
Eventually(func() error { return goleak.Find(currentGRs) }).Should(Succeed())
118+
Eventually(func() error { return goleak.Find(currentGRs) }, 10*time.Second).Should(Succeed())
119119
})
120120

121121
It("should not create goroutines if never started", func() {

pkg/internal/testing/process/process_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ var _ = Describe("Start method", func() {
5050
HealthCheck: HealthCheck{
5151
URL: getServerURL(server),
5252
},
53+
StopTimeout: 2 * time.Second,
5354
}
54-
processState.Path = "bash"
5555
processState.Args = simpleBashScript
5656

5757
})

0 commit comments

Comments
 (0)