Skip to content

Commit

Permalink
Merge pull request #2415 from sbueringer/pr-minor-builder-multi
Browse files Browse the repository at this point in the history
⚠ builder: return error when multiple reconcilers are set
  • Loading branch information
k8s-ci-robot committed Jul 26, 2023
2 parents 2596de1 + 985569b commit e644e50
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pkg/builder/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ func (blder *Builder) doController(r reconcile.Reconciler) error {
globalOpts := blder.mgr.GetControllerOptions()

ctrlOptions := blder.ctrlOptions
if ctrlOptions.Reconciler != nil && r != nil {
return errors.New("reconciler was set via WithOptions() and via Build() or Complete()")
}
if ctrlOptions.Reconciler == nil {
ctrlOptions.Reconciler = r
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/builder/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ var _ = Describe("application", func() {
Expect(instance).NotTo(BeNil())
})

It("should prefer reconciler from options during creation of controller", func() {
It("should not allow multiple reconcilers 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)
Expand All @@ -315,8 +315,8 @@ var _ = Describe("application", func() {
Owns(&appsv1.ReplicaSet{}).
WithOptions(controller.Options{Reconciler: typedNoop{}}).
Build(noop)
Expect(err).NotTo(HaveOccurred())
Expect(instance).NotTo(BeNil())
Expect(err).To(HaveOccurred())
Expect(instance).To(BeNil())
})

It("should allow multiple controllers for the same kind", func() {
Expand Down

0 comments on commit e644e50

Please sign in to comment.