Skip to content

Commit da529bb

Browse files
author
Phillip Wittrock
authored
Merge pull request #10 from pwittrock/iterations
Update example names
2 parents 148a88f + 72c8bf5 commit da529bb

4 files changed

+17
-9
lines changed

pkg/controller/controller.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,20 @@ func (gc *GenericController) Watch(obj metav1.Object, p ...predicates.Predicate)
9595
eventhandlers.MapAndEnqueue{Map: eventhandlers.MapToSelf, Predicates: p})
9696
}
9797

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 })
104112
func (gc *GenericController) WatchControllerOf(obj metav1.Object, path eventhandlers.Path,
105113
p ...predicates.Predicate) error {
106114
gc.once.Do(gc.init)

pkg/controller/example_watchandhandleevents_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"k8s.io/client-go/util/workqueue"
3232
)
3333

34-
func ExampleGenericController_WatchAndHandleEvents() {
34+
func ExampleGenericController_WatchEvents() {
3535
// One time setup for program
3636
flag.Parse()
3737
informerFactory := config.GetKubernetesInformersOrDie()

pkg/controller/example_watchandmap_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
corev1 "k8s.io/api/core/v1"
3131
)
3232

33-
func ExampleGenericController_WatchAndMap() {
33+
func ExampleGenericController_WatchTransformationOf() {
3434
// One time setup for program
3535
flag.Parse()
3636
informerFactory := config.GetKubernetesInformersOrDie()

pkg/controller/example_watchandmaptocontroller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
corev1 "k8s.io/api/core/v1"
3030
)
3131

32-
func ExampleGenericController_WatchAndMapToController() {
32+
func ExampleGenericController_WatchControllerOf() {
3333
// One time setup for program
3434
flag.Parse()
3535
informerFactory := config.GetKubernetesInformersOrDie()

0 commit comments

Comments
 (0)