Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Created January 24, 2023 12:11
Show Gist options
  • Select an option

  • Save arriqaaq/a7a17bb7772e642d6eeb56e84fc7dbf1 to your computer and use it in GitHub Desktop.

Select an option

Save arriqaaq/a7a17bb7772e642d6eeb56e84fc7dbf1 to your computer and use it in GitHub Desktop.
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