k8s

package
v0.6.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeletionHandlingMetaNamespaceKeyFunc

func DeletionHandlingMetaNamespaceKeyFunc(obj interface{}) (string, error)

DeletionHandlingMetaNamespaceKeyFunc checks for cache.DeletedFinalStateUnknown objects before calling cache.MetaNamespaceKeyFunc.

Types

type Config

type Config struct {
	// The queue for your objects; either a cache.FIFO or
	// a cache.DeltaFIFO. Your Process() function should accept
	// the output of this Oueue's Pop() method.
	cache.Queue

	// Something that can list and watch your objects.
	cache.ListerWatcher

	// Something that can process your objects.
	Process ProcessFunc

	// The type of your objects.
	ObjectType runtime.Object

	// Reprocess everything at least this often.
	// Note that if it takes longer for you to clear the queue than this
	// period, you will end up processing items in the order determined
	// by cache.FIFO.Replace(). Currently, this is random. If this is a
	// problem, we can change that replacement policy to append new
	// things to the end of the queue instead of replacing the entire
	// queue.
	FullResyncPeriod time.Duration

	// If true, when Process() returns an error, re-enqueue the object.
	// TODO: add interface to let you inject a delay/backoff or drop
	//       the object completely if desired. Pass the object in
	//       question to this interface as a parameter.
	RetryOnError bool
}

Config contains all the settings for a Controller.

type Controller

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

Controller is a generic controller framework.

func New

func New(c *Config) *Controller

New makes a new Controller from the given Config.

func NewIndexerInformer

func NewIndexerInformer(
	lw cache.ListerWatcher,
	objType runtime.Object,
	resyncPeriod time.Duration,
	h ResourceEventHandler,
	indexers cache.Indexers,
) (cache.Indexer, *Controller)

NewIndexerInformer returns a cache.Indexer and a controller for populating the index while also providing event notifications. You should only used the returned cache.Index for Get/List operations; Add/Modify/Deletes will cause the event notifications to be faulty.

Parameters:

  • lw is list and watch functions for the source of the resource you want to be informed of.
  • objType is an object of the type that you expect to receive.
  • resyncPeriod: if non-zero, will re-list this often (you will get OnUpdate calls, even if nothing changed). Otherwise, re-list will be delayed as long as possible (until the upstream source closes the watch or times out, or you stop the controller).
  • h is the object you want notifications sent to.

func (*Controller) HasSynced

func (c *Controller) HasSynced() bool

HasSynced returns true once this controller has completed an initial resource listing

func (*Controller) Requeue

func (c *Controller) Requeue(obj interface{}) error

Requeue adds the provided object back into the queue if it does not already exist.

func (*Controller) Run

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

Run begins processing items, and will continue until a value is sent down stopCh. It's an error to call Run more than once. Run blocks; call via go.

type ControllerInterface

type ControllerInterface interface {
	Run(stopCh <-chan struct{})
	HasSynced() bool
}

ControllerInterface .

type PodWatcher

type PodWatcher struct {
	Store      StoreToPodLister
	Controller *Controller
}

PodWatcher is a struct which holds the return values of (k8s.io/kubernetes/pkg/controller/framework). NewIndexerInformer together.

func NewPodWatcher

func NewPodWatcher(c kubernetes.Interface, ns string) *PodWatcher

NewPodWatcher creates a new BuildPodWatcher useful to list the pods using a cache which gets updated based on the watch func.

type ProcessFunc

type ProcessFunc func(obj interface{}) error

ProcessFunc processes a single object.

type ResourceEventHandler

type ResourceEventHandler interface {
	OnAdd(obj interface{})
	OnUpdate(oldObj, newObj interface{})
	OnDelete(obj interface{})
}

ResourceEventHandler can handle notifications for events that happen to a resource. The events are informational only, so you can't return an error.

  • OnAdd is called when an object is added.
  • OnUpdate is called when an object is modified. Note that oldObj is the last known state of the object-- it is possible that several changes were combined together, so you can't use this to see every single change. OnUpdate is also called when a re-list happens, and it will get called even if nothing changed. This is useful for periodically evaluating or syncing something.
  • OnDelete will get the final state of the item if it is known, otherwise it will get an object of type cache.DeletedFinalStateUnknown. This can happen if the watch is closed and misses the delete event and we don't notice the deletion until the subsequent re-list.

type ResourceEventHandlerFuncs

type ResourceEventHandlerFuncs struct {
	AddFunc    func(obj interface{})
	UpdateFunc func(oldObj, newObj interface{})
	DeleteFunc func(obj interface{})
}

ResourceEventHandlerFuncs is an adaptor to let you easily specify as many or as few of the notification functions as you want while still implementing ResourceEventHandler.

func (ResourceEventHandlerFuncs) OnAdd

func (r ResourceEventHandlerFuncs) OnAdd(obj interface{})

OnAdd calls AddFunc if it's not nil.

func (ResourceEventHandlerFuncs) OnDelete

func (r ResourceEventHandlerFuncs) OnDelete(obj interface{})

OnDelete calls DeleteFunc if it's not nil.

func (ResourceEventHandlerFuncs) OnUpdate

func (r ResourceEventHandlerFuncs) OnUpdate(oldObj, newObj interface{})

OnUpdate calls UpdateFunc if it's not nil.

type StoreToPodLister

type StoreToPodLister struct {
	cache.Indexer
}

StoreToPodLister makes a Store have the List method of the client.PodInterface The Store must contain (only) Pods.

Example: s := cache.NewStore() lw := cache.ListWatch{Client: c, FieldSelector: sel, Resource: "pods"} r := cache.NewReflector(lw, &api.Pod{}, s).Run() l := StoreToPodLister{s} l.List()

func (*StoreToPodLister) List

func (s *StoreToPodLister) List(selector labels.Selector) (pods []*v1.Pod, err error)

List | Please note that selector is filtering among the pods that have gotten into the store; there may have been some filtering that already happened before that. We explicitly don't return api.PodList, to avoid expensive allocations, which in most cases are unnecessary.

Jump to

Keyboard shortcuts

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