in cmd/kube-egress-gateway-controller/cmd/root.go [110:205]
func startControllers(cmd *cobra.Command, args []string) {
var err error
var setupLog = ctrl.Log.WithName("setup")
options := ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{
BindAddress: ":" + strconv.Itoa(metricsPort),
},
HealthProbeBindAddress: ":" + strconv.Itoa(probePort),
LeaderElection: enableLeaderElection,
LeaderElectionNamespace: leaderElectionNamespace,
LeaderElectionID: "0a299682.microsoft.com",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
// speeds up voluntary leader transitions as the new leader don't have to wait
// LeaseDuration time first.
//
// In the default scaffold provided, the program ends immediately after
// the manager stops, so would be fine to enable this option. However,
// if you are doing or is intended to do any operation such as perform cleanups
// after the manager stops then its usage might be unsafe.
LeaderElectionReleaseOnCancel: true,
BaseContext: func() context.Context {
return ctrl.LoggerInto(context.Background(), ctrl.Log)
},
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}
cloudConfig, err = configloader.Load[config.CloudConfig](context.Background(), nil, &configloader.FileLoaderConfig{FilePath: cloudConfigFile})
if err != nil {
setupLog.Error(err, "unable to parse config file")
os.Exit(1)
}
if err := cloudConfig.DefaultAndValidate(); err != nil {
setupLog.Error(err, "cloud configuration is invalid")
os.Exit(1)
}
factory, err := getClientFactoryFromConfig(cloudConfig)
if err != nil {
setupLog.Error(err, "unable to create client factory")
os.Exit(1)
}
az, err := azmanager.CreateAzureManager(cloudConfig, factory)
if err != nil {
setupLog.Error(err, "unable to create azure manager")
os.Exit(1)
}
if err = (&controllers.StaticGatewayConfigurationReconciler{
Client: mgr.GetClient(),
SecretNamespace: secretNamespace,
Recorder: mgr.GetEventRecorderFor("staticGatewayConfiguration-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "StaticGatewayConfiguration")
os.Exit(1)
}
if err = (&controllers.GatewayLBConfigurationReconciler{
Client: mgr.GetClient(),
AzureManager: az,
Recorder: mgr.GetEventRecorderFor("gatewayLBConfiguration-controller"),
LBProbePort: gatewayLBProbePort,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "GatewayLBConfiguration")
os.Exit(1)
}
if err = (&controllers.GatewayVMConfigurationReconciler{
Client: mgr.GetClient(),
AzureManager: az,
Recorder: mgr.GetEventRecorderFor("gatewayVMConfiguration-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "GatewayVMConfiguration")
os.Exit(1)
}
//+kubebuilder:scaffold:builder
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}
setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}