Documentation ¶
Overview ¶
Package kv implements a low-level key/value store backed by Kubernetes config maps. It supports main operations expected from key/value store such as Put, Get, Delete and List. Operations are protected by an internal mutex and therefore can be safely used inside a single node application. Basics There are only few things worth to know: key/value database is created based on bucket name so in order to have multiple configMaps - use different bucket names. Teardown() function will remove configMap entry completely destroying all entries. Caveats Since k8s-kv is based on configMaps which are in turn based on Etcd key/value store - all values have a limitation of 1MB so each bucket in k8s-kv is limited to that size. To overcome it - create more buckets. If you have multi-node application that is frequently reading/writing to the same buckets - be aware of race conditions as it doesn't provide any cross-node locking capabilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotFound = errors.New("not found")
)
errors
Functions ¶
This section is empty.
Types ¶
type ConfigMapInterface ¶
type ConfigMapInterface interface { Get(name string, options meta_v1.GetOptions) (*v1.ConfigMap, error) Create(cfgMap *v1.ConfigMap) (*v1.ConfigMap, error) Update(cfgMap *v1.ConfigMap) (*v1.ConfigMap, error) Delete(name string, options *meta_v1.DeleteOptions) error }
ConfigMapInterface implements a subset of Kubernetes original ConfigMapInterface to provide required operations for k8s-kv. Main purpose of this interface is to enable easier testing.
type GobSerializer ¶
type GobSerializer struct{}
GobSerializer - gob based serializer
func (*GobSerializer) Decode ¶
func (s *GobSerializer) Decode(data []byte, target interface{}) error
Decode - decodes given bytes into target struct
func (*GobSerializer) Encode ¶
func (s *GobSerializer) Encode(source interface{}) ([]byte, error)
Encode - encodes source into bytes using Gob encoder
type KV ¶
type KV struct {
// contains filtered or unexported fields
}
KV provides access to key/value store operations such as Put, Get, Delete, List. Entry in ConfigMap is created based on bucket name and total size is limited to 1MB per bucket. Operations are protected by an internal mutex so it's safe to use in a single node application.
func New ¶
func New(implementer ConfigMapInterface, app, bucket string) (*KV, error)
New creates a new instance of KV. Requires prepared ConfigMapInterface (provided by go-client), app and bucket names. App name is used as a label to make it easier to distinguish different k8s-kv instances created by separate (or the same) application. Bucket name is used to give a name to config map.
func (*KV) Get ¶
Get retrieves value from the key/value store bucket or returns ErrNotFound error if it was not found.
type KVDB ¶
type KVDB interface { Put(key string, value []byte) error Get(key string) (value []byte, err error) Delete(key string) error List(prefix string) (data map[string][]byte, err error) Teardown() error }
KVDB generic kv package interface
type Serializer ¶
type Serializer interface { Encode(source interface{}) ([]byte, error) Decode(data []byte, target interface{}) error }
Serializer - generic serializer interface
func DefaultSerializer ¶
func DefaultSerializer() Serializer
DefaultSerializer - returns default serializer