Repository: vllm-project/aibrix
File: cmd/controllers/main.go (Go)

Code before:
			return nil
		}

		select {
		case <-certsReady:
			return mgr.GetWebhookServer().StartedChecker()(req)
		default:
			return errors.New("certificates are not ready")
		}
	}); 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)
	}
}

// TODO: if the argument list will grow, we should create a ControllerSetupOptions struct instead.
func setupControllers(mgr ctrl.Manager, runtimeConfig config.RuntimeConfig, certsReady chan struct{}) {
	// The controllers won't work until the webhooks are operating,
	// and the webhook won't work until the certs are all in places.
	if certsReady == nil {
		setupLog.Info("webhook setup skipped due to --disable-webhook flag")
	} else {
		setupLog.Info("waiting for the cert generation to complete")
		<-certsReady
		setupLog.Info("certs ready")

		if err := apiwebhook.SetupBackendRuntimeWebhook(mgr); err != nil {
			setupLog.Error(err, "unable to create webhook", "webhook", "Model")
			os.Exit(1)
		}
	}

	// Kind controller registration is encapsulated inside the pkg/controller/controller.go
	// So here we can use more clean registration flow and there's no need to change logics in future.
	if err := controller.SetupWithManager(mgr, runtimeConfig); err != nil {
		setupLog.Error(err, "unable to setup controller")
		os.Exit(1)
	}
}


Review comment (suggestion):
Basically, certsReady doesn't mean disableWebhook, which will lead to confusion for further readers, let's not do like this. But we can remove the disableWebhook judgement here because once `disabledWebhook=false`, the certsReady will always be closed.

Code after:
	if err := mgr.AddReadyzCheck("readyz", func(req *http.Request) error {
		if disableWebhook {
			return nil
		}

		select {
		case <-certsReady:
			return mgr.GetWebhookServer().StartedChecker()(req)
		default:
			return errors.New("webhook certificates are not ready")
		}
	}); 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)
	}
}

// TODO: if the argument list will grow, we should create a ControllerSetupOptions struct instead.
func setupControllers(mgr ctrl.Manager, runtimeConfig config.RuntimeConfig, certsReady chan struct{}, disableWebhook bool) {
	// The controllers won't work until the webhooks are operating,
	// and the webhook won't work until the certs are all in places.
	if disableWebhook {
		setupLog.Info("webhook setup skipped due to --disable-webhook flag")
	} else {
		setupLog.Info("waiting for the cert generation to complete")
		<-certsReady
		setupLog.Info("certs ready")
		if err := apiwebhook.SetupModelAdapterWebhook(mgr); err != nil {
			setupLog.Error(err, "unable to setup webhook", "webhook", "ModelAdapter")
			os.Exit(1)
		}
	}

	// Kind controller registration is encapsulated inside the pkg/controller/controller.go
	// So here we can use more clean registration flow and there's no need to change logics in future.
	if err := controller.SetupWithManager(mgr, runtimeConfig); err != nil {
		setupLog.Error(err, "unable to setup controller")
		os.Exit(1)
	}
}