controller

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2018 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BurstReplicas is the maximum amount of requests in a row for CRUD operations on resources by controllers,
	// to avoid unintentional DoS
	BurstReplicas uint = 250
)
View Source
const (
	// If a watch drops a delete event for a pod, it'll take this long
	// before a dormant controller waiting for those packets is woken up anyway. It is
	// specifically targeted at the case where some problem prevents an update
	// of expectations, without it the controller could stay asleep forever. This should
	// be set based on the expected latency of watch events.
	//
	// Currently a controller can service (create *and* observe the watch events for said
	// creation) about 10 pods a second, so it takes about 1 min to service
	// 500 pods. Just creation is limited to 20qps, and watching happens with ~10-30s
	// latency/pod at the scale of 3000 pods over 100 nodes.
	ExpectationsTimeout = 5 * time.Minute
)

Variables

View Source
var ExpKeyFunc = func(obj interface{}) (string, error) {
	if e, ok := obj.(*ControlleeExpectations); ok {
		return e.key, nil
	}
	return "", fmt.Errorf("Could not find key for obj %#v", obj)
}

ExpKeyFunc to parse out the key from a ControlleeExpectation

View Source
var UIDSetKeyFunc = func(obj interface{}) (string, error) {
	if u, ok := obj.(*UIDSet); ok {
		return u.key, nil
	}
	return "", fmt.Errorf("Could not find key for obj %#v", obj)
}

UIDSetKeyFunc to parse out the key from a UIDSet.

View Source
var UpdateTaintBackoff = wait.Backoff{
	Steps:    5,
	Duration: 100 * time.Millisecond,
	Jitter:   1.0,
}

Functions

func GetControllerOf

func GetControllerOf(controllee metav1.Object) *metav1.OwnerReference

GetControllerOf returns the controllerRef if controllee has a controller, otherwise returns nil.

func HandlePanic

func HandlePanic()

func HasFinalizer

func HasFinalizer(object metav1.Object, finalizer string) bool

func NewListWatchFromClient

func NewListWatchFromClient(c cache.Getter, resource string, namespace string, fieldSelector fields.Selector, labelSelector labels.Selector) *cache.ListWatch

NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.

func NewResourceEventHandlerFuncsForFunc

func NewResourceEventHandlerFuncsForFunc(f func(interface{})) cache.ResourceEventHandlerFuncs

func NoResyncPeriodFunc

func NoResyncPeriodFunc() time.Duration

Returns 0 for resyncPeriod in case resyncing is not needed.

func PodKey added in v0.5.0

func PodKey(pod *k8sv1.Pod) string

func PodKeys added in v0.5.0

func PodKeys(pods []*k8sv1.Pod) []string

func RecheckDeletionTimestamp

func RecheckDeletionTimestamp(getObject func() (metav1.Object, error)) func() error

RecheckDeletionTimestamp returns a CanAdopt() function to recheck deletion.

The CanAdopt() function calls getObject() to fetch the latest value, and denies adoption attempts if that object has a non-nil DeletionTimestamp.

func RemoveFinalizer added in v0.5.0

func RemoveFinalizer(object metav1.Object, finalizer string)

func VirtualMachineKey

func VirtualMachineKey(vmi *v1.VirtualMachineInstance) string

func VirtualMachineKeys

func VirtualMachineKeys(vmis []*v1.VirtualMachineInstance) []string

Types

type BaseControllerRefManager

type BaseControllerRefManager struct {
	Controller metav1.Object
	Selector   labels.Selector

	CanAdoptFunc func() error
	// contains filtered or unexported fields
}

func (*BaseControllerRefManager) CanAdopt

func (m *BaseControllerRefManager) CanAdopt() error

func (*BaseControllerRefManager) ClaimObject

func (m *BaseControllerRefManager) ClaimObject(obj metav1.Object, match func(metav1.Object) bool, adopt, release func(metav1.Object) error) (bool, error)

ClaimObject tries to take ownership of an object for this controller.

It will reconcile the following:

  • Adopt orphans if the match function returns true.
  • Release owned objects if the match function returns false.

A non-nil error is returned if some form of reconciliation was attempted and failed. Usually, controllers should try again later in case reconciliation is still needed.

If the error is nil, either the reconciliation succeeded, or no reconciliation was necessary. The returned boolean indicates whether you now own the object.

No reconciliation will be attempted if the controller is being deleted.

type ControlleeExpectations

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

ControlleeExpectations track controllee creates/deletes.

func (*ControlleeExpectations) Add

func (e *ControlleeExpectations) Add(add, del int64)

Add increments the add and del counters.

func (*ControlleeExpectations) Fulfilled

func (e *ControlleeExpectations) Fulfilled() bool

Fulfilled returns true if this expectation has been fulfilled.

func (*ControlleeExpectations) GetExpectations

func (e *ControlleeExpectations) GetExpectations() (int64, int64)

GetExpectations returns the add and del expectations of the controllee.

type ControllerExpectations

type ControllerExpectations struct {
	cache.Store
}

ControllerExpectations is a cache mapping controllers to what they expect to see before being woken up for a sync.

func NewControllerExpectations

func NewControllerExpectations() *ControllerExpectations

NewControllerExpectations returns a store for ControllerExpectations.

func (*ControllerExpectations) CreationObserved

func (r *ControllerExpectations) CreationObserved(controllerKey string)

CreationObserved atomically decrements the `add` expectation count of the given controller.

func (*ControllerExpectations) DeleteExpectations

func (r *ControllerExpectations) DeleteExpectations(controllerKey string)

DeleteExpectations deletes the expectations of the given controller from the TTLStore.

func (*ControllerExpectations) DeletionObserved

func (r *ControllerExpectations) DeletionObserved(controllerKey string)

DeletionObserved atomically decrements the `del` expectation count of the given controller.

func (*ControllerExpectations) ExpectCreations

func (r *ControllerExpectations) ExpectCreations(controllerKey string, adds int) error

func (*ControllerExpectations) ExpectDeletions

func (r *ControllerExpectations) ExpectDeletions(controllerKey string, dels int) error

func (*ControllerExpectations) GetExpectations

func (r *ControllerExpectations) GetExpectations(controllerKey string) (*ControlleeExpectations, bool, error)

GetExpectations returns the ControlleeExpectations of the given controller.

func (*ControllerExpectations) LowerExpectations

func (r *ControllerExpectations) LowerExpectations(controllerKey string, add, del int)

Decrements the expectation counts of the given controller.

func (*ControllerExpectations) RaiseExpectations

func (r *ControllerExpectations) RaiseExpectations(controllerKey string, add, del int)

Increments the expectation counts of the given controller.

func (*ControllerExpectations) SatisfiedExpectations

func (r *ControllerExpectations) SatisfiedExpectations(controllerKey string) bool

SatisfiedExpectations returns true if the required adds/dels for the given controller have been observed. Add/del counts are established by the controller at sync time, and updated as controllees are observed by the controller manager.

func (*ControllerExpectations) SetExpectations

func (r *ControllerExpectations) SetExpectations(controllerKey string, add, del int) error

SetExpectations registers new expectations for the given controller. Forgets existing expectations.

type ControllerExpectationsInterface

type ControllerExpectationsInterface interface {
	GetExpectations(controllerKey string) (*ControlleeExpectations, bool, error)
	SatisfiedExpectations(controllerKey string) bool
	DeleteExpectations(controllerKey string)
	SetExpectations(controllerKey string, add, del int) error
	ExpectCreations(controllerKey string, adds int) error
	ExpectDeletions(controllerKey string, dels int) error
	CreationObserved(controllerKey string)
	DeletionObserved(controllerKey string)
	RaiseExpectations(controllerKey string, add, del int)
	LowerExpectations(controllerKey string, add, del int)
}

ControllerExpectationsInterface is an interface that allows users to set and wait on expectations. Only abstracted out for testing. Warning: if using KeyFunc it is not safe to use a single ControllerExpectationsInterface with different types of controllers, because the keys might conflict across types.

type Expectations

type Expectations interface {
	Fulfilled() bool
}

Expectations are either fulfilled, or expire naturally.

type KubeInformerFactory

type KubeInformerFactory interface {
	// Starts any informers that have not been started yet
	// This function is thread safe and idempotent
	Start(stopCh <-chan struct{})

	// Watches for vmi objects
	VMI() cache.SharedIndexInformer

	// Watches for VirtualMachineInstanceReplicaSet objects
	VMIReplicaSet() cache.SharedIndexInformer

	// Watches for VirtualMachineInstancePreset objects
	VirtualMachinePreset() cache.SharedIndexInformer

	// Watches for pods related only to kubevirt
	KubeVirtPod() cache.SharedIndexInformer

	// Watches for nodes
	KubeVirtNode() cache.SharedIndexInformer

	// VirtualMachine handles the VMIs that are stopped or not running
	VirtualMachine() cache.SharedIndexInformer

	// Watches for ConfigMap objects
	ConfigMap() cache.SharedIndexInformer
}

func NewKubeInformerFactory

func NewKubeInformerFactory(restClient *rest.RESTClient, clientSet kubecli.KubevirtClient) KubeInformerFactory

type RealVirtualMachineControl

type RealVirtualMachineControl struct {
	Clientset kubecli.KubevirtClient
}

func (RealVirtualMachineControl) PatchVirtualMachine

func (r RealVirtualMachineControl) PatchVirtualMachine(namespace, name string, data []byte) error

type ResyncPeriodFunc

type ResyncPeriodFunc func() time.Duration

func StaticResyncPeriodFunc

func StaticResyncPeriodFunc(resyncPeriod time.Duration) ResyncPeriodFunc

StaticResyncPeriodFunc returns the resync period specified

type UIDSet

type UIDSet struct {
	sets.String
	// contains filtered or unexported fields
}

UIDSet holds a key and a set of UIDs. Used by the UIDTrackingControllerExpectations to remember which UID it has seen/still waiting for.

type UIDTrackingControllerExpectations

type UIDTrackingControllerExpectations struct {
	ControllerExpectationsInterface
	// contains filtered or unexported fields
}

UIDTrackingControllerExpectations tracks the UID of the pods it deletes. This cache is needed over plain old expectations to safely handle graceful deletion. The desired behavior is to treat an update that sets the DeletionTimestamp on an object as a delete. To do so consistently, one needs to remember the expected deletes so they aren't double counted. TODO: RTCTimerTrack creates as well (#22599)

func NewUIDTrackingControllerExpectations

func NewUIDTrackingControllerExpectations(ce ControllerExpectationsInterface) *UIDTrackingControllerExpectations

NewUIDTrackingControllerExpectations returns a wrapper around ControllerExpectations that is aware of deleteKeys.

func (*UIDTrackingControllerExpectations) DeleteExpectations

func (u *UIDTrackingControllerExpectations) DeleteExpectations(rcKey string)

DeleteExpectations deletes the UID set and invokes DeleteExpectations on the underlying ControllerExpectationsInterface.

func (*UIDTrackingControllerExpectations) DeletionObserved

func (u *UIDTrackingControllerExpectations) DeletionObserved(rcKey, deleteKey string)

DeletionObserved records the given deleteKey as a deletion, for the given rc.

func (*UIDTrackingControllerExpectations) ExpectDeletions

func (u *UIDTrackingControllerExpectations) ExpectDeletions(rcKey string, deletedKeys []string) error

ExpectDeletions records expectations for the given deleteKeys, against the given controller.

func (*UIDTrackingControllerExpectations) GetUIDs

func (u *UIDTrackingControllerExpectations) GetUIDs(controllerKey string) sets.String

GetUIDs is a convenience method to avoid exposing the set of expected uids. The returned set is not thread safe, all modifications must be made holding the uidStoreLock.

type VirtualMachineConditionManager added in v0.5.0

type VirtualMachineConditionManager struct {
}

func NewVirtualMachineInstanceConditionManager added in v0.6.1

func NewVirtualMachineInstanceConditionManager() *VirtualMachineConditionManager

func (*VirtualMachineConditionManager) AddPodCondition added in v0.6.1

AddPodCondition add pod condition to the VM.

func (*VirtualMachineConditionManager) CheckFailure added in v0.5.0

func (d *VirtualMachineConditionManager) CheckFailure(vmi *v1.VirtualMachineInstance, syncErr error, reason string) (changed bool)

func (*VirtualMachineConditionManager) HasCondition added in v0.5.0

func (*VirtualMachineConditionManager) RemoveCondition added in v0.5.0

type VirtualMachineControlInterface

type VirtualMachineControlInterface interface {
	PatchVirtualMachine(namespace, name string, data []byte) error
}

type VirtualMachineControllerRefManager

type VirtualMachineControllerRefManager struct {
	BaseControllerRefManager
	// contains filtered or unexported fields
}

func NewVirtualMachineControllerRefManager

func NewVirtualMachineControllerRefManager(
	virtualMachineControl VirtualMachineControlInterface,
	controller metav1.Object,
	selector labels.Selector,
	controllerKind schema.GroupVersionKind,
	canAdopt func() error,
) *VirtualMachineControllerRefManager

NewVirtualMachineControllerRefManager returns a VirtualMachineControllerRefManager that exposes methods to manage the controllerRef of virtual machines.

The CanAdopt() function can be used to perform a potentially expensive check (such as a live GET from the API server) prior to the first adoption. It will only be called (at most once) if an adoption is actually attempted. If CanAdopt() returns a non-nil error, all adoptions will fail.

NOTE: Once CanAdopt() is called, it will not be called again by the same

VirtualMachineControllerRefManager instance. Create a new instance if it makes
sense to check CanAdopt() again (e.g. in a different sync pass).

func (*VirtualMachineControllerRefManager) AdoptVirtualMachine

AdoptVirtualMachine sends a patch to take control of the vmi. It returns the error if the patching fails.

func (*VirtualMachineControllerRefManager) ClaimVirtualMachineByName

ClaimVirtualMachineByName tries to take ownership of a VirtualMachineInstance.

It will reconcile the following:

  • Adopt orphans if the selector matches.
  • Release owned objects if the selector no longer matches.

Optional: If one or more filters are specified, a VirtualMachineInstance will only be claimed if all filters return true.

A non-nil error is returned if some form of reconciliation was attempted and failed. Usually, controllers should try again later in case reconciliation is still needed.

If the error is nil, either the reconciliation succeeded, or no reconciliation was necessary. The list of VirtualMachines that you now own is returned.

func (*VirtualMachineControllerRefManager) ClaimVirtualMachines

ClaimVirtualMachines tries to take ownership of a list of VirtualMachines.

It will reconcile the following:

  • Adopt orphans if the selector matches.
  • Release owned objects if the selector no longer matches.

Optional: If one or more filters are specified, a VirtualMachineInstance will only be claimed if all filters return true.

A non-nil error is returned if some form of reconciliation was attempted and failed. Usually, controllers should try again later in case reconciliation is still needed.

If the error is nil, either the reconciliation succeeded, or no reconciliation was necessary. The list of VirtualMachines that you now own is returned.

func (*VirtualMachineControllerRefManager) ReleaseVirtualMachine

ReleaseVirtualMachine sends a patch to free the virtual machine from the control of the controller. It returns the error if the patching fails. 404 and 422 errors are ignored.

Jump to

Keyboard shortcuts

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