This example starts a new Controller named "pod-controller" to Watch Pods and call a no-op Reconciler.
()
| 55 | |
| 56 | // This example starts a new Controller named "pod-controller" to Watch Pods and call a no-op Reconciler. |
| 57 | func ExampleController() { |
| 58 | // mgr is a manager.Manager |
| 59 | |
| 60 | // Create a new Controller that will call the provided Reconciler function in response |
| 61 | // to events. |
| 62 | c, err := controller.New("pod-controller", mgr, controller.Options{ |
| 63 | Reconciler: reconcile.Func(func(context.Context, reconcile.Request) (reconcile.Result, error) { |
| 64 | // Your business logic to implement the API by creating, updating, deleting objects goes here. |
| 65 | return reconcile.Result{}, nil |
| 66 | }), |
| 67 | }) |
| 68 | if err != nil { |
| 69 | log.Error(err, "unable to create pod-controller") |
| 70 | os.Exit(1) |
| 71 | } |
| 72 | |
| 73 | // Watch for Pod create / update / delete events and call Reconcile |
| 74 | err = c.Watch(source.Kind(mgr.GetCache(), &corev1.Pod{}, &handler.TypedEnqueueRequestForObject[*corev1.Pod]{})) |
| 75 | if err != nil { |
| 76 | log.Error(err, "unable to watch pods") |
| 77 | os.Exit(1) |
| 78 | } |
| 79 | |
| 80 | // Start the Controller through the manager. |
| 81 | if err := mgr.Start(signals.SetupSignalHandler()); err != nil { |
| 82 | log.Error(err, "unable to continue running manager") |
| 83 | os.Exit(1) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // This example starts a new Controller named "pod-controller" to Watch Pods with the unstructured object and call a no-op Reconciler. |
| 88 | func ExampleController_unstructured() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…