in main.go [53:109]
func main() {
var metricsAddr string
var enableLeaderElection bool
flag.StringVar(&metricsAddr, "metrics-addr", "localhost:8080", "The address the metric endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&watchNamespace, "namespace", "",
"Namespace that the controller watches to reconcile etcdadmConfig objects. If unspecified, the controller watches forobjects across all namespaces.")
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
opts := ctrl.Options{
Scheme: scheme,
Metrics: server.Options{
BindAddress: metricsAddr,
},
LeaderElection: enableLeaderElection,
LeaderElectionID: "e949c6e2.cluster.x-k8s.io",
}
if watchNamespace != "" {
opts.Cache = cache.Options{
DefaultNamespaces: map[string]cache.Config{watchNamespace: {}},
}
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), opts)
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}
// Setup the context that's going to be used in controllers and for the manager.
ctx := ctrl.SetupSignalHandler()
if err = (&controllers.EtcdadmConfigReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("EtcdadmConfig"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(ctx, mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "EtcdadmConfig")
os.Exit(1)
}
if err = (&bootstrapv1beta1.EtcdadmConfig{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "EtcdadmConfig")
os.Exit(1)
}
// +kubebuilder:scaffold:builder
setupLog.Info("starting manager")
if err := mgr.Start(ctx); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}