controller

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2016 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package controller contains code for controllers (like the replication controller).

Index

Constants

View Source
const (
	// FailedCreatePodReason is added in an event and in a replica set condition
	// when a pod for a replica set is failed to be created.
	FailedCreatePodReason = "FailedCreate"
	// SuccessfulCreatePodReason is added in an event when a pod for a replica set
	// is successfully created.
	SuccessfulCreatePodReason = "SuccessfulCreate"
	// FailedDeletePodReason is added in an event and in a replica set condition
	// when a pod for a replica set is failed to be deleted.
	FailedDeletePodReason = "FailedDelete"
	// SuccessfulDeletePodReason is added in an event when a pod for a replica set
	// is successfully deleted.
	SuccessfulDeletePodReason = "SuccessfulDelete"
)

Reasons for pod events

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.

Functions

func FilterActivePods added in v0.7.0

func FilterActivePods(pods []*api.Pod) []*api.Pod

FilterActivePods returns pods that have not terminated.

func FilterActiveReplicaSets added in v1.2.0

func FilterActiveReplicaSets(replicaSets []*extensions.ReplicaSet) []*extensions.ReplicaSet

FilterActiveReplicaSets returns replica sets that have (or at least ought to have) pods.

func GetPodFromTemplate added in v1.3.0

func GetPodFromTemplate(template *api.PodTemplateSpec, parentObject runtime.Object, controllerRef *api.OwnerReference) (*api.Pod, error)

func IsPodActive added in v1.2.0

func IsPodActive(p *api.Pod) bool

func NoResyncPeriodFunc added in v1.1.1

func NoResyncPeriodFunc() time.Duration

Returns 0 for resyncPeriod in case resyncing is not needed.

func PodKey added in v1.2.0

func PodKey(pod *api.Pod) string

PodKey returns a key unique to the given pod within a cluster. It's used so we consistently use the same key scheme in this module. It does exactly what cache.MetaNamespaceKeyFunc would have done except there's not possibility for error since we know the exact type.

Types

type ActivePods added in v1.1.0

type ActivePods []*api.Pod

ActivePods type allows custom sorting of pods so a controller can pick the best ones to delete.

func (ActivePods) Len added in v1.1.0

func (s ActivePods) Len() int

func (ActivePods) Less added in v1.1.0

func (s ActivePods) Less(i, j int) bool

func (ActivePods) Swap added in v1.1.0

func (s ActivePods) Swap(i, j int)

type ByLogging added in v1.4.0

type ByLogging []*api.Pod

ByLogging allows custom sorting of pods so the best one can be picked for getting its logs.

func (ByLogging) Len added in v1.4.0

func (s ByLogging) Len() int

func (ByLogging) Less added in v1.4.0

func (s ByLogging) Less(i, j int) bool

func (ByLogging) Swap added in v1.4.0

func (s ByLogging) Swap(i, j int)

type ControlleeExpectations added in v1.2.0

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

ControlleeExpectations track controllee creates/deletes.

func (*ControlleeExpectations) Add added in v1.2.0

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

Add increments the add and del counters.

func (*ControlleeExpectations) Fulfilled added in v1.2.0

func (e *ControlleeExpectations) Fulfilled() bool

Fulfilled returns true if this expectation has been fulfilled.

func (*ControlleeExpectations) GetExpectations added in v1.2.0

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

GetExpectations returns the add and del expectations of the controllee.

type ControllerClientBuilder added in v1.5.0

type ControllerClientBuilder interface {
	Config(name string) (*restclient.Config, error)
	Client(name string) (clientset.Interface, error)
	ClientOrDie(name string) clientset.Interface
}

ControllerClientBuilder allow syou to get clients and configs for controllers

type ControllerExpectations added in v1.1.0

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

func NewControllerExpectations() *ControllerExpectations

NewControllerExpectations returns a store for ControllerExpectations.

func (*ControllerExpectations) CreationObserved added in v1.1.0

func (r *ControllerExpectations) CreationObserved(controllerKey string)

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

func (*ControllerExpectations) DeleteExpectations added in v1.1.0

func (r *ControllerExpectations) DeleteExpectations(controllerKey string)

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

func (*ControllerExpectations) DeletionObserved added in v1.1.0

func (r *ControllerExpectations) DeletionObserved(controllerKey string)

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

func (*ControllerExpectations) ExpectCreations added in v1.1.0

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

func (*ControllerExpectations) ExpectDeletions added in v1.1.0

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

func (*ControllerExpectations) GetExpectations added in v1.1.0

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

GetExpectations returns the ControlleeExpectations of the given controller.

func (*ControllerExpectations) LowerExpectations added in v1.2.0

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

Decrements the expectation counts of the given controller.

func (*ControllerExpectations) RaiseExpectations added in v1.2.0

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

Increments the expectation counts of the given controller.

func (*ControllerExpectations) SatisfiedExpectations added in v1.1.0

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

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

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

type ControllerExpectationsInterface added in v1.1.0

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 ControllersByCreationTimestamp added in v1.2.0

type ControllersByCreationTimestamp []*api.ReplicationController

ControllersByCreationTimestamp sorts a list of ReplicationControllers by creation timestamp, using their names as a tie breaker.

func (ControllersByCreationTimestamp) Len added in v1.2.0

func (ControllersByCreationTimestamp) Less added in v1.2.0

func (ControllersByCreationTimestamp) Swap added in v1.2.0

func (o ControllersByCreationTimestamp) Swap(i, j int)

type Expectations added in v0.17.0

type Expectations interface {
	Fulfilled() bool
}

Expectations are either fulfilled, or expire naturally.

type FakePodControl added in v1.1.0

type FakePodControl struct {
	sync.Mutex
	Templates      []api.PodTemplateSpec
	ControllerRefs []api.OwnerReference
	DeletePodName  []string
	Patches        [][]byte
	Err            error
}

func (*FakePodControl) Clear added in v1.1.0

func (f *FakePodControl) Clear()

func (*FakePodControl) CreatePods added in v1.1.0

func (f *FakePodControl) CreatePods(namespace string, spec *api.PodTemplateSpec, object runtime.Object) error

func (*FakePodControl) CreatePodsOnNode added in v1.1.0

func (f *FakePodControl) CreatePodsOnNode(nodeName, namespace string, template *api.PodTemplateSpec, object runtime.Object) error

func (*FakePodControl) CreatePodsWithControllerRef added in v1.4.0

func (f *FakePodControl) CreatePodsWithControllerRef(namespace string, spec *api.PodTemplateSpec, object runtime.Object, controllerRef *api.OwnerReference) error

func (*FakePodControl) DeletePod added in v1.1.0

func (f *FakePodControl) DeletePod(namespace string, podID string, object runtime.Object) error

func (*FakePodControl) PatchPod added in v1.4.0

func (f *FakePodControl) PatchPod(namespace, name string, data []byte) error

type MatchingCache added in v1.2.0

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

MatchingCache save label and selector matching relationship

func NewMatchingCache added in v1.2.0

func NewMatchingCache(maxCacheEntries int) *MatchingCache

NewMatchingCache return a NewMatchingCache, which save label and selector matching relationship.

func (*MatchingCache) Add added in v1.2.0

func (c *MatchingCache) Add(labelObj objectWithMeta, selectorObj objectWithMeta)

Add will add matching information to the cache.

func (*MatchingCache) GetMatchingObject added in v1.2.0

func (c *MatchingCache) GetMatchingObject(labelObj objectWithMeta) (controller interface{}, exists bool)

GetMatchingObject lookup the matching object for a given object. Note: the cache information may be invalid since the controller may be deleted or updated, we need check in the external request to ensure the cache data is not dirty.

func (*MatchingCache) InvalidateAll added in v1.2.0

func (c *MatchingCache) InvalidateAll()

InvalidateAll invalidate the whole cache.

func (*MatchingCache) Update added in v1.2.0

func (c *MatchingCache) Update(labelObj objectWithMeta, selectorObj objectWithMeta)

Update update the cached matching information.

type PodControlInterface

type PodControlInterface interface {
	// CreatePods creates new pods according to the spec.
	CreatePods(namespace string, template *api.PodTemplateSpec, object runtime.Object) error
	// CreatePodsOnNode creates a new pod according to the spec on the specified node.
	CreatePodsOnNode(nodeName, namespace string, template *api.PodTemplateSpec, object runtime.Object) error
	// CreatePodsWithControllerRef creates new pods according to the spec, and sets object as the pod's controller.
	CreatePodsWithControllerRef(namespace string, template *api.PodTemplateSpec, object runtime.Object, controllerRef *api.OwnerReference) error
	// DeletePod deletes the pod identified by podID.
	DeletePod(namespace string, podID string, object runtime.Object) error
	// PatchPod patches the pod.
	PatchPod(namespace, name string, data []byte) error
}

PodControlInterface is an interface that knows how to add or delete pods created as an interface to allow testing.

type PodControllerRefManager added in v1.4.0

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

func NewPodControllerRefManager added in v1.4.0

func NewPodControllerRefManager(
	podControl PodControlInterface,
	controllerObject api.ObjectMeta,
	controllerSelector labels.Selector,
	controllerKind unversioned.GroupVersionKind,
) *PodControllerRefManager

NewPodControllerRefManager returns a PodControllerRefManager that exposes methods to manage the controllerRef of pods.

func (*PodControllerRefManager) AdoptPod added in v1.4.0

func (m *PodControllerRefManager) AdoptPod(pod *api.Pod) error

AdoptPod sends a patch to take control of the pod. It returns the error if the patching fails.

func (*PodControllerRefManager) Classify added in v1.4.0

func (m *PodControllerRefManager) Classify(pods []*api.Pod) (
	matchesAndControlled []*api.Pod,
	matchesNeedsController []*api.Pod,
	controlledDoesNotMatch []*api.Pod)

Classify first filters out inactive pods, then it classify the remaining pods into three categories: 1. matchesAndControlled are the pods whose labels match the selector of the RC, and have a controllerRef pointing to the controller 2. matchesNeedsController are the pods whose labels match the RC, but don't have a controllerRef. (Pods with matching labels but with a controllerRef pointing to other object are ignored) 3. controlledDoesNotMatch are the pods that have a controllerRef pointing to the controller, but their labels no longer match the selector.

func (*PodControllerRefManager) ReleasePod added in v1.4.0

func (m *PodControllerRefManager) ReleasePod(pod *api.Pod) error

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

type RealPodControl

type RealPodControl struct {
	KubeClient clientset.Interface
	Recorder   record.EventRecorder
}

RealPodControl is the default implementation of PodControlInterface.

func (RealPodControl) CreatePods added in v1.1.0

func (r RealPodControl) CreatePods(namespace string, template *api.PodTemplateSpec, object runtime.Object) error

func (RealPodControl) CreatePodsOnNode added in v1.1.0

func (r RealPodControl) CreatePodsOnNode(nodeName, namespace string, template *api.PodTemplateSpec, object runtime.Object) error

func (RealPodControl) CreatePodsWithControllerRef added in v1.4.0

func (r RealPodControl) CreatePodsWithControllerRef(namespace string, template *api.PodTemplateSpec, controllerObject runtime.Object, controllerRef *api.OwnerReference) error

func (RealPodControl) DeletePod added in v1.1.0

func (r RealPodControl) DeletePod(namespace string, podID string, object runtime.Object) error

func (RealPodControl) PatchPod added in v1.4.0

func (r RealPodControl) PatchPod(namespace, name string, data []byte) error

type ReplicaSetsByCreationTimestamp added in v1.2.0

type ReplicaSetsByCreationTimestamp []*extensions.ReplicaSet

ReplicaSetsByCreationTimestamp sorts a list of ReplicaSet by creation timestamp, using their names as a tie breaker.

func (ReplicaSetsByCreationTimestamp) Len added in v1.2.0

func (ReplicaSetsByCreationTimestamp) Less added in v1.2.0

func (ReplicaSetsByCreationTimestamp) Swap added in v1.2.0

func (o ReplicaSetsByCreationTimestamp) Swap(i, j int)

type ReplicaSetsBySizeNewer added in v1.4.0

type ReplicaSetsBySizeNewer []*extensions.ReplicaSet

ReplicaSetsBySizeNewer sorts a list of ReplicaSet by size in descending order, using their creation timestamp or name as a tie breaker. By using the creation timestamp, this sorts from new to old replica sets.

func (ReplicaSetsBySizeNewer) Len added in v1.4.0

func (o ReplicaSetsBySizeNewer) Len() int

func (ReplicaSetsBySizeNewer) Less added in v1.4.0

func (o ReplicaSetsBySizeNewer) Less(i, j int) bool

func (ReplicaSetsBySizeNewer) Swap added in v1.4.0

func (o ReplicaSetsBySizeNewer) Swap(i, j int)

type ReplicaSetsBySizeOlder added in v1.4.0

type ReplicaSetsBySizeOlder []*extensions.ReplicaSet

ReplicaSetsBySizeOlder sorts a list of ReplicaSet by size in descending order, using their creation timestamp or name as a tie breaker. By using the creation timestamp, this sorts from old to new replica sets.

func (ReplicaSetsBySizeOlder) Len added in v1.4.0

func (o ReplicaSetsBySizeOlder) Len() int

func (ReplicaSetsBySizeOlder) Less added in v1.4.0

func (o ReplicaSetsBySizeOlder) Less(i, j int) bool

func (ReplicaSetsBySizeOlder) Swap added in v1.4.0

func (o ReplicaSetsBySizeOlder) Swap(i, j int)

type ResyncPeriodFunc added in v1.1.1

type ResyncPeriodFunc func() time.Duration

func StaticResyncPeriodFunc added in v1.2.0

func StaticResyncPeriodFunc(resyncPeriod time.Duration) ResyncPeriodFunc

StaticResyncPeriodFunc returns the resync period specified

type SAControllerClientBuilder added in v1.5.0

type SAControllerClientBuilder struct {
	// ClientConfig is a skeleton config to clone and use as the basis for each controller client
	ClientConfig *restclient.Config

	// CoreClient is used to provision service accounts if needed and watch for their associated tokens
	// to construct a controller client
	CoreClient unversionedcore.CoreInterface

	// Namespace is the namespace used to host the service accounts that will back the
	// controllers.  It must be highly privileged namespace which normal users cannot inspect.
	Namespace string
}

SAControllerClientBuilder is a ControllerClientBuilder that returns clients identifying as service accounts

func (SAControllerClientBuilder) Client added in v1.5.0

func (SAControllerClientBuilder) ClientOrDie added in v1.5.0

func (SAControllerClientBuilder) Config added in v1.5.0

config returns a complete clientConfig for constructing clients. This is separate in anticipation of composition which means that not all clientsets are known here

type SimpleControllerClientBuilder added in v1.5.0

type SimpleControllerClientBuilder struct {
	// ClientConfig is a skeleton config to clone and use as the basis for each controller client
	ClientConfig *restclient.Config
}

SimpleControllerClientBuilder returns a fixed client with different user agents

func (SimpleControllerClientBuilder) Client added in v1.5.0

func (SimpleControllerClientBuilder) ClientOrDie added in v1.5.0

func (SimpleControllerClientBuilder) Config added in v1.5.0

type UIDSet added in v1.2.0

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 added in v1.2.0

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 consistenly, one needs to remember the expected deletes so they aren't double counted. TODO: Track creates as well (#22599)

func NewUIDTrackingControllerExpectations added in v1.2.0

func NewUIDTrackingControllerExpectations(ce ControllerExpectationsInterface) *UIDTrackingControllerExpectations

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

func (*UIDTrackingControllerExpectations) DeleteExpectations added in v1.2.0

func (u *UIDTrackingControllerExpectations) DeleteExpectations(rcKey string)

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

func (*UIDTrackingControllerExpectations) DeletionObserved added in v1.2.0

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

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

func (*UIDTrackingControllerExpectations) ExpectDeletions added in v1.2.0

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

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

func (*UIDTrackingControllerExpectations) GetUIDs added in v1.2.0

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.

Directories

Path Synopsis
Package certificates contains logic for watching and synchronizing CertificateSigningRequests.
Package certificates contains logic for watching and synchronizing CertificateSigningRequests.
Package cronjob contains the controller for CronJob objects.
Package cronjob contains the controller for CronJob objects.
Package daemon contains logic for watching and synchronizing daemons.
Package daemon contains logic for watching and synchronizing daemons.
Package deployment contains all the logic for handling Kubernetes Deployments.
Package deployment contains all the logic for handling Kubernetes Deployments.
Package service provides EndpointController implementation to manage and sync service endpoints.
Package service provides EndpointController implementation to manage and sync service endpoints.
Package job contains logic for watching and synchronizing jobs.
Package job contains logic for watching and synchronizing jobs.
namespace contains a controller that handles namespace lifecycle
namespace contains a controller that handles namespace lifecycle
Package node contains code for syncing cloud instances with node registry
Package node contains code for syncing cloud instances with node registry
Package podautoscaler contains logic for autoscaling number of pods based on metrics observed.
Package podautoscaler contains logic for autoscaling number of pods based on metrics observed.
Package podgc contains a very simple pod "garbage collector" implementation, PodGCController, that runs in the controller manager.
Package podgc contains a very simple pod "garbage collector" implementation, PodGCController, that runs in the controller manager.
Package replicaset contains logic for watching and synchronizing ReplicaSets.
Package replicaset contains logic for watching and synchronizing ReplicaSets.
Package replication contains logic for watching and synchronizing replication controllers.
Package replication contains logic for watching and synchronizing replication controllers.
resourcequota contains a controller that makes resource quota usage observations
resourcequota contains a controller that makes resource quota usage observations
Package route contains code for syncing cloud routing rules with the list of registered nodes.
Package route contains code for syncing cloud routing rules with the list of registered nodes.
Package service contains code for syncing cloud load balancers with the service registry.
Package service contains code for syncing cloud load balancers with the service registry.
Package serviceaccount provides implementations to manage service accounts and service account tokens
Package serviceaccount provides implementations to manage service accounts and service account tokens
volume
attachdetach
Package volume implements a controller to manage volume attach and detach operations.
Package volume implements a controller to manage volume attach and detach operations.
attachdetach/cache
Package cache implements data structures used by the attach/detach controller to keep track of volumes, the nodes they are attached to, and the pods that reference them.
Package cache implements data structures used by the attach/detach controller to keep track of volumes, the nodes they are attached to, and the pods that reference them.
attachdetach/populator
Package populator implements interfaces that monitor and keep the states of the desired_state_of_word in sync with the "ground truth" from informer.
Package populator implements interfaces that monitor and keep the states of the desired_state_of_word in sync with the "ground truth" from informer.
attachdetach/reconciler
Package reconciler implements interfaces that attempt to reconcile the desired state of the with the actual state of the world by triggering actions.
Package reconciler implements interfaces that attempt to reconcile the desired state of the with the actual state of the world by triggering actions.
attachdetach/statusupdater
Package statusupdater implements interfaces that enable updating the status of API objects.
Package statusupdater implements interfaces that enable updating the status of API objects.

Jump to

Keyboard shortcuts

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