@@ -95,12 +95,20 @@ func (gc *GenericController) Watch(obj metav1.Object, p ...predicates.Predicate)
95
95
eventhandlers.MapAndEnqueue {Map : eventhandlers .MapToSelf , Predicates : p })
96
96
}
97
97
98
- // WatchControllerOf watches for events for objects matching obj's type and enqueues events for the
99
- // controller of the object if the controller UID matches the ownerref UID.
100
- // Will walk the owners references looking up the controller using the path function and comparing the UID of
101
- // the object to the ownersref UID.
102
- // e.g. if obj was a Pod and the path contained lookup functions for ReplicaSet, Deployment, Foo it would walk
103
- // Pod -> (controller) ReplicaSet -> (controller) Deployment -> (controller) Foo and reconcile Foo only.
98
+ // WatchControllerOf reconciles the controller of the object type being watched. e.g. If the
99
+ // controller created a Pod, watch the Pod for events and invoke the controller reconcile function.
100
+ // Uses path to lookup the ancestors. Will lookup each ancestor in the path until it gets to the
101
+ // root and then reconcile this key.
102
+ //
103
+ // Example: Deployment controller creates a ReplicaSet. ReplicaSet controller creates a Pod. Deployment
104
+ // controller wants to have its reconcile method called for Pod events for any Pods it created (transitively).
105
+ // - Pod event occurs - find owners references
106
+ // - Lookup the Pod parent ReplicaSet by using the first path element (compare UID to ref)
107
+ // - Lookup the ReplicaSet parent Deployment by using the second path element (compare UID to ref)
108
+ // - Enqueue reconcile for Deployment namespace/name
109
+ //
110
+ // This could be implemented as:
111
+ // WatchControllerOf(&corev1.Pod, eventhandlers.Path{FnToLookupReplicaSetByNamespaceName, FnToLookupDeploymentByNamespaceName })
104
112
func (gc * GenericController ) WatchControllerOf (obj metav1.Object , path eventhandlers.Path ,
105
113
p ... predicates.Predicate ) error {
106
114
gc .once .Do (gc .init )
0 commit comments