...

Source file src/edge-infra.dev/pkg/lib/runtime/manager/manager.go

Documentation: edge-infra.dev/pkg/lib/runtime/manager

     1  package manager
     2  
     3  import (
     4  	"context"
     5  	"net"
     6  	"time"
     7  
     8  	"github.com/go-logr/logr"
     9  
    10  	"edge-infra.dev/pkg/lib/runtime/healthz"
    11  )
    12  
    13  type Manager interface {
    14  	// Add will set requested dependencies on the component, and cause the component to be
    15  	// started when Start is called.  Add will inject any dependencies for which the argument
    16  	// implements the inject interface - e.g. inject.Client.
    17  	// Depending on if a Runnable implements LeaderElectionRunnable interface, a Runnable can be run in either
    18  	// non-leaderelection mode (always running) or leader election mode (managed by leader election if enabled).
    19  	Add(Runnable) error
    20  
    21  	// AddLivezCheck allows you to add Livez checker
    22  	AddLivezCheck(name string, check healthz.Checker) error
    23  
    24  	// AddReadyzCheck allows you to add Readyz checker
    25  	AddReadyzCheck(name string, check healthz.Checker) error
    26  
    27  	// Start starts all registered Controllers and blocks until the context is cancelled.
    28  	// Returns an error if there is an error starting any controller.
    29  	//
    30  	// If LeaderElection is used, the binary must be exited immediately after this returns,
    31  	// otherwise components that need leader election might continue to run after the leader
    32  	// lock was lost.
    33  	Start(ctx context.Context) error
    34  
    35  	// GetLogger returns this manager's logger.
    36  	GetLogger() logr.Logger
    37  }
    38  
    39  type Options struct {
    40  	// Logger is the logger that should be used by this manager.
    41  	// If none is set, it defaults to log.Log global logger.
    42  	Logger *logr.Logger
    43  
    44  	// MetricsBindAddress is the TCP address that the controller should bind to
    45  	// for serving prometheus metrics.
    46  	// It can be set to "0" to disable the metrics serving.
    47  	MetricsBindAddress string
    48  
    49  	// HealthProbeBindAddress is the TCP address that the controller should bind to
    50  	// for serving health probes
    51  	HealthProbeBindAddress string
    52  
    53  	// Readiness probe endpoint name, defaults to "/readyz"
    54  	ReadinessEndpointName string
    55  
    56  	// Liveness probe endpoint name, defaults to "/livez"
    57  	LivenessEndpointName string
    58  
    59  	// BaseContext is the function that provides Context values to Runnables
    60  	// managed by the Manager. If a BaseContext function isn't provided, Runnables
    61  	// will receive a new Background Context instead.
    62  	BaseContext BaseContextFunc
    63  
    64  	// GracefulShutdownTimeout is the duration given to runnable to stop before the manager actually returns on stop.
    65  	// To disable graceful shutdown, set to time.Duration(0)
    66  	// To use graceful shutdown without timeout, set to a negative duration, e.G. time.Duration(-1)
    67  	// The graceful shutdown is skipped for safety reasons in case the leader election lease is lost.
    68  	GracefulShutdownTimeout *time.Duration
    69  
    70  	// Dependency injection for testing
    71  	newMetricsListener     func(addr string) (net.Listener, error)
    72  	newHealthProbeListener func(addr string) (net.Listener, error)
    73  }
    74  

View as plain text