Created
January 24, 2023 12:11
-
-
Save arriqaaq/a7a17bb7772e642d6eeb56e84fc7dbf1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "github.com/go-logr/logr" | |
| "sigs.k8s.io/controller-runtime/pkg/client" | |
| "sigs.k8s.io/controller-runtime/pkg/controller" | |
| "sigs.k8s.io/controller-runtime/pkg/handler" | |
| "sigs.k8s.io/controller-runtime/pkg/source" | |
| ) | |
| type MyController struct { | |
| client.Client | |
| log logr.Logger | |
| } | |
| func (c *MyController) Reconcile(req controller.Request) (controller.Result, error) { | |
| // your logic here | |
| } | |
| func main() { | |
| builder := controller.NewControllerManagedBy(mgr). | |
| For(&MyType{}). | |
| Watches(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ | |
| IsController: true, | |
| OwnerType: &MyType{}, | |
| }) | |
| if err := builder.Complete(mgr); err != nil { | |
| log.Error(err, "unable to create controller") | |
| os.Exit(1) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment