diff --git a/cmd/main.go b/cmd/main.go index 7128e310..369d2dbc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -101,29 +101,9 @@ func main() { tlsOpts = append(tlsOpts, disableHTTP2) } - webhookServer := webhook.NewServer(webhook.Options{ - TLSOpts: tlsOpts, - }) - - // Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server. - // More info: - // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.0/pkg/metrics/server - // - https://book.kubebuilder.io/reference/metrics.html - metricsServerOptions := metricsserver.Options{ - BindAddress: metricsAddr, - SecureServing: secureMetrics, - TLSOpts: tlsOpts, - } - - if secureMetrics { - // FilterProvider is used to protect the metrics endpoint with authn/authz. - // These configurations ensure that only authorized users and service accounts - // can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info: - // https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.0/pkg/metrics/filters#WithAuthenticationAndAuthorization - metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization - } - - // Initialize HealthManager and register components + // Create HealthManager and start health server early so probes are + // answered immediately, before the (potentially slow) manager and + // controller initialisation. healthManager := health.NewHealthManager() healthManager.Register(health.ComponentCollectorManager) healthManager.Register(health.ComponentBufferQueue) @@ -135,10 +115,6 @@ func main() { // reconciling before enforcing readiness checks. healthManager.SuppressReadiness(2 * time.Minute) - // No need to add the standard controller with kubebuilder:scaffold:builder - // The env-based controller doesn't rely on CRDs - - // New health server from health package healthServer := health.NewHealthServer(healthManager, probeAddr) if err := healthServer.Start(); err != nil { setupLog.Error(err, "unable to start health server") @@ -152,6 +128,30 @@ func main() { } }() + setupLog.Info("health server started, initializing manager") + + webhookServer := webhook.NewServer(webhook.Options{ + TLSOpts: tlsOpts, + }) + + // Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server. + // More info: + // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.0/pkg/metrics/server + // - https://book.kubebuilder.io/reference/metrics.html + metricsServerOptions := metricsserver.Options{ + BindAddress: metricsAddr, + SecureServing: secureMetrics, + TLSOpts: tlsOpts, + } + + if secureMetrics { + // FilterProvider is used to protect the metrics endpoint with authn/authz. + // These configurations ensure that only authorized users and service accounts + // can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info: + // https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.0/pkg/metrics/filters#WithAuthenticationAndAuthorization + metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization + } + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, Metrics: metricsServerOptions, @@ -190,6 +190,9 @@ func main() { os.Exit(1) } + // No need to add the standard controller with kubebuilder:scaffold:builder + // The env-based controller doesn't rely on CRDs + setupLog.Info("starting manager") if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { setupLog.Error(err, "problem running manager")