controllermanager

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecoverStores

func RecoverStores(ctx context.Context, stores []Store) error

RecoverStores recovers all stores in the background and blocks until all of them have finished recovering.

func RunControllers

func RunControllers(ctx context.Context, controllers []Controller) error

RunControllers starts all the given Controllers in the background and blocks until all of them are started. If any controller's Run method returns an error, this method returns and cancels all other runs. if the context is canceled, it will cancel starting up.

func ShutdownRunnables

func ShutdownRunnables(ctx context.Context, controllers []Runnable)

ShutdownRunnables stops all runnables and blocks until they return.

func StartWebhooksAndWait

func StartWebhooksAndWait(ctx context.Context, webhooks []Webhook) error

StartWebhooksAndWait starts all the given Webhooks in the background and blocks until they are all ready. If any controller's Start method returns an error, this method returns and cancels the context. To terminate controllers, cancel the passed context.

Types

type BaseManager

type BaseManager struct {
	// contains filtered or unexported fields
}

BaseManager is the base manager that manages runnables, readiness and liveness status.

func NewBaseManager

func NewBaseManager(ctrlContext controllercontext.Context) *BaseManager

func (*BaseManager) Add

func (m *BaseManager) Add(runnables ...Runnable)

Add a new runnable to the manager to be managed. Will not take effect once Start is called.

func (*BaseManager) GetHealth

func (m *BaseManager) GetHealth() []HealthStatus

GetHealth returns a list of all health statuses. This has to be overridden, and returns an empty slice by default.

func (*BaseManager) GetReadiness

func (m *BaseManager) GetReadiness() error

GetReadiness returns an error if the base manager is not yet fully initialized.

func (*BaseManager) IsStarted added in v0.1.0

func (m *BaseManager) IsStarted() bool

func (*BaseManager) IsStarting added in v0.1.0

func (m *BaseManager) IsStarting() bool

func (*BaseManager) ShutdownAndWait

func (m *BaseManager) ShutdownAndWait(ctx context.Context)

func (*BaseManager) Start

func (m *BaseManager) Start(ctx context.Context) error

Start will perform shared start routines.

type Controller

type Controller interface {
	Runnable

	// Run should block until it terminates; if there is an error, it should return
	// one. If the context is canceled, it should return the context's error in a
	// timely fashion.
	Run(ctx context.Context) error

	// GetHealth returns the health status of the Controller.
	GetHealth() HealthStatus
}

Controller encapsulates a routine that can be run and shut down.

type ControllerManager

type ControllerManager struct {
	*BaseManager
	// contains filtered or unexported fields
}

ControllerManager performs a high-level management of multiple controllers and also optionally performs leader election.

func NewControllerManager added in v0.1.0

func NewControllerManager(
	ctrlContext controllercontext.Context,
	ctrlCfg configv1alpha1.ControllerManagerConfigSpec,
	defaultLeaseName string,
) (*ControllerManager, error)

func (*ControllerManager) Add

func (m *ControllerManager) Add(runnables ...Runnable)

Add a new runnable to the controller manager to be managed. Will not take effect once Start is called.

func (*ControllerManager) AddStore

func (m *ControllerManager) AddStore(stores ...Store)

AddStore adds a new Store to be recovered. Will not take effect once Start is called.

func (*ControllerManager) GetHealth

func (m *ControllerManager) GetHealth() []HealthStatus

GetHealth returns a list of all controllers' health statuses.

func (*ControllerManager) ShutdownAndWait

func (m *ControllerManager) ShutdownAndWait(ctx context.Context)

func (*ControllerManager) Start

func (m *ControllerManager) Start(ctx context.Context, startTimeout time.Duration) error

Start will start up all controllers and blocks until all of them are started and ready. This method will first block until elected, and once elected it will block until the controllers are fully started.

If there is an error in starting, this method returns an error. When the context is canceled, all controllers should stop their start process as well.

type HealthStatus

type HealthStatus struct {
	Name    string `json:"name"`
	Healthy bool   `json:"healthy"`
	Message string `json:"message,omitempty"`
}

type Runnable

type Runnable interface {
	// Shutdown should block until it terminates. This is to provide graceful
	// shutdown.
	Shutdown(ctx context.Context)
}

type Store

type Store interface {
	Name() string
	Recover(ctx context.Context) error
}

type Webhook

type Webhook interface {
	Runnable

	// Name of the webhook.
	Name() string

	// Start blocks until the webhook is ready. Once the method returns, it is
	// assumed to be Ready. If the context is canceled, Start should return timely
	// with the context error.
	Start(ctx context.Context) error

	// Ready specifies if the webhook is ready to receive requests.
	Ready() bool

	// Path of the webhook.
	Path() string

	// Handle the incoming request and returns a response.
	Handle(ctx context.Context, req *admissionv1.AdmissionRequest) (*admissionv1.AdmissionResponse, error)
}

type WebhookManager

type WebhookManager struct {
	*BaseManager
	// contains filtered or unexported fields
}

WebhookManager takes care of the lifecycles of webhooks, and the liveness and readiness status of the server.

func NewWebhookManager

func NewWebhookManager(ctrlContext controllercontext.Context) *WebhookManager

func (*WebhookManager) Add

func (m *WebhookManager) Add(runnables ...Runnable)

Add a new runnable to the webhook manager to be managed. Will not take effect once Start is called.

func (*WebhookManager) Start

func (m *WebhookManager) Start(ctx context.Context) error

Start will start up all webhooks and returns.

If there is an error in starting, this method returns an error. When the context is canceled, all webhooks should stop as well.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL