Skip to content

🐛 Prefer reconciler from controller.Options #1022

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

Merged
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: 3 additions & 1 deletion pkg/builder/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ func (blder *Builder) doController(r reconcile.Reconciler) error {
return err
}
ctrlOptions := blder.ctrlOptions
ctrlOptions.Reconciler = r
if ctrlOptions.Reconciler == nil {
ctrlOptions.Reconciler = r
}
blder.ctrl, err = newController(name, blder.mgr, ctrlOptions)
return err
}
27 changes: 27 additions & 0 deletions pkg/builder/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"
)

type typedNoop struct{}

func (typedNoop) Reconcile(reconcile.Request) (reconcile.Result, error) {
return reconcile.Result{}, nil
}

var _ = Describe("application", func() {
var stop chan struct{}

Expand Down Expand Up @@ -151,6 +157,27 @@ var _ = Describe("application", func() {
Expect(instance).NotTo(BeNil())
})

It("should prefer reconciler from options during creation of controller", func() {
newController = func(name string, mgr manager.Manager, options controller.Options) (controller.Controller, error) {
if options.Reconciler != (typedNoop{}) {
return nil, fmt.Errorf("Custom reconciler expected %T but found %T", typedNoop{}, options.Reconciler)
}
return controller.New(name, mgr, options)
}

By("creating a controller manager")
m, err := manager.New(cfg, manager.Options{})
Expect(err).NotTo(HaveOccurred())

instance, err := ControllerManagedBy(m).
For(&appsv1.ReplicaSet{}).
Owns(&appsv1.ReplicaSet{}).
WithOptions(controller.Options{Reconciler: typedNoop{}}).
Build(noop)
Expect(err).NotTo(HaveOccurred())
Expect(instance).NotTo(BeNil())
})

It("should allow multiple controllers for the same kind", func() {
By("creating a controller manager")
m, err := manager.New(cfg, manager.Options{})
Expand Down