Skip to content

Commit

Permalink
Merge pull request #520 from awesomenix/master
Browse files Browse the repository at this point in the history
🐛 surface controller options when using builder
  • Loading branch information
k8s-ci-robot committed Aug 5, 2019
2 parents dc83571 + 8102998 commit 335a587
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/builder/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Builder struct {
watchRequest []watchRequest
config *rest.Config
ctrl controller.Controller
ctrlOptions controller.Options
name string
}

Expand Down Expand Up @@ -107,6 +108,12 @@ func (blder *Builder) WithEventFilter(p predicate.Predicate) *Builder {
return blder
}

// WithOptions overrides the controller options use in doController. Defaults to empty.
func (blder *Builder) WithOptions(options controller.Options) *Builder {
blder.ctrlOptions = options
return blder
}

// Named sets the name of the controller to the given name. The name shows up
// in metrics, among other things, and thus should be a prometheus compatible name
// (underscores and alphanumeric characters only).
Expand Down Expand Up @@ -201,6 +208,8 @@ func (blder *Builder) doController(r reconcile.Reconciler) error {
if err != nil {
return err
}
blder.ctrl, err = newController(name, blder.mgr, controller.Options{Reconciler: r})
ctrlOptions := blder.ctrlOptions
ctrlOptions.Reconciler = r
blder.ctrl, err = newController(name, blder.mgr, ctrlOptions)
return err
}
18 changes: 18 additions & 0 deletions pkg/builder/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ var _ = Describe("application", func() {
Expect(instance).To(BeNil())
})

It("should override max concurrent reconcilers during creation of controller", func() {
const maxConcurrentReconciles = 5
newController = func(name string, mgr manager.Manager, options controller.Options) (
controller.Controller, error) {
if options.MaxConcurrentReconciles == maxConcurrentReconciles {
return controller.New(name, mgr, options)
}
return nil, fmt.Errorf("max concurrent reconcilers expected %d but found %d", maxConcurrentReconciles, options.MaxConcurrentReconciles)
}
instance, err := SimpleController().
For(&appsv1.ReplicaSet{}).
Owns(&appsv1.ReplicaSet{}).
WithOptions(controller.Options{MaxConcurrentReconciles: maxConcurrentReconciles}).
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

0 comments on commit 335a587

Please sign in to comment.