Documentation ¶
Overview ¶
Package controller contains code for controllers (like the replication controller).
Index ¶
- Constants
- Variables
- func FilterActivePods(pods []api.Pod) []*api.Pod
- func FilterActiveReplicaSets(replicaSets []*extensions.ReplicaSet) []*extensions.ReplicaSet
- func IsPodActive(p api.Pod) bool
- func NoResyncPeriodFunc() time.Duration
- func PodKey(pod *api.Pod) string
- type ActivePods
- type ControlleeExpectations
- type ControllerExpectations
- func (r *ControllerExpectations) CreationObserved(controllerKey string)
- func (r *ControllerExpectations) DeleteExpectations(controllerKey string)
- func (r *ControllerExpectations) DeletionObserved(controllerKey string)
- func (r *ControllerExpectations) ExpectCreations(controllerKey string, adds int) error
- func (r *ControllerExpectations) ExpectDeletions(controllerKey string, dels int) error
- func (r *ControllerExpectations) GetExpectations(controllerKey string) (*ControlleeExpectations, bool, error)
- func (r *ControllerExpectations) LowerExpectations(controllerKey string, add, del int)
- func (r *ControllerExpectations) RaiseExpectations(controllerKey string, add, del int)
- func (r *ControllerExpectations) SatisfiedExpectations(controllerKey string) bool
- func (r *ControllerExpectations) SetExpectations(controllerKey string, add, del int) error
- type ControllerExpectationsInterface
- type ControllersByCreationTimestamp
- type Expectations
- type FakePodControl
- func (f *FakePodControl) Clear()
- func (f *FakePodControl) CreatePods(namespace string, spec *api.PodTemplateSpec, object runtime.Object) error
- func (f *FakePodControl) CreatePodsOnNode(nodeName, namespace string, template *api.PodTemplateSpec, ...) error
- func (f *FakePodControl) DeletePod(namespace string, podID string, object runtime.Object) error
- type MatchingCache
- func (c *MatchingCache) Add(labelObj objectWithMeta, selectorObj objectWithMeta)
- func (c *MatchingCache) GetMatchingObject(labelObj objectWithMeta) (controller interface{}, exists bool)
- func (c *MatchingCache) InvalidateAll()
- func (c *MatchingCache) Update(labelObj objectWithMeta, selectorObj objectWithMeta)
- type PodControlInterface
- type RealPodControl
- func (r RealPodControl) CreatePods(namespace string, template *api.PodTemplateSpec, object runtime.Object) error
- func (r RealPodControl) CreatePodsOnNode(nodeName, namespace string, template *api.PodTemplateSpec, ...) error
- func (r RealPodControl) DeletePod(namespace string, podID string, object runtime.Object) error
- type ReplicaSetsByCreationTimestamp
- type ResyncPeriodFunc
- type UIDSet
- type UIDTrackingControllerExpectations
- func (u *UIDTrackingControllerExpectations) DeleteExpectations(rcKey string)
- func (u *UIDTrackingControllerExpectations) DeletionObserved(rcKey, deleteKey string)
- func (u *UIDTrackingControllerExpectations) ExpectDeletions(rcKey string, deletedKeys []string) error
- func (u *UIDTrackingControllerExpectations) GetUIDs(controllerKey string) sets.String
Constants ¶
const ( CreatedByAnnotation = "kubernetes.io/created-by" // 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 ¶
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
var (
KeyFunc = framework.DeletionHandlingMetaNamespaceKeyFunc
)
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 ¶
FilterActivePods returns pods that have not terminated.
func FilterActiveReplicaSets ¶
func FilterActiveReplicaSets(replicaSets []*extensions.ReplicaSet) []*extensions.ReplicaSet
FilterActiveReplicaSets returns replica sets that have (or at least ought to have) pods.
func IsPodActive ¶
func NoResyncPeriodFunc ¶
Returns 0 for resyncPeriod in case resyncing is not needed.
Types ¶
type ActivePods ¶
ActivePods type allows custom sorting of pods so a controller can pick the best ones to delete.
func (ActivePods) Len ¶
func (s ActivePods) Len() int
func (ActivePods) Less ¶
func (s ActivePods) Less(i, j int) bool
func (ActivePods) Swap ¶
func (s ActivePods) Swap(i, j int)
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 ¶
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` expecation 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 ControllersByCreationTimestamp ¶
type ControllersByCreationTimestamp []*api.ReplicationController
ControllersByCreationTimestamp sorts a list of ReplicationControllers by creation timestamp, using their names as a tie breaker.
func (ControllersByCreationTimestamp) Len ¶
func (o ControllersByCreationTimestamp) Len() int
func (ControllersByCreationTimestamp) Less ¶
func (o ControllersByCreationTimestamp) Less(i, j int) bool
func (ControllersByCreationTimestamp) Swap ¶
func (o ControllersByCreationTimestamp) Swap(i, j int)
type Expectations ¶
type Expectations interface {
Fulfilled() bool
}
Expectations are either fulfilled, or expire naturally.
type FakePodControl ¶
type FakePodControl struct { sync.Mutex Templates []api.PodTemplateSpec DeletePodName []string Err error }
func (*FakePodControl) Clear ¶
func (f *FakePodControl) Clear()
func (*FakePodControl) CreatePods ¶
func (f *FakePodControl) CreatePods(namespace string, spec *api.PodTemplateSpec, object runtime.Object) error
func (*FakePodControl) CreatePodsOnNode ¶
func (f *FakePodControl) CreatePodsOnNode(nodeName, namespace string, template *api.PodTemplateSpec, object runtime.Object) error
type MatchingCache ¶
type MatchingCache struct {
// contains filtered or unexported fields
}
MatchingCache save label and selector matching relationship
func NewMatchingCache ¶
func NewMatchingCache(maxCacheEntries int) *MatchingCache
NewMatchingCache return a NewMatchingCache, which save label and selector matching relationship.
func (*MatchingCache) Add ¶
func (c *MatchingCache) Add(labelObj objectWithMeta, selectorObj objectWithMeta)
Add will add matching information to the cache.
func (*MatchingCache) GetMatchingObject ¶
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 ¶
func (c *MatchingCache) InvalidateAll()
InvalidateAll invalidate the whole cache.
func (*MatchingCache) Update ¶
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 accorting to the spec on the specified node. CreatePodsOnNode(nodeName, namespace string, template *api.PodTemplateSpec, object runtime.Object) error // DeletePod deletes the pod identified by podID. DeletePod(namespace string, podID string, object runtime.Object) error }
PodControlInterface is an interface that knows how to add or delete pods created as an interface to allow testing.
type RealPodControl ¶
type RealPodControl struct { KubeClient clientset.Interface Recorder record.EventRecorder }
RealPodControl is the default implementation of PodControlInterface.
func (RealPodControl) CreatePods ¶
func (r RealPodControl) CreatePods(namespace string, template *api.PodTemplateSpec, object runtime.Object) error
func (RealPodControl) CreatePodsOnNode ¶
func (r RealPodControl) CreatePodsOnNode(nodeName, namespace string, template *api.PodTemplateSpec, object runtime.Object) error
type ReplicaSetsByCreationTimestamp ¶
type ReplicaSetsByCreationTimestamp []*extensions.ReplicaSet
ReplicaSetsByCreationTimestamp sorts a list of ReplicationSets by creation timestamp, using their names as a tie breaker.
func (ReplicaSetsByCreationTimestamp) Len ¶
func (o ReplicaSetsByCreationTimestamp) Len() int
func (ReplicaSetsByCreationTimestamp) Less ¶
func (o ReplicaSetsByCreationTimestamp) Less(i, j int) bool
func (ReplicaSetsByCreationTimestamp) Swap ¶
func (o ReplicaSetsByCreationTimestamp) Swap(i, j int)
type ResyncPeriodFunc ¶
func StaticResyncPeriodFunc ¶
func StaticResyncPeriodFunc(resyncPeriod time.Duration) ResyncPeriodFunc
StaticResyncPeriodFunc returns the resync period specified
type UIDSet ¶
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 consistenly, one needs to remember the expected deletes so they aren't double counted. TODO: Track 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.
Directories ¶
Path | Synopsis |
---|---|
Package framework implements all the grunt work involved in running a simple controller.
|
Package framework implements all the grunt work involved in running a simple controller. |