cilium: github.com/cilium/cilium/pkg/kvstore/store Index | Files

package store

import "github.com/cilium/cilium/pkg/kvstore/store"

Package store implements a shared store backed by a kvstore or similar with the following properties:

* A single type is used to represent all keys * Any number of collaborators can join the store. Typically a collaborator

is an individual Cilium agent running on each node.

* All collaborators can own and contribute keys to the store. Each key is

owned by exactly one collaborator. It is the responsibility of each
collaborator to pick a key name which is guaranteed to be unique.

* All collaborate desire to see all keys within the scope of a store. The

scope of the store is defined by a common key prefix. For this purpose,
each collaborator maintains a local cache of all keys in the store by
subscribing to change events.

Index

Package Files

doc.go store.go

type Configuration Uses

type Configuration struct {
    // Prefix is the key prefix of the store shared by all keys. The prefix
    // is the unique identification of the store. Multiple collaborators
    // connected to the same kvstore cluster configuring stores with
    // matching prefixes will automatically form a shared store. This
    // parameter is required.
    Prefix string

    // SynchronizationInterval is the interval in which locally owned keys
    // are synchronized with the kvstore. This parameter is optional.
    SynchronizationInterval time.Duration

    // KeyCreator is called to allocate a Key instance when a new shared
    // key is discovered. This parameter is required.
    KeyCreator KeyCreator

    // Backend is the kvstore to use as a backend. If no backend is
    // specified, kvstore.Client() is being used.
    Backend kvstore.BackendOperations

    // Observer is the observe that will receive events on key mutations
    Observer Observer
}

Configuration is the set of configuration parameters of a shared store.

type Key Uses

type Key interface {
    NamedKey

    // Marshal is called to retrieve the byte slice representation of the
    // data represented by the key to store it in the kvstore. The function
    // must ensure that the underlying datatype is properly locked. It is
    // typically a good idea to use json.Marshal to implement this
    // function.
    Marshal() ([]byte, error)

    // Unmarshal is called when an update from the kvstore is received. The
    // byte slice passed to the function is coming from the Marshal
    // function from another collaborator. The function must unmarshal and
    // update the underlying data type. It is typically a good idea to use
    // json.Unmarshal to implement this function.
    Unmarshal(data []byte) error
}

Key is the interface that a data structure must implement in order to be stored and shared as a key in a SharedStore.

type KeyCreator Uses

type KeyCreator func() Key

KeyCreator is the function to create a new empty Key instances. Store collaborators must implement this interface and provide the implementation in the Configuration structure.

type LocalKey Uses

type LocalKey interface {
    Key

    // DeepKeyCopy must return a deep copy of the key
    DeepKeyCopy() LocalKey
}

LocalKey is a Key owned by the local store instance

type NamedKey Uses

type NamedKey interface {
    // GetKeyName must return the name of the key. The name of the key must
    // be unique within the store and stable for a particular key. The name
    // of the key must be identical across agent restarts as the keys
    // remain in the kvstore.
    GetKeyName() string
}

NamedKey is an interface that a data structure must implement in order to be deleted from a SharedStore.

type Observer Uses

type Observer interface {
    // OnDelete is called when the key has been deleted from the shared store
    OnDelete(k NamedKey)

    // OnUpdate is called whenever a change has occurred in the data
    // structure represented by the key
    OnUpdate(k Key)
}

Observer receives events when objects in the store mutate

type SharedStore Uses

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

SharedStore is an instance of a shared store. It is created with JoinSharedStore() and released with the SharedStore.Close() function.

func JoinSharedStore Uses

func JoinSharedStore(c Configuration) (*SharedStore, error)

JoinSharedStore creates a new shared store based on the provided configuration. An error is returned if the configuration is invalid. The store is initialized with the contents of the kvstore. An error is returned if the contents cannot be retrieved synchronously from the kvstore. Starts a controller to continuously synchronize the store with the kvstore.

func (*SharedStore) Close Uses

func (s *SharedStore) Close()

Close stops participation with a shared store and removes all keys owned by this node in the kvstore. This stops the controller started by JoinSharedStore().

func (*SharedStore) DeleteLocalKey Uses

func (s *SharedStore) DeleteLocalKey(key NamedKey)

DeleteLocalKey removes a key from being synchronized with the kvstore

func (*SharedStore) Release Uses

func (s *SharedStore) Release()

Release frees all resources own by the store but leaves all keys in the kvstore intact

func (*SharedStore) SharedKeysMap Uses

func (s *SharedStore) SharedKeysMap() map[string]Key

SharedKeysMap returns a copy of the SharedKeysMap, the returned map can be safely modified but the values of the map represent the actual data stored in the internal SharedStore SharedKeys map.

func (*SharedStore) UpdateKeySync Uses

func (s *SharedStore) UpdateKeySync(key LocalKey) error

UpdateKeySync synchronously synchronizes a key with the kvstore.

func (*SharedStore) UpdateLocalKey Uses

func (s *SharedStore) UpdateLocalKey(key LocalKey)

UpdateLocalKey adds a key to be synchronized with the kvstore

func (*SharedStore) UpdateLocalKeySync Uses

func (s *SharedStore) UpdateLocalKeySync(key LocalKey) error

UpdateLocalKeySync synchronously synchronizes a local key with the kvstore and adds it to the list of local keys to be synchronized if the initial synchronous synchronization was successful

Package store imports 13 packages (graph) and is imported by 7 packages. Updated 2019-07-19. Refresh now. Tools for package owners.