package manager import ( "context" "net" "time" "github.com/go-logr/logr" "edge-infra.dev/pkg/lib/runtime/healthz" ) type Manager interface { // Add will set requested dependencies on the component, and cause the component to be // started when Start is called. Add will inject any dependencies for which the argument // implements the inject interface - e.g. inject.Client. // Depending on if a Runnable implements LeaderElectionRunnable interface, a Runnable can be run in either // non-leaderelection mode (always running) or leader election mode (managed by leader election if enabled). Add(Runnable) error // AddLivezCheck allows you to add Livez checker AddLivezCheck(name string, check healthz.Checker) error // AddReadyzCheck allows you to add Readyz checker AddReadyzCheck(name string, check healthz.Checker) error // Start starts all registered Controllers and blocks until the context is cancelled. // Returns an error if there is an error starting any controller. // // If LeaderElection is used, the binary must be exited immediately after this returns, // otherwise components that need leader election might continue to run after the leader // lock was lost. Start(ctx context.Context) error // GetLogger returns this manager's logger. GetLogger() logr.Logger } type Options struct { // Logger is the logger that should be used by this manager. // If none is set, it defaults to log.Log global logger. Logger *logr.Logger // MetricsBindAddress is the TCP address that the controller should bind to // for serving prometheus metrics. // It can be set to "0" to disable the metrics serving. MetricsBindAddress string // HealthProbeBindAddress is the TCP address that the controller should bind to // for serving health probes HealthProbeBindAddress string // Readiness probe endpoint name, defaults to "/readyz" ReadinessEndpointName string // Liveness probe endpoint name, defaults to "/livez" LivenessEndpointName string // BaseContext is the function that provides Context values to Runnables // managed by the Manager. If a BaseContext function isn't provided, Runnables // will receive a new Background Context instead. BaseContext BaseContextFunc // GracefulShutdownTimeout is the duration given to runnable to stop before the manager actually returns on stop. // To disable graceful shutdown, set to time.Duration(0) // To use graceful shutdown without timeout, set to a negative duration, e.G. time.Duration(-1) // The graceful shutdown is skipped for safety reasons in case the leader election lease is lost. GracefulShutdownTimeout *time.Duration // Dependency injection for testing newMetricsListener func(addr string) (net.Listener, error) newHealthProbeListener func(addr string) (net.Listener, error) }