controller

package
v2.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: Apache-2.0 Imports: 13 Imported by: 17

Documentation

Overview

Package controller contains implementation and defition to create kubernetes controllers.

Index

Constants

This section is empty.

Variables

View Source
var DummyMetricsRecorder = dummy(0)

DummyMetricsRecorder is a dummy metrics recorder.

View Source
var (
	// ErrControllerNotValid will be used when the controller has invalid configuration.
	ErrControllerNotValid = errors.New("controller not valid")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Handler is the controller handler.
	Handler Handler
	// Retriever is the controller retriever.
	Retriever Retriever
	// Leader elector will be used to use only one instance, if no set it will be
	// leader election will be ignored
	LeaderElector leaderelection.Runner
	// MetricsRecorder will record the controller metrics.
	MetricsRecorder MetricsRecorder
	// Logger will log messages of the controller.
	Logger log.Logger

	// name of the controller.
	Name string
	// ConcurrentWorkers is the number of concurrent workers the controller will have running processing events.
	ConcurrentWorkers int
	// ResyncInterval is the interval the controller will process all the selected resources.
	ResyncInterval time.Duration
	// ProcessingJobRetries is the number of times the job will try to reprocess the event before returning a real error.
	ProcessingJobRetries int
	// DisableResync will disable resyncing, if disabled the controller only will react on event updates and resync
	// all when it runs for the first time.
	// This is useful for secondary resource controllers (e.g pod controller of a primary controller based on deployments).
	DisableResync bool
}

Config is the controller configuration.

type Controller

type Controller interface {
	// Run runs the controller and blocks until the context is `Done`.
	Run(ctx context.Context) error
}

Controller is the object that will implement the different kinds of controllers that will be running on the application.

func New

func New(cfg *Config) (Controller, error)

New creates a new controller that can be configured using the cfg parameter.

type Handler

type Handler interface {
	Handle(context.Context, runtime.Object) error
}

Handler knows how to handle the received resources from a kubernetes cluster.

type HandlerFunc

type HandlerFunc func(context.Context, runtime.Object) error

HandlerFunc knows how to handle resource adds.

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(ctx context.Context, obj runtime.Object) error

Handle satisfies controller.Handler interface.

type MetricsRecorder

type MetricsRecorder interface {
	// IncResourceEvent increments in one the metric records of a queued event.
	IncResourceEventQueued(ctx context.Context, controller string, isRequeue bool)
	// ObserveResourceInQueueDuration measures how long takes to dequeue a queued object. If the object is already in queue
	// it will be measured once, since the first time it was added to the queue.
	ObserveResourceInQueueDuration(ctx context.Context, controller string, queuedAt time.Time)
	// ObserveResourceProcessingDuration measures how long it takes to process a resources (handling).
	ObserveResourceProcessingDuration(ctx context.Context, controller string, success bool, startProcessingAt time.Time)
	// RegisterResourceQueueLengthFunc will register a function that will be called
	// by the metrics recorder to get the length of a queue at a given point in time.
	RegisterResourceQueueLengthFunc(controller string, f func(context.Context) int) error
}

MetricsRecorder knows how to record metrics of a controller.

type Retriever

type Retriever interface {
	List(ctx context.Context, options metav1.ListOptions) (runtime.Object, error)
	Watch(ctx context.Context, options metav1.ListOptions) (watch.Interface, error)
}

Retriever is how a controller will retrieve the events on the resources from the APÎ server.

A Retriever is bound to a single type.

func MustRetrieverFromListerWatcher

func MustRetrieverFromListerWatcher(lw cache.ListerWatcher) Retriever

MustRetrieverFromListerWatcher returns a Retriever from a Kubernetes client-go cache.ListerWatcher if there is an error it will panic.

func RetrieverFromListerWatcher

func RetrieverFromListerWatcher(lw cache.ListerWatcher) (Retriever, error)

RetrieverFromListerWatcher returns a Retriever from a Kubernetes client-go cache.ListerWatcher. If the received lister watcher is nil it will error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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