Documentation ¶
Overview ¶
Package cache is a client-side caching mechanism. It is useful for reducing the number of server calls you'd otherwise need to make. Reflector watches a server and updates a Store. Two stores are provided; one that simply caches objects (for example, to allow a scheduler to list currently available minions), and one that additionally acts as a FIFO queue (for example, to allow a scheduler to process incoming pods).
Index ¶
- type Enumerator
- type FIFO
- func (f *FIFO) Add(id string, obj interface{})
- func (c *FIFO) ContainedIDs() util.StringSet
- func (f *FIFO) Delete(id string)
- func (f *FIFO) Get(id string) (item interface{}, exists bool)
- func (f *FIFO) List() []interface{}
- func (f *FIFO) Pop() interface{}
- func (f *FIFO) Replace(idToObj map[string]interface{})
- func (f *FIFO) Update(id string, obj interface{})
- type GetFunc
- type ListWatch
- type ListerWatcher
- type Poller
- type Reflector
- type Store
- type StoreToNodeLister
- type StoreToPodLister
- type StoreToServiceLister
- type UndeltaStore
- func (u *UndeltaStore) Add(id string, obj interface{})
- func (u *UndeltaStore) ContainedIDs() util.StringSet
- func (u *UndeltaStore) Delete(id string)
- func (u *UndeltaStore) Get(id string) (item interface{}, exists bool)
- func (u *UndeltaStore) List() []interface{}
- func (u *UndeltaStore) Replace(idToObj map[string]interface{})
- func (u *UndeltaStore) Update(id string, obj interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Enumerator ¶
Enumerator should be able to return the list of objects to be synced with one object at a time.
type FIFO ¶
type FIFO struct {
// contains filtered or unexported fields
}
FIFO receives adds and updates from a Reflector, and puts them in a queue for FIFO order processing. If multiple adds/updates of a single item happen while an item is in the queue before it has been processed, it will only be processed once, and when it is processed, the most recent version will be processed. This can't be done with a channel.
func NewFIFO ¶
func NewFIFO() *FIFO
NewFIFO returns a Store which can be used to queue up items to process.
func (*FIFO) Add ¶
Add inserts an item, and puts it in the queue. The item is only enqueued if it doesn't already exist in the set.
func (*FIFO) ContainedIDs ¶
ContainedIDs returns a util.StringSet containing all IDs of the stored items. This is a snapshot of a moment in time, and one should keep in mind that other go routines can add or remove items after you call this.
func (*FIFO) Delete ¶
Delete removes an item. It doesn't add it to the queue, because this implementation assumes the consumer only cares about the objects, not the order in which they were created/added.
func (*FIFO) Pop ¶
func (f *FIFO) Pop() interface{}
Pop waits until an item is ready and returns it. If multiple items are ready, they are returned in the order in which they were added/updated. The item is removed from the queue (and the store) before it is returned, so if you don't succesfully process it, you need to add it back with Add().
type GetFunc ¶
type GetFunc func() (Enumerator, error)
GetFunc should return an enumerator that you wish the Poller to proccess.
type ListWatch ¶
type ListWatch struct { Client *client.Client FieldSelector labels.Selector Resource string Namespace string }
ListWatch knows how to list and watch a set of apiserver resources. It satisfies the ListerWatcher interface. It is a convenience function for users of NewReflector, etc. Client must not be nil.
type ListerWatcher ¶
type ListerWatcher interface { // List should return a list type object; the Items field will be extracted, and the // ResourceVersion field will be used to start the watch in the right place. List() (runtime.Object, error) // Watch should begin a watch at the specified version. Watch(resourceVersion string) (watch.Interface, error) }
ListerWatcher is any object that knows how to perform an initial list and start a watch on a resource.
type Poller ¶
type Poller struct {
// contains filtered or unexported fields
}
Poller is like Reflector, but it periodically polls instead of watching. This is intended to be a workaround for api objects that don't yet support watching.
func NewPoller ¶
NewPoller constructs a new poller. Note that polling probably doesn't make much sense to use along with the FIFO queue. The returned Poller will call getFunc and sync the objects in 'store' with the returned Enumerator, waiting 'period' between each call. It probably only makes sense to use a poller if you're treating the store as read-only.
type Reflector ¶
type Reflector struct {
// contains filtered or unexported fields
}
Reflector watches a specified resource and causes all changes to be reflected in the given store.
func NewReflector ¶
func NewReflector(lw ListerWatcher, expectedType interface{}, store Store) *Reflector
NewReflector creates a new Reflector object which will keep the given store up to date with the server's contents for the given resource. Reflector promises to only put things in the store that have the type of expectedType.
type Store ¶
type Store interface { Add(id string, obj interface{}) Update(id string, obj interface{}) Delete(id string) List() []interface{} ContainedIDs() util.StringSet Get(id string) (item interface{}, exists bool) // Replace will delete the contents of the store, using instead the // given map. Store takes ownership of the map, you should not reference // it after calling this function. Replace(idToObj map[string]interface{}) }
Store is a generic object storage interface. Reflector knows how to watch a server and update a store. A generic store is provided, which allows Reflector to be used as a local caching system, and an LRU store, which allows Reflector to work like a queue of items yet to be processed.
type StoreToNodeLister ¶
type StoreToNodeLister struct {
Store
}
StoreToNodeLister makes a Store have the List method of the client.NodeInterface The Store must contain (only) Nodes.
func (*StoreToNodeLister) GetNodeInfo ¶
func (s *StoreToNodeLister) GetNodeInfo(id string) (*api.Node, error)
TODO Move this back to scheduler as a helper function that takes a Store, rather than a method of StoreToNodeLister. GetNodeInfo returns cached data for the minion 'id'.
type StoreToPodLister ¶
type StoreToPodLister struct {
Store
}
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()
type StoreToServiceLister ¶
type StoreToServiceLister struct {
Store
}
StoreToServiceLister makes a Store that has the List method of the client.ServiceInterface The Store must contain (only) Services.
func (*StoreToServiceLister) GetPodServices ¶
TODO: Move this back to scheduler as a helper function that takes a Store, rather than a method of StoreToServiceLister.
func (*StoreToServiceLister) List ¶
func (s *StoreToServiceLister) List() (services api.ServiceList, err error)
type UndeltaStore ¶
type UndeltaStore struct { ActualStore Store PushFunc func([]interface{}) }
UndeltaStore listens to incremental updates and sends complete state on every change. It implements the Store interface so that it can receive a stream of mirrored objects from Reflector. Whenever it receives any complete (Store.Replace) or incremental change (Store.Add, Store.Update, Store.Delete), it sends the complete state by calling PushFunc. It is thread-safe. It guarantees that every change (Add, Update, Replace, Delete) results in one call to PushFunc, but sometimes PushFunc may be called twice with the same values. PushFunc should be thread safe.
func NewUndeltaStore ¶
func NewUndeltaStore(pushFunc func([]interface{})) *UndeltaStore
NewUndeltaStore returns an UndeltaStore implemented with a Store.
func (*UndeltaStore) Add ¶
func (u *UndeltaStore) Add(id string, obj interface{})
func (*UndeltaStore) ContainedIDs ¶
func (u *UndeltaStore) ContainedIDs() util.StringSet
func (*UndeltaStore) Delete ¶
func (u *UndeltaStore) Delete(id string)
func (*UndeltaStore) Get ¶
func (u *UndeltaStore) Get(id string) (item interface{}, exists bool)
func (*UndeltaStore) List ¶
func (u *UndeltaStore) List() []interface{}
func (*UndeltaStore) Replace ¶
func (u *UndeltaStore) Replace(idToObj map[string]interface{})
func (*UndeltaStore) Update ¶
func (u *UndeltaStore) Update(id string, obj interface{})