@@ -21,18 +21,18 @@ and are central to building Operators, Workload APIs, Configuration APIs, Autosc
21
21
Controllers
22
22
23
23
Controllers are work queues that enqueue work in response to source.Source events (e.g. Pod Create, Update, Delete)
24
- and trigger reconcile.reconcile functions when the work is dequeued.
24
+ and trigger reconcile.Reconcile functions when the work is dequeued.
25
25
26
26
Unlike http handlers, Controllers DO NOT perform work directly in response to events, but instead enqueue
27
- ReconcileRequests so the work is performed eventually.
27
+ reconcile.Requests so the work is performed eventually.
28
28
29
- * Controllers run reconcile.reconcile functions against objects (provided as name / Namespace).
29
+ * Controllers run reconcile.Reconcile functions against objects (provided as name / Namespace).
30
30
31
- * Controllers enqueue reconcile.ReconcileRequests in response events provided by source.Sources.
31
+ * Controllers enqueue reconcile.Requests in response events provided by source.Sources.
32
32
33
33
reconcile
34
34
35
- reconcile.reconcile is a function that may be called at anytime with the name / Namespace of an
35
+ reconcile.Reconcile is a function that may be called at anytime with the name / Namespace of an
36
36
object. When called, it will ensure that the state of the system matches what is specified in the object at the
37
37
time reconcile is called.
38
38
@@ -42,9 +42,9 @@ ReplicationController.
42
42
43
43
* reconcile works on a single object type. - e.g. it will only reconcile ReplicaSets.
44
44
45
- * reconcile is triggered by a ReconcileRequest containing the name / Namespace of an object to reconcile.
45
+ * reconcile is triggered by a reconcile.Request containing the name / Namespace of an object to reconcile.
46
46
47
- * reconcile does not care about the event contents or event type triggering the ReconcileRequest .
47
+ * reconcile does not care about the event contents or event type triggering the reconcile.Request .
48
48
- e.g. it doesn't matter whether a ReplicaSet was created or updated, reconcile will check that the correct
49
49
Pods exist either way.
50
50
@@ -70,16 +70,16 @@ from another source (e.g. WebHook callback).
70
70
71
71
EventHandler
72
72
73
- eventhandler.EventHandler transforms and enqueues events from a source.Source into reconcile.ReconcileRequests .
73
+ eventhandler.EventHandler transforms and enqueues events from a source.Source into reconcile.Requests .
74
74
75
75
Example: a Pod Create event from a Source is provided to the eventhandler.EnqueueHandler, which enqueues a
76
- ReconcileRequest containing the name / Namespace of the Pod.
76
+ reconcile.Request containing the name / Namespace of the Pod.
77
77
78
- * EventHandler takes an event.Event and enqueues ReconcileRequests
78
+ * EventHandler takes an event.Event and enqueues reconcile.Requests
79
79
80
- * EventHandlers MAY map an event for an object of one type to a ReconcileRequest for an object of another type.
80
+ * EventHandlers MAY map an event for an object of one type to a reconcile.Request for an object of another type.
81
81
82
- * EventHandlers MAY map an event for an object to multiple ReconcileRequests for different objects.
82
+ * EventHandlers MAY map an event for an object to multiple reconcile.Requests for different objects.
83
83
84
84
* Users SHOULD use the provided EventHandler implementations instead of implementing their own for almost all cases.
85
85
@@ -100,13 +100,13 @@ Source provides event:
100
100
101
101
* &source.KindSource{"core", "v1", "Pod"} -> (Pod foo/bar Create Event)
102
102
103
- EventHandler enqueues ReconcileRequest :
103
+ EventHandler enqueues Request :
104
104
105
- * &eventhandler.Enqueue{} -> (ReconcileRequest {"foo", "bar"})
105
+ * &eventhandler.Enqueue{} -> (reconcile.Request {"foo", "bar"})
106
106
107
- Reconcile is called with the ReconcileRequest :
107
+ Reconcile is called with the Request :
108
108
109
- * Reconcile(ReconcileRequest {"foo", "bar"})
109
+ * Reconcile(Request {"foo", "bar"})
110
110
111
111
112
112
controllerManager
@@ -162,22 +162,22 @@ to Pod or ReplicaSet events. The Reconcile function simply adds a label to the
162
162
client client.Interface
163
163
}
164
164
165
- // Implement reconcile.reconcile so the controller can reconcile objects
165
+ // Implement reconcile.Reconcile so the controller can reconcile objects
166
166
var _ reconcile.Reconcile = &ReconcileReplicaSet{}
167
167
168
168
// Reconcile writes a "hello": "world" annotation to ReplicaSets that don't have one.
169
- func (r *ReconcileReplicaSet) Reconcile(request reconcile.ReconcileRequest ) (reconcile.ReconcileResult , error) {
169
+ func (r *ReconcileReplicaSet) Reconcile(request reconcile.Request ) (reconcile.Result , error) {
170
170
// Fetch the ReplicaSet from the cache
171
171
rs := &appsv1.ReplicaSet{}
172
172
err := r.client.Get(context.TODO(), request.NamespacedName, rs)
173
173
if errors.IsNotFound(err) {
174
174
log.Printf("Could not find ReplicaSet %v.\n", request)
175
- return reconcile.ReconcileResult {}, nil
175
+ return reconcile.Result {}, nil
176
176
}
177
177
178
178
if err != nil {
179
179
log.Printf("Could not fetch ReplicaSet %v for %+v\n", err, request)
180
- return reconcile.ReconcileResult {}, err
180
+ return reconcile.Result {}, err
181
181
}
182
182
183
183
// Print the ReplicaSet
@@ -189,18 +189,18 @@ to Pod or ReplicaSet events. The Reconcile function simply adds a label to the
189
189
rs.Labels = map[string]string{}
190
190
}
191
191
if rs.Labels["hello"] == "world" {
192
- return reconcile.ReconcileResult {}, nil
192
+ return reconcile.Result {}, nil
193
193
}
194
194
195
195
// Update the ReplicaSet
196
196
rs.Labels["hello"] = "world"
197
197
err = r.client.Update(context.TODO(), rs)
198
198
if err != nil {
199
199
log.Printf("Could not write ReplicaSet %v\n", err)
200
- return reconcile.ReconcileResult {}, err
200
+ return reconcile.Result {}, err
201
201
}
202
202
203
- return reconcile.ReconcileResult {}, nil
203
+ return reconcile.Result {}, nil
204
204
}
205
205
206
206
Controller Example
@@ -233,13 +233,13 @@ For example, a Deployment controller might use an EnqueueHandler and EnqueueOwne
233
233
234
234
* Watch for ReplicaSet Events - enqueue the key of the Deployment that created the ReplicaSet (e.g the Owner)
235
235
236
- Note: ReconcileRequests are deduplicated when they are enqueued. Many Pod Events for the same ReplicaSet
236
+ Note: reconcile.Requests are deduplicated when they are enqueued. Many Pod Events for the same ReplicaSet
237
237
may trigger only 1 reconcile invocation as each Event results in the Handler trying to enqueue
238
- the same ReconcileRequest for the ReplicaSet.
238
+ the same reconcile.Request for the ReplicaSet.
239
239
240
- controller Writing Tips
240
+ Controller Writing Tips
241
241
242
- reconcile Runtime Complexity:
242
+ Reconcile Runtime Complexity:
243
243
244
244
* It is better to write Controllers to perform an O(1) reconcile N times (e.g. on N different objects) instead of
245
245
performing an O(N) reconcile 1 time (e.g. on a single object which manages N other objects).
@@ -250,7 +250,7 @@ Services from a single reconcile.
250
250
251
251
Event Multiplexing:
252
252
253
- * ReconcileRequests for the same name / Namespace are deduplicated when they are enqueued. This allows
253
+ * reconcile.Requests for the same name / Namespace are deduplicated when they are enqueued. This allows
254
254
for Controllers to gracefully handle event storms for a single object. Multiplexing multiple event Sources to
255
255
a single object type takes advantage of this.
256
256
0 commit comments