Created
July 6, 2020 20:10
-
-
Save lxfontes/4c69ea4ab0be60669a5ca7266cdcf06c to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"fmt" | |
corev1 "k8s.io/api/core/v1" | |
"sigs.k8s.io/controller-runtime/pkg/client/config" | |
"sigs.k8s.io/controller-runtime/pkg/controller" | |
"sigs.k8s.io/controller-runtime/pkg/handler" | |
"sigs.k8s.io/controller-runtime/pkg/manager" | |
"sigs.k8s.io/controller-runtime/pkg/manager/signals" | |
"sigs.k8s.io/controller-runtime/pkg/reconcile" | |
"sigs.k8s.io/controller-runtime/pkg/source" | |
) | |
func main() { | |
mgr, err := manager.New(config.GetConfigOrDie(), manager.Options{MetricsBindAddress: "0"}) | |
if err != nil { | |
panic(err) | |
} | |
c, err := controller.New("pod-controller", mgr, controller.Options{ | |
Reconciler: reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) { | |
// Your business logic to implement the API by creating, updating, deleting objects goes here. | |
fmt.Println(o) | |
return reconcile.Result{}, nil | |
}), | |
}) | |
if err != nil { | |
panic(err) | |
} | |
// Watch for Pod create / update / delete events and call Reconcile | |
err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForObject{}) | |
if err != nil { | |
panic(err) | |
} | |
if err := mgr.Start(signals.SetupSignalHandler()); err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment