Skip to content

Commit 5a47857

Browse files
committedJun 26, 2018
address feedback on PR 48
#48
1 parent d5af5c5 commit 5a47857

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed
 

‎pkg/cache/internal/informers_map.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ func (ip *InformersMap) Get(gvk schema.GroupVersionKind, obj runtime.Object) (*M
163163
})
164164
i = &MapEntry{
165165
Informer: ni,
166-
Reader: CacheReader{indexer: ni.GetIndexer(), groupVersionKind: gvk}}
166+
Reader: CacheReader{indexer: ni.GetIndexer(), groupVersionKind: gvk},
167+
}
167168
ip.informersByGVK[gvk] = i
168169

169170
// Start the Informer if need by

‎pkg/controller/controller.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ type Controller interface {
5050
//
5151
// Watch may be provided one or more Predicates to filter events before they are given to the EventHandler.
5252
// Events will be passed to the EventHandler iff all provided Predicates evaluate to true.
53-
Watch(src source.Source, evthdler handler.EventHandler, prct ...predicate.Predicate) error
53+
Watch(src source.Source, eventhandler handler.EventHandler, predicates ...predicate.Predicate) error
5454

5555
// Start starts the controller. Start blocks until stop is closed or a controller has an error starting.
5656
Start(stop <-chan struct{}) error
5757
}
5858

5959
// New returns a new Controller registered with the Manager. The Manager will ensure that shared Caches have
6060
// been synced before the Controller is Started.
61-
func New(name string, mrg manager.Manager, options Options) (Controller, error) {
61+
func New(name string, mgr manager.Manager, options Options) (Controller, error) {
6262
if options.Reconciler == nil {
6363
return nil, fmt.Errorf("must specify Reconciler")
6464
}
@@ -72,23 +72,23 @@ func New(name string, mrg manager.Manager, options Options) (Controller, error)
7272
}
7373

7474
// Inject dependencies into Reconciler
75-
if err := mrg.SetFields(options.Reconciler); err != nil {
75+
if err := mgr.SetFields(options.Reconciler); err != nil {
7676
return nil, err
7777
}
7878

7979
// Create controller with dependencies set
8080
c := &controller.Controller{
8181
Do: options.Reconciler,
82-
Cache: mrg.GetCache(),
83-
Config: mrg.GetConfig(),
84-
Scheme: mrg.GetScheme(),
85-
Client: mrg.GetClient(),
86-
Recorder: mrg.GetRecorder(name),
82+
Cache: mgr.GetCache(),
83+
Config: mgr.GetConfig(),
84+
Scheme: mgr.GetScheme(),
85+
Client: mgr.GetClient(),
86+
Recorder: mgr.GetRecorder(name),
8787
Queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), name),
8888
MaxConcurrentReconciles: options.MaxConcurrentReconciles,
8989
Name: name,
9090
}
9191

9292
// Add the controller as a Manager components
93-
return c, mrg.Add(c)
93+
return c, mgr.Add(c)
9494
}

‎pkg/doc.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ ReplicaSet with controller=true.
6262
* Reconciler contains all of the business logic of a Controller.
6363
6464
* Reconciler typically works on a single object type. - e.g. it will only reconcile ReplicaSets. For separate
65-
types use separate Controllers.
65+
types use separate Controllers. If you wish to trigger reconciles from other objects, you can provide
66+
a mapping (e.g. owner references) that maps the object that triggers the reconcile to the object being reconciled.
6667
6768
* Reconciler is provided the Name / Namespace of the object to reconcile.
6869
@@ -108,11 +109,12 @@ Predicate
108109
predicate.Predicate is an optional argument to Controller.Watch that filters events. This allows common filters to be
109110
reused and composed.
110111
111-
* Predicate takes and event and returns a bool (true to enqueue)
112+
* Predicate takes an event and returns a bool (true to enqueue)
112113
113114
* Predicates are optional arguments
114115
115-
* Users SHOULD use the provided Predicate implementations, but MAY implement additional Predicates.
116+
* Users SHOULD use the provided Predicate implementations, but MAY implement additional
117+
Predicates e.g. generation changed, label selectors changed etc.
116118
117119
PodController Diagram
118120

‎pkg/handler/enqueue_owner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (e *EnqueueRequestForOwner) parseOwnerTypeGroupKind(scheme *runtime.Scheme)
9595
}
9696
// Expect only 1 kind. If there is more than one kind this is probably an edge case such as ListOptions.
9797
if len(kinds) != 1 {
98-
err := fmt.Errorf("Expected exactly 1 kind for OwnerType")
98+
err := fmt.Errorf("Expected exactly 1 kind for OwnerType %T, but found %s kinds", e.OwnerType, kinds)
9999
log.Error(err, "", "OwnerType", e.OwnerType, "Kinds", kinds)
100100
return err
101101

‎pkg/internal/controller/controller.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type Controller struct {
7171
// the Queue for processing
7272
Queue workqueue.RateLimitingInterface
7373

74-
// SetFields is used to SetFields dependencies into other objects such as Sources, EventHandlers and Predicates
74+
// SetFields is used to inject dependencies into other objects such as Sources, EventHandlers and Predicates
7575
SetFields func(i interface{}) error
7676

7777
// mu is used to synchronize Controller setup
@@ -126,7 +126,7 @@ func (c *Controller) Start(stop <-chan struct{}) error {
126126
c.mu.Lock()
127127
defer c.mu.Unlock()
128128

129-
// TODO)(pwittrock): Reconsider HandleCrash
129+
// TODO(pwittrock): Reconsider HandleCrash
130130
defer utilruntime.HandleCrash()
131131
defer c.Queue.ShutDown()
132132

@@ -146,10 +146,10 @@ func (c *Controller) Start(stop <-chan struct{}) error {
146146
}
147147

148148
if c.JitterPeriod == 0 {
149-
c.JitterPeriod = time.Second
149+
c.JitterPeriod = 1 * time.Second
150150
}
151151

152-
// Launch two workers to process resources
152+
// Launch workers to process resources
153153
log.Info("Starting workers", "Controller", c.Name, "WorkerCount", c.MaxConcurrentReconciles)
154154
for i := 0; i < c.MaxConcurrentReconciles; i++ {
155155
// Process work items

0 commit comments

Comments
 (0)
Please sign in to comment.