MCPcopy
hub / github.com/kubernetes-sigs/controller-runtime / ExampleFuncs

Function ExampleFuncs

pkg/handler/example_test.go:92–127  ·  view source on GitHub ↗

This example implements handler.EnqueueRequestForObject.

()

Source from the content-addressed store, hash-verified

90
91// This example implements handler.EnqueueRequestForObject.
92func ExampleFuncs() {
93 // controller is a controller.controller
94 err := c.Watch(
95 source.Kind(mgr.GetCache(), &corev1.Pod{},
96 handler.TypedFuncs[*corev1.Pod, reconcile.Request]{
97 CreateFunc: func(ctx context.Context, e event.TypedCreateEvent[*corev1.Pod], q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
98 q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
99 Name: e.Object.Name,
100 Namespace: e.Object.Namespace,
101 }})
102 },
103 UpdateFunc: func(ctx context.Context, e event.TypedUpdateEvent[*corev1.Pod], q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
104 q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
105 Name: e.ObjectNew.Name,
106 Namespace: e.ObjectNew.Namespace,
107 }})
108 },
109 DeleteFunc: func(ctx context.Context, e event.TypedDeleteEvent[*corev1.Pod], q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
110 q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
111 Name: e.Object.Name,
112 Namespace: e.Object.Namespace,
113 }})
114 },
115 GenericFunc: func(ctx context.Context, e event.TypedGenericEvent[*corev1.Pod], q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
116 q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
117 Name: e.Object.Name,
118 Namespace: e.Object.Namespace,
119 }})
120 },
121 },
122 ),
123 )
124 if err != nil {
125 // handle it
126 }
127}

Callers

nothing calls this directly

Calls 4

KindFunction · 0.92
WatchMethod · 0.65
GetCacheMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…