in main.go [59:121]
func main() {
var metricsAddr string
var enableLeaderElection bool
var maxConcurrentReconciles int
var healthcheckInterval int
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 etcdadmCluster objects. If unspecified, the controller watches for objects across all namespaces.")
flag.IntVar(&maxConcurrentReconciles, "max-concurrent-reconciles", 10, "The maximum number of concurrent etcdadm-controller reconciles.")
flag.IntVar(&healthcheckInterval, "healthcheck-interval", 30, "The time interval between each healthcheck loop in seconds.")
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
opts := ctrl.Options{
Scheme: scheme,
Metrics: server.Options{
BindAddress: metricsAddr,
},
LeaderElection: enableLeaderElection,
LeaderElectionID: "cc88008e.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, stopCh := setupSignalHandler()
etcdadmReconciler := &controllers.EtcdadmClusterReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("EtcdadmCluster"),
Scheme: mgr.GetScheme(),
MaxConcurrentReconciles: maxConcurrentReconciles,
HealthCheckInterval: time.Second * time.Duration(healthcheckInterval),
}
if err = (etcdadmReconciler).SetupWithManager(ctx, mgr, stopCh); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "EtcdadmCluster")
os.Exit(1)
}
if err = (&etcdclusterv1beta1.EtcdadmCluster{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "EtcdadmCluster")
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)
}
}