controller

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package controller contains a reusable abstraction for efficiently watching for changes in resources in a Kubernetes cluster.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestControllerRun

func TestControllerRun(r Resource) func()

TestControllerRun takes the given Resource and runs the Controller. The returned function should be called to stop the controller. The returned function will block until the controller stops.

Types

type Backgrounder

type Backgrounder interface {
	Run(<-chan struct{})
}

Backgrounder should be implemented by a Resource that requires additional background processing. If a Resource implements this, then the Controller will automatically Run the Backgrounder for the duration of the controller.

The channel will be closed when the Controller is quitting. The Controller will block until the Backgrounder completes.

type Controller

type Controller struct {
	Log      hclog.Logger
	Resource Resource
	// contains filtered or unexported fields
}

Controller is a generic cache.Controller implementation that watches Kubernetes for changes to specific set of resources and calls the configured callbacks as data changes.

func (*Controller) HasSynced

func (c *Controller) HasSynced() bool

HasSynced implements cache.Controller

func (*Controller) LastSyncResourceVersion

func (c *Controller) LastSyncResourceVersion() string

LastSyncResourceVersion implements cache.Controller

func (*Controller) Run

func (c *Controller) Run(stopCh <-chan struct{})

Run starts the Controller and blocks until stopCh is closed.

Important: Callers must ensure that Run is only called once at a time.

type Resource

type Resource interface {
	// Informer returns the SharedIndexInformer that the controller will
	// use to watch for changes. An Informer is the long-running task that
	// holds blocking queries to K8S and stores data in a local store.
	Informer() cache.SharedIndexInformer

	// Upsert and Delete are the callbacks called when processing the queue
	// of changes from the Informer. If an error is returned, the given item
	// will be retried.
	Upsert(string, interface{}) error
	Delete(string) error
}

Resource should be implemented by anything that should be watchable by Controller. The Resource needs to be aware of how to create the Informer that is responsible for making API calls as well as what to do on Upsert and Delete.

func NewResource

func NewResource(
	informer cache.SharedIndexInformer,
	upsert ResourceUpsertFunc,
	delete ResourceDeleteFunc,
) Resource

NewResource returns a Resource implementation for the given informer, upsert handler, and delete handler.

type ResourceDeleteFunc

type ResourceDeleteFunc func(string) error

type ResourceUpsertFunc

type ResourceUpsertFunc func(string, interface{}) error

ResourceUpsertFunc and ResourceDeleteFunc are the callback types for when a resource is inserted, updated, or deleted.

Jump to

Keyboard shortcuts

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