kubehandler

package module
v0.0.0-...-0bd438f Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2019 License: Apache-2.0 Imports: 8 Imported by: 2

README

Kubehandler

An event dispatcher for Kubernetes controllers.

Note: This is alpha software. Please use with caution.

Sample Controller

There is a sample controller available in sample-controller/. You can use that as a starting point for building a new controller.

EventHandler

Kubehandler defines a Go interface, EventHandler. Any type that implements this interface can be used to handle events.

type EventHandler interface {
	GetName() string
	GetSynced() cache.InformerSynced
	GetInformer() cache.SharedInformer
	AddFunc(namespace, name string) error
	UpdateFunc(namespace, name string) error
	DeleteFunc(namespace, name string) error
}

Each of the Add/Update/Delete Funcs receive the namespace and the name of the resource that has been modified (or created or deleted). kubehandler.DefaultHandler implements a DefaultHandler that accepts all events and does nothing. In order to make use of this behaviour, you can use the bundled DefaultHandler by inheriting from it:

type DeploymentsHandler struct {
	kubehandler.DefaultHandler
}

You will need an EventLoop to consume events. You can create one like so:

	loop := kubehandler.NewEventLoop("workqueueName")

You can then register the EventHandler with the EventLoop.

	loop.Register(&DeploymentsHandler{
		DefaultHandler: kubehandler.DefaultHandler{
			Synced:   deploymentsInformer.Informer().HasSynced,
			Informer: deploymentsInformer.Informer(),
		},
	})

Finally, run the EventLoop.

	threadiness := 2
	stopCh := make(chan struct{})

	loop.Run(threadiness, stopCh)

You may use the channel passed in to EventLoop.Run to stop the EventLoop.

	close(stopCh)

DefaultHandler

DefaultHandler provides implementations of EventHandler.

GetName() string

Returns defaultHandler.Name

GetSynced() cache.InformerSynced

Returns defaultHandler.Synced

GetInformer() cache.SharedInformer

Returns defaultHandler.Informer

The following functions are no-ops.

AddFunc(namespace, name string) error
UpdateFunc(namespace, name string) error
DeleteFunc(namespace, name string) error

Documentation

Index

Constants

View Source
const (
	WorkqueueAddEvent    string = "add"
	WorkqueueUpdateEvent string = "update"
	WorkqueueDeleteEvent string = "delete"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultHandler

type DefaultHandler struct {
	Synced   cache.InformerSynced
	Informer cache.SharedInformer
	Name     string
}

func (*DefaultHandler) AddFunc

func (handler *DefaultHandler) AddFunc(namespace, name string) error

func (*DefaultHandler) DeleteFunc

func (handler *DefaultHandler) DeleteFunc(namespace, name string) error

func (*DefaultHandler) GetInformer

func (handler *DefaultHandler) GetInformer() cache.SharedInformer

func (*DefaultHandler) GetName

func (handler *DefaultHandler) GetName() string

func (*DefaultHandler) GetSynced

func (handler *DefaultHandler) GetSynced() cache.InformerSynced

func (*DefaultHandler) UpdateFunc

func (handler *DefaultHandler) UpdateFunc(namespace, name string) error

type EventHandler

type EventHandler interface {
	GetName() string
	GetSynced() cache.InformerSynced
	GetInformer() cache.SharedInformer
	AddFunc(namespace, name string) error
	UpdateFunc(namespace, name string) error
	DeleteFunc(namespace, name string) error
}

EventHandler represents Event Handling for a Resource

type EventLoop

type EventLoop interface {
	Run(threadiness int, stopCh <-chan struct{}) error
	Register(handler EventHandler)
}

EventLoop represents a central EventHandler registry which runs in a loop

func NewEventLoop

func NewEventLoop(name string) EventLoop

NewEventLoop instantiates a workqueue backed EventLoop

type WorkQueue

type WorkQueue interface {
	Run(threadiness int, stopCh <-chan struct{}) error
	AddSynced(cache.InformerSynced)
	EnqueueAdd(kind string, obj interface{})
	EnqueueUpdate(kind string, obj interface{})
	EnqueueDelete(kind string, obj interface{})
	RegisterAddHandler(kind string, handler WorkQueueHandler)
	RegisterUpdateHandler(kind string, handler WorkQueueHandler)
	RegisterDeleteHandler(kind string, handler WorkQueueHandler)
	Length() int
}

WorkQueue manages the rate limiting interface

func NewWorkQueue

func NewWorkQueue(name string) WorkQueue

NewWorkQueue creates a WorkQueue with a name

type WorkQueueHandler

type WorkQueueHandler func(namespace, name string) error

WorkQueueHandler defines the contract of a handler function

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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