controller

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: Apache-2.0 Imports: 29 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 DataVolumeKey added in v0.8.0

func DataVolumeKey(dataVolume *cdiv1.DataVolume) string

func GetControllerOf added in v0.1.0

func GetControllerOf(pod *k8sv1.Pod) *metav1.OwnerReference

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

func HandlePanic

func HandlePanic()

func HasFinalizer added in v0.1.0

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

func IsControlledBy added in v0.11.0

func IsControlledBy(pod *k8sv1.Pod, vmi *virtv1.VirtualMachineInstance) bool

func MigrationKey added in v0.9.2

func MigrationKey(migration *v1.VirtualMachineInstanceMigration) string

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, kubevirtNamespace 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 added in v0.1.0

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 added in v0.1.0

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

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

func (*BaseControllerRefManager) CanAdopt added in v0.1.0

func (m *BaseControllerRefManager) CanAdopt() error

func (*BaseControllerRefManager) ClaimObject added in v0.1.0

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 VirtualMachineInstanceMigration objects
	VirtualMachineInstanceMigration() cache.SharedIndexInformer

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

	// Watches for PersistentVolumeClaim objects
	PersistentVolumeClaim() cache.SharedIndexInformer

	// Watches for LimitRange objects
	LimitRanges() cache.SharedIndexInformer

	// Watches for CDI DataVolume objects
	DataVolume() cache.SharedIndexInformer

	// Fake CDI DataVolume informer used when feature gate is disabled
	DummyDataVolume() cache.SharedIndexInformer
}

func NewKubeInformerFactory

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

type RealVirtualMachineControl added in v0.1.0

type RealVirtualMachineControl struct {
	Clientset kubecli.KubevirtClient
}

func (RealVirtualMachineControl) PatchDataVolume added in v0.8.0

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

func (RealVirtualMachineControl) PatchVirtualMachine added in v0.1.0

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) GetPodCondition added in v0.7.0

func (d *VirtualMachineConditionManager) GetPodCondition(pod *k8sv1.Pod, conditionType k8sv1.PodConditionType, status k8sv1.ConditionStatus) *k8sv1.PodCondition

func (*VirtualMachineConditionManager) HasCondition added in v0.5.0

func (*VirtualMachineConditionManager) PodHasCondition added in v0.7.0

func (d *VirtualMachineConditionManager) PodHasCondition(pod *k8sv1.Pod, conditionType k8sv1.PodConditionType, status k8sv1.ConditionStatus) bool

func (*VirtualMachineConditionManager) RemoveCondition added in v0.5.0

type VirtualMachineControlInterface added in v0.1.0

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

type VirtualMachineControllerRefManager added in v0.1.0

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

func NewVirtualMachineControllerRefManager added in v0.1.0

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) AdoptDataVolume added in v0.8.0

func (m *VirtualMachineControllerRefManager) AdoptDataVolume(dataVolume *cdiv1.DataVolume) error

AdoptDataVolume sends a patch to take control of the dataVolume. It returns the error if the patching fails.

func (*VirtualMachineControllerRefManager) AdoptVirtualMachine added in v0.1.0

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

func (*VirtualMachineControllerRefManager) ClaimMatchedDataVolumes added in v0.8.0

func (m *VirtualMachineControllerRefManager) ClaimMatchedDataVolumes(dataVolumes []*cdiv1.DataVolume, filters ...func(machine *cdiv1.DataVolume) bool) ([]*cdiv1.DataVolume, error)

ClaimDataVolume tries to take ownership of a list of DataVolumes.

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 DataVolume 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 DataVolumes that you now own is returned.

func (*VirtualMachineControllerRefManager) ClaimVirtualMachineByName added in v0.3.0

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 added in v0.1.0

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) ReleaseDataVolume added in v0.8.0

func (m *VirtualMachineControllerRefManager) ReleaseDataVolume(dataVolume *cdiv1.DataVolume) error

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

func (*VirtualMachineControllerRefManager) ReleaseVirtualMachine added in v0.1.0

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