Documentation
¶
Overview ¶
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 ¶
- type Configuration
- type Key
- type KeyCreator
- type LocalKey
- type NamedKey
- type Observer
- type SharedStore
- func (s *SharedStore) Close(ctx context.Context)
- func (s *SharedStore) DeleteLocalKey(ctx context.Context, key NamedKey)
- func (s *SharedStore) NumEntries() int
- func (s *SharedStore) Release()
- func (s *SharedStore) SharedKeysMap() map[string]Key
- func (s *SharedStore) UpdateKeySync(ctx context.Context, key LocalKey, lease bool) error
- func (s *SharedStore) UpdateLocalKeySync(ctx context.Context, key LocalKey) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Configuration ¶
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 // handled. This parameter is optional SharedKeyDeleteDelay *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 Context context.Context }
Configuration is the set of configuration parameters of a shared store.
type Key ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (s *SharedStore) Close(ctx context.Context)
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 ¶
func (s *SharedStore) DeleteLocalKey(ctx context.Context, key NamedKey)
DeleteLocalKey removes a key from being synchronized with the kvstore
func (*SharedStore) NumEntries ¶
func (s *SharedStore) NumEntries() int
NumEntries returns the number of entries in the store
func (*SharedStore) Release ¶
func (s *SharedStore) Release()
Release frees all resources own by the store but leaves all keys in the kvstore intact
func (*SharedStore) SharedKeysMap ¶
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 ¶
UpdateKeySync synchronously synchronizes a key with the kvstore.
func (*SharedStore) UpdateLocalKeySync ¶
func (s *SharedStore) UpdateLocalKeySync(ctx context.Context, 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