kubernetes: github.com/erikstmartin/kubernetes/pkg/client/cache Index | Files

package cache

import "github.com/erikstmartin/kubernetes/pkg/client/cache"

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).


Package Files

doc.go fifo.go poller.go reflector.go store.go

type Enumerator Uses

type Enumerator interface {
    Len() int
    Get(index int) (ID string, object interface{})

Enumerator should be able to return the list of objects to be synced with one object at a time.

type FIFO Uses

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 Uses

func NewFIFO() *FIFO

NewFIFO returns a Store which can be used to queue up items to process.

func (*FIFO) Add Uses

func (f *FIFO) Add(id string, obj interface{})

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) Contains Uses

func (c *FIFO) Contains() util.StringSet

Contains returns a util.StringSet containing all IDs of stored the 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 Uses

func (f *FIFO) Delete(id string)

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) Get Uses

func (f *FIFO) Get(id string) (item interface{}, exists bool)

Get returns the requested item, or sets exists=false.

func (*FIFO) List Uses

func (f *FIFO) List() []interface{}

List returns a list of all the items.

func (*FIFO) Pop Uses

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().

func (*FIFO) Replace Uses

func (f *FIFO) Replace(idToObj map[string]interface{})

Replace will delete the contents of 'f', using instead the given map. 'f' takes ownersip of the map, you should not reference the map again after calling this function. f's queue is reset, too; upon return, it will contain the items in the map, in no particular order.

func (*FIFO) Update Uses

func (f *FIFO) Update(id string, obj interface{})

Update is the same as Add in this implementation.

type GetFunc Uses

type GetFunc func() (Enumerator, error)

GetFunc should return an enumerator that you wish the Poller to proccess.

type ListerWatcher Uses

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 Uses

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 Uses

func NewPoller(getFunc GetFunc, period time.Duration, store Store) *Poller

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.

func (*Poller) Run Uses

func (p *Poller) Run()

Run begins polling. It starts a goroutine and returns immediately.

type Reflector Uses

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 Uses

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.

func (*Reflector) Run Uses

func (r *Reflector) Run()

Run starts a watch and handles watch events. Will restart the watch if it is closed. Run starts a goroutine and returns immediately.

type Store Uses

type Store interface {
    Add(id string, obj interface{})
    Update(id string, obj interface{})
    Delete(id string)
    List() []interface{}
    Contains() 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.

func NewStore Uses

func NewStore() Store

NewStore returns a Store implemented simply with a map and a lock.

Package cache imports 11 packages (graph). Updated 2018-04-10. Refresh now. Tools for package owners.