Skip to content

Commit 046b8f3

Browse files
committed
Address PR comments
1 parent bf51669 commit 046b8f3

37 files changed

+466
-414
lines changed

example/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import (
2121
"flag"
2222
"log"
2323

24+
appsv1 "k8s.io/api/apps/v1"
25+
corev1 "k8s.io/api/core/v1"
26+
"k8s.io/apimachinery/pkg/api/errors"
27+
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
2428
"sigs.k8s.io/controller-runtime/pkg/client"
2529
"sigs.k8s.io/controller-runtime/pkg/client/config"
2630
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -30,10 +34,6 @@ import (
3034
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
3135
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
3236
"sigs.k8s.io/controller-runtime/pkg/source"
33-
appsv1 "k8s.io/api/apps/v1"
34-
corev1 "k8s.io/api/core/v1"
35-
"k8s.io/apimachinery/pkg/api/errors"
36-
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
3737
)
3838

3939
func main() {
@@ -46,22 +46,22 @@ func main() {
4646
log.Fatal(err)
4747
}
4848

49-
// Setup a new controller to Reconcile ReplicaSets
49+
// Setup a new controller to Reconciler ReplicaSets
5050
c, err := controller.New("foo-controller", mrg, controller.Options{
51-
Reconcile: &reconcileReplicaSet{client: mrg.GetClient()},
51+
Reconciler: &reconcileReplicaSet{client: mrg.GetClient()},
5252
})
5353
if err != nil {
5454
log.Fatal(err)
5555
}
5656

5757
// Watch ReplicaSets and enqueue ReplicaSet object key
58-
if err := c.Watch(&source.Kind{Type: &appsv1.ReplicaSet{}}, &handler.Enqueue{}); err != nil {
58+
if err := c.Watch(&source.Kind{Type: &appsv1.ReplicaSet{}}, &handler.EnqueueRequestForObject{}); err != nil {
5959
log.Fatal(err)
6060
}
6161

6262
// Watch Pods and enqueue owning ReplicaSet key
6363
if err := c.Watch(&source.Kind{Type: &corev1.Pod{}},
64-
&handler.EnqueueOwner{OwnerType: &appsv1.ReplicaSet{}, IsController: true}); err != nil {
64+
&handler.EnqueueRequestForOwner{OwnerType: &appsv1.ReplicaSet{}, IsController: true}); err != nil {
6565
log.Fatal(err)
6666
}
6767

@@ -73,8 +73,8 @@ type reconcileReplicaSet struct {
7373
client client.Client
7474
}
7575

76-
// Implement reconcile.Reconcile so the controller can reconcile objects
77-
var _ reconcile.Reconcile = &reconcileReplicaSet{}
76+
// Implement reconcile.Reconciler so the controller can reconcile objects
77+
var _ reconcile.Reconciler = &reconcileReplicaSet{}
7878

7979
func (r *reconcileReplicaSet) Reconcile(request reconcile.Request) (reconcile.Result, error) {
8080
// Fetch the ReplicaSet from the cache

pkg/admission/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Package admission provides functions to manage webhooks certificates.
1919
2020
There are 3 typical ways to use this library:
2121
22-
* The sync function can be used as a Reconcile function.
22+
* The sync function can be used as a Reconciler function.
2323
2424
* Invoking it directly fromt eh webhook server at startup.
2525

pkg/controller/controller.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ type Options struct {
3333
// MaxConcurrentReconciles is the maximum number of concurrent Reconciles which can be run. Defaults to 1.
3434
MaxConcurrentReconciles int
3535

36-
// Reconcile reconciles an object
37-
Reconcile reconcile.Reconcile
36+
// Reconciler reconciles an object
37+
Reconciler reconcile.Reconciler
3838
}
3939

40-
// Controller is a work queue that watches for changes to objects (i.e. Create / Update / Delete events) and
41-
// then reconciles an object (i.e. make changes to ensure the system state matches what is specified in the object).
40+
// Controller implements a Kubernetes API. A Controller manages a work queue fed reconcile.Requests
41+
// from source.Sources. Work is performed through the reconcile.Reconciler for each enqueued item.
42+
// Work typically is reads and writes Kubernetes objects to make the system state match the state specified
43+
// in the object Spec.
4244
type Controller interface {
43-
// Reconcile is called to Reconcile an object by Namespace/Name
44-
reconcile.Reconcile
45+
// Reconciler is called to Reconciler an object by Namespace/Name
46+
reconcile.Reconciler
4547

4648
// Watch takes events provided by a Source and uses the EventHandler to enqueue reconcile.Requests in
4749
// response to the events.
@@ -57,8 +59,8 @@ type Controller interface {
5759
// New returns a new Controller registered with the Manager. The Manager will ensure that shared Caches have
5860
// been synced before the Controller is Started.
5961
func New(name string, mrg manager.Manager, options Options) (Controller, error) {
60-
if options.Reconcile == nil {
61-
return nil, fmt.Errorf("must specify Reconcile")
62+
if options.Reconciler == nil {
63+
return nil, fmt.Errorf("must specify Reconciler")
6264
}
6365

6466
if len(name) == 0 {
@@ -69,14 +71,14 @@ func New(name string, mrg manager.Manager, options Options) (Controller, error)
6971
options.MaxConcurrentReconciles = 1
7072
}
7173

72-
// Inject dependencies into Reconcile
73-
if err := mrg.SetFields(options.Reconcile); err != nil {
74+
// Inject dependencies into Reconciler
75+
if err := mrg.SetFields(options.Reconciler); err != nil {
7476
return nil, err
7577
}
7678

7779
// Create controller with dependencies set
7880
c := &controller.Controller{
79-
Do: options.Reconcile,
81+
Do: options.Reconciler,
8082
Cache: mrg.GetCache(),
8183
Config: mrg.GetConfig(),
8284
Scheme: mrg.GetScheme(),

pkg/controller/controller_integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var _ = Describe("controller", func() {
5656

5757
By("Creating the Controller")
5858
instance, err := controller.New("foo-controller", cm, controller.Options{
59-
Reconcile: reconcile.Func(
59+
Reconciler: reconcile.Func(
6060
func(request reconcile.Request) (reconcile.Result, error) {
6161
reconciled <- request
6262
return reconcile.Result{}, nil
@@ -65,12 +65,12 @@ var _ = Describe("controller", func() {
6565
Expect(err).NotTo(HaveOccurred())
6666

6767
By("Watching Resources")
68-
err = instance.Watch(&source.Kind{Type: &appsv1.ReplicaSet{}}, &handler.EnqueueOwner{
68+
err = instance.Watch(&source.Kind{Type: &appsv1.ReplicaSet{}}, &handler.EnqueueRequestForOwner{
6969
OwnerType: &appsv1.Deployment{},
7070
})
7171
Expect(err).NotTo(HaveOccurred())
7272

73-
err = instance.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.Enqueue{})
73+
err = instance.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForObject{})
7474
Expect(err).NotTo(HaveOccurred())
7575

7676
By("Starting the Manager")

pkg/controller/controller_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,29 @@ var _ = Describe("controller.Controller", func() {
4646
It("should return an error if Name is not Specified", func(done Done) {
4747
m, err := manager.New(cfg, manager.Options{})
4848
Expect(err).NotTo(HaveOccurred())
49-
c, err := controller.New("", m, controller.Options{Reconcile: rec})
49+
c, err := controller.New("", m, controller.Options{Reconciler: rec})
5050
Expect(c).To(BeNil())
5151
Expect(err.Error()).To(ContainSubstring("must specify Name for Controller"))
5252

5353
close(done)
5454
})
5555

56-
It("should return an error if Reconcile is not Specified", func(done Done) {
56+
It("should return an error if Reconciler is not Specified", func(done Done) {
5757
m, err := manager.New(cfg, manager.Options{})
5858
Expect(err).NotTo(HaveOccurred())
5959

6060
c, err := controller.New("foo", m, controller.Options{})
6161
Expect(c).To(BeNil())
62-
Expect(err.Error()).To(ContainSubstring("must specify Reconcile"))
62+
Expect(err.Error()).To(ContainSubstring("must specify Reconciler"))
6363

6464
close(done)
6565
})
6666

67-
It("NewController should return an error if injecting Reconcile fails", func(done Done) {
67+
It("NewController should return an error if injecting Reconciler fails", func(done Done) {
6868
m, err := manager.New(cfg, manager.Options{})
6969
Expect(err).NotTo(HaveOccurred())
7070

71-
c, err := controller.New("foo", m, controller.Options{Reconcile: &failRec{}})
71+
c, err := controller.New("foo", m, controller.Options{Reconciler: &failRec{}})
7272
Expect(c).To(BeNil())
7373
Expect(err).To(HaveOccurred())
7474
Expect(err.Error()).To(ContainSubstring("expected error"))
@@ -78,7 +78,7 @@ var _ = Describe("controller.Controller", func() {
7878
})
7979
})
8080

81-
var _ reconcile.Reconcile = &failRec{}
81+
var _ reconcile.Reconciler = &failRec{}
8282
var _ inject.Client = &failRec{}
8383

8484
type failRec struct{}

pkg/controller/controllerutil/controllerutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727

2828
// SetControllerReference sets owner as a Controller OwnerReference on owned.
2929
// This is used for garbage collection of the owned object and for
30-
// reconciling the owner object on changes to owned (with a Watch + EnqueueOwner).
30+
// reconciling the owner object on changes to owned (with a Watch + EnqueueRequestForOwner).
3131
func SetControllerReference(owner, object v1.Object, scheme *runtime.Scheme) error {
3232
ro, ok := owner.(runtime.Object)
3333
if !ok {

pkg/controller/doc.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ limitations under the License.
1515
*/
1616

1717
/*
18-
Package controller provides types and functions for building Controllers.
18+
Package controller provides types and functions for building Controllers. Controllers implement Kubernetes APIs.
1919
2020
Creation
2121
22-
To create a new Controller, first create a manager.Manager and provide it to New. The Manager will
23-
take care of Starting / Stopping the Controller, as well as provide shared Caches and Clients to the
24-
Sources, EventHandlers, Predicates, and Reconcile.
22+
To create a new Controller, first create a manager.Manager and pass it to the controller.New function.
23+
The Controller MUST be started by calling Manager.Start.
2524
*/
2625
package controller

pkg/controller/example_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var mrg manager.Manager
3434
// manager.Manager will be used to Start the Controller, and will provide it a shared Cache and Client.
3535
func ExampleNew() {
3636
_, err := controller.New("pod-controller", mrg, controller.Options{
37-
Reconcile: reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) {
37+
Reconciler: reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) {
3838
// Your business logic to implement the API by creating, updating, deleting objects goes here.
3939
return reconcile.Result{}, nil
4040
}),
@@ -48,7 +48,7 @@ func ExampleNew() {
4848
// it with the DefaultControllerManager.
4949
func ExampleController() {
5050
_, err := controller.New("pod-controller", mrg, controller.Options{
51-
Reconcile: reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) {
51+
Reconciler: reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) {
5252
// Your business logic to implement the API by creating, updating, deleting objects goes here.
5353
return reconcile.Result{}, nil
5454
}),
@@ -62,7 +62,7 @@ func ExampleController() {
6262
// This example watches Pods and enqueues reconcile.Requests with the changed Pod Name and Namespace.
6363
func ExampleController_Watch() {
6464
c, err := controller.New("pod-controller", mrg, controller.Options{
65-
Reconcile: reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) {
65+
Reconciler: reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) {
6666
// Your business logic to implement the API by creating, updating, deleting objects goes here.
6767
return reconcile.Result{}, nil
6868
}),
@@ -71,7 +71,7 @@ func ExampleController_Watch() {
7171
log.Fatal(err)
7272
}
7373

74-
err = c.Watch(&source.Kind{Type: &v1.Pod{}}, &handler.Enqueue{})
74+
err = c.Watch(&source.Kind{Type: &v1.Pod{}}, &handler.EnqueueRequestForObject{})
7575
if err != nil {
7676
log.Fatal(err)
7777
}

0 commit comments

Comments
 (0)