Documentation ¶
Overview ¶
Interfaces for database-related operations.
Index ¶
- Constants
- func EverythingFunc(runtime.Object) bool
- func IsInternalError(err error) bool
- func IsInvalidError(err error) bool
- func IsInvalidObj(err error) bool
- func IsNodeExist(err error) bool
- func IsNotFound(err error) bool
- func IsTestFailed(err error) bool
- func IsUnreachable(err error) bool
- func NamespaceKeyFunc(prefix string, obj runtime.Object) (string, error)
- func NoNamespaceKeyFunc(prefix string, obj runtime.Object) (string, error)
- func ParseListResourceVersion(resourceVersion string) (uint64, error)
- func ParseWatchResourceVersion(resourceVersion string) (uint64, error)
- type Cacher
- func (c *Cacher) Create(ctx context.Context, key string, obj, out runtime.Object, ttl uint64) error
- func (c *Cacher) Delete(ctx context.Context, key string, out runtime.Object, ...) error
- func (c *Cacher) Get(ctx context.Context, key string, objPtr runtime.Object, ignoreNotFound bool) error
- func (c *Cacher) GetToList(ctx context.Context, key string, filter Filter, listObj runtime.Object) error
- func (c *Cacher) GuaranteedUpdate(ctx context.Context, key string, ptrToType runtime.Object, ignoreNotFound bool, ...) error
- func (c *Cacher) LastSyncResourceVersion() (uint64, error)
- func (c *Cacher) List(ctx context.Context, key string, resourceVersion string, filter Filter, ...) error
- func (c *Cacher) Stop()
- func (c *Cacher) Versioner() Versioner
- func (c *Cacher) Watch(ctx context.Context, key string, resourceVersion string, filter Filter) (watch.Interface, error)
- func (c *Cacher) WatchList(ctx context.Context, key string, resourceVersion string, filter Filter) (watch.Interface, error)
- type CacherConfig
- type Filter
- type Interface
- type InternalError
- type InvalidError
- type MatchValue
- type Preconditions
- type ResponseMeta
- type SimpleFilter
- type SimpleUpdateFunc
- type StorageError
- func NewInvalidObjError(key, msg string) *StorageError
- func NewKeyExistsError(key string, rv int64) *StorageError
- func NewKeyNotFoundError(key string, rv int64) *StorageError
- func NewResourceVersionConflictsError(key string, rv int64) *StorageError
- func NewUnreachableError(key string, rv int64) *StorageError
- type TriggerPublisherFunc
- type UpdateFunc
- type Versioner
Constants ¶
const ( ErrCodeKeyNotFound int = iota + 1 ErrCodeKeyExists ErrCodeResourceVersionConflicts ErrCodeInvalidObj ErrCodeUnreachable )
const ( // MaximumListWait determines how long we're willing to wait for a // list if a client specified a resource version in the future. MaximumListWait = 60 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func EverythingFunc ¶ added in v1.4.2
func IsInternalError ¶ added in v1.3.0
IsInternalError returns true if and only if err is an InternalError.
func IsInvalidError ¶ added in v1.3.0
IsInvalidError returns true if and only if err is an InvalidError.
func IsInvalidObj ¶ added in v1.3.0
IsInvalidObj returns true if and only if err is invalid error
func IsNodeExist ¶
IsNodeExist returns true if and only if err is an node already exist error.
func IsNotFound ¶
IsNotFound returns true if and only if err is "key" not found error.
func IsTestFailed ¶
IsTestFailed returns true if and only if err is a write conflict.
func IsUnreachable ¶
IsUnreachable returns true if and only if err indicates the server could not be reached.
func NoNamespaceKeyFunc ¶
func ParseListResourceVersion ¶
ParseListResourceVersion takes a resource version argument and converts it to the etcd version.
func ParseWatchResourceVersion ¶
ParseWatchResourceVersion takes a resource version argument and converts it to the etcd version we should pass to helper.Watch(). Because resourceVersion is an opaque value, the default watch behavior for non-zero watch is to watch the next value (if you pass "1", you will see updates from "2" onwards).
Types ¶
type Cacher ¶
Cacher is responsible for serving WATCH and LIST requests for a given resource from its internal cache and updating its cache in the background based on the underlying storage contents. Cacher implements storage.Interface (although most of the calls are just delegated to the underlying storage).
func NewCacherFromConfig ¶
func NewCacherFromConfig(config CacherConfig) *Cacher
Create a new Cacher responsible from service WATCH and LIST requests from its internal cache and updating its cache in the background based on the given configuration.
func (*Cacher) Delete ¶
func (c *Cacher) Delete(ctx context.Context, key string, out runtime.Object, preconditions *Preconditions) error
Implements storage.Interface.
func (*Cacher) Get ¶
func (c *Cacher) Get(ctx context.Context, key string, objPtr runtime.Object, ignoreNotFound bool) error
Implements storage.Interface.
func (*Cacher) GetToList ¶
func (c *Cacher) GetToList(ctx context.Context, key string, filter Filter, listObj runtime.Object) error
Implements storage.Interface.
func (*Cacher) GuaranteedUpdate ¶
func (c *Cacher) GuaranteedUpdate(ctx context.Context, key string, ptrToType runtime.Object, ignoreNotFound bool, preconditions *Preconditions, tryUpdate UpdateFunc) error
Implements storage.Interface.
func (*Cacher) LastSyncResourceVersion ¶
Returns resource version to which the underlying cache is synced.
func (*Cacher) List ¶
func (c *Cacher) List(ctx context.Context, key string, resourceVersion string, filter Filter, listObj runtime.Object) error
Implements storage.Interface.
type CacherConfig ¶
type CacherConfig struct { // Maximum size of the history cached in memory. CacheCapacity int // An underlying storage.Interface. Storage Interface // An underlying storage.Versioner. Versioner Versioner // The Cache will be caching objects of a given Type and assumes that they // are all stored under ResourcePrefix directory in the underlying database. Type interface{} ResourcePrefix string // KeyFunc is used to get a key in the underyling storage for a given object. KeyFunc func(runtime.Object) (string, error) // TriggerPublisherFunc is used for optimizing amount of watchers that // needs to process an incoming event. TriggerPublisherFunc TriggerPublisherFunc // NewList is a function that creates new empty object storing a list of // objects of type Type. NewListFunc func() runtime.Object Codec runtime.Codec }
CacherConfig contains the configuration for a given Cache.
type Filter ¶ added in v1.4.2
type Filter interface { // Filter is a predicate which takes an API object and returns true // if and only if the object should remain in the set. Filter(obj runtime.Object) bool // For any triggers known to the Filter, if Filter() can return only // (a subset of) objects for which indexing function returns <value>, // (<index name>, <value> pair would be returned. // // This is optimization to avoid computing Filter() function (which are // usually relatively expensive) in case we are sure they will return // false anyway. Trigger() []MatchValue }
Filter is interface that is used to pass filtering mechanism.
var Everything Filter = everything{}
Everything is a Filter which accepts all objects.
func NewSimpleFilter ¶ added in v1.4.2
func NewSimpleFilter( filterFunc func(runtime.Object) bool, triggerFunc func() []MatchValue) Filter
type Interface ¶
type Interface interface { // Returns Versioner associated with this interface. Versioner() Versioner // Create adds a new object at a key unless it already exists. 'ttl' is time-to-live // in seconds (0 means forever). If no error is returned and out is not nil, out will be // set to the read value from database. Create(ctx context.Context, key string, obj, out runtime.Object, ttl uint64) error // Delete removes the specified key and returns the value that existed at that spot. // If key didn't exist, it will return NotFound storage error. Delete(ctx context.Context, key string, out runtime.Object, preconditions *Preconditions) error // Watch begins watching the specified key. Events are decoded into API objects, // and any items passing 'filter' are sent down to returned watch.Interface. // resourceVersion may be used to specify what version to begin watching, // which should be the current resourceVersion, and no longer rv+1 // (e.g. reconnecting without missing any updates). Watch(ctx context.Context, key string, resourceVersion string, filter Filter) (watch.Interface, error) // WatchList begins watching the specified key's items. Items are decoded into API // objects and any item passing 'filter' are sent down to returned watch.Interface. // resourceVersion may be used to specify what version to begin watching, // which should be the current resourceVersion, and no longer rv+1 // (e.g. reconnecting without missing any updates). WatchList(ctx context.Context, key string, resourceVersion string, filter Filter) (watch.Interface, error) // Get unmarshals json found at key into objPtr. On a not found error, will either // return a zero object of the requested type, or an error, depending on ignoreNotFound. // Treats empty responses and nil response nodes exactly like a not found error. Get(ctx context.Context, key string, objPtr runtime.Object, ignoreNotFound bool) error // GetToList unmarshals json found at key and opaque it into *List api object // (an object that satisfies the runtime.IsList definition). GetToList(ctx context.Context, key string, filter Filter, listObj runtime.Object) error // List unmarshalls jsons found at directory defined by key and opaque them // into *List api object (an object that satisfies runtime.IsList definition). // The returned contents may be delayed, but it is guaranteed that they will // be have at least 'resourceVersion'. List(ctx context.Context, key string, resourceVersion string, filter Filter, listObj runtime.Object) error // GuaranteedUpdate keeps calling 'tryUpdate()' to update key 'key' (of type 'ptrToType') // retrying the update until success if there is index conflict. // Note that object passed to tryUpdate may change across invocations of tryUpdate() if // other writers are simultaneously updating it, so tryUpdate() needs to take into account // the current contents of the object when deciding how the update object should look. // If the key doesn't exist, it will return NotFound storage error if ignoreNotFound=false // or zero value in 'ptrToType' parameter otherwise. // If the object to update has the same value as previous, it won't do any update // but will return the object in 'ptrToType' parameter. // // Example: // // s := /* implementation of Interface */ // err := s.GuaranteedUpdate( // "myKey", &MyType{}, true, // func(input runtime.Object, res ResponseMeta) (runtime.Object, *uint64, error) { // // Before each incovation of the user defined function, "input" is reset to // // current contents for "myKey" in database. // curr := input.(*MyType) // Guaranteed to succeed. // // // Make the modification // curr.Counter++ // // // Return the modified object - return an error to stop iterating. Return // // a uint64 to alter the TTL on the object, or nil to keep it the same value. // return cur, nil, nil // } // }) GuaranteedUpdate(ctx context.Context, key string, ptrToType runtime.Object, ignoreNotFound bool, precondtions *Preconditions, tryUpdate UpdateFunc) error }
Interface offers a common interface for object marshaling/unmarshaling operations and hides all the storage-related operations behind it.
type InternalError ¶ added in v1.3.0
type InternalError struct {
Reason string
}
InternalError is generated when an error occurs in the storage package, i.e., not from the underlying storage backend (e.g., etcd).
func NewInternalError ¶ added in v1.3.0
func NewInternalError(reason string) InternalError
func NewInternalErrorf ¶ added in v1.3.0
func NewInternalErrorf(format string, a ...interface{}) InternalError
func (InternalError) Error ¶ added in v1.3.0
func (e InternalError) Error() string
type InvalidError ¶ added in v1.3.0
InvalidError is generated when an error caused by invalid API object occurs in the storage package.
func NewInvalidError ¶ added in v1.3.0
func NewInvalidError(errors field.ErrorList) InvalidError
func (InvalidError) Error ¶ added in v1.3.0
func (e InvalidError) Error() string
type MatchValue ¶ added in v1.4.2
MatchValue defines a pair (<index name>, <value for that index>).
func NoTriggerFunc ¶ added in v1.4.2
func NoTriggerFunc() []MatchValue
func NoTriggerPublisher ¶ added in v1.4.2
func NoTriggerPublisher(runtime.Object) []MatchValue
type Preconditions ¶ added in v1.3.0
Preconditions must be fulfilled before an operation (update, delete, etc.) is carried out.
func NewUIDPreconditions ¶ added in v1.3.0
func NewUIDPreconditions(uid string) *Preconditions
NewUIDPreconditions returns a Preconditions with UID set.
type ResponseMeta ¶
type ResponseMeta struct { // TTL is the time to live of the node that contained the returned object. It may be // zero or negative in some cases (objects may be expired after the requested // expiration time due to server lag). TTL int64 // The resource version of the node that contained the returned object. ResourceVersion uint64 }
ResponseMeta contains information about the database metadata that is associated with an object. It abstracts the actual underlying objects to prevent coupling with concrete database and to improve testability.
type SimpleFilter ¶ added in v1.4.2
type SimpleFilter struct {
// contains filtered or unexported fields
}
SimpleFilter implements Filter interface.
func (*SimpleFilter) Filter ¶ added in v1.4.2
func (s *SimpleFilter) Filter(obj runtime.Object) bool
func (*SimpleFilter) Trigger ¶ added in v1.4.2
func (s *SimpleFilter) Trigger() []MatchValue
type StorageError ¶ added in v1.3.0
func NewInvalidObjError ¶ added in v1.3.0
func NewInvalidObjError(key, msg string) *StorageError
func NewKeyExistsError ¶ added in v1.3.0
func NewKeyExistsError(key string, rv int64) *StorageError
func NewKeyNotFoundError ¶ added in v1.3.0
func NewKeyNotFoundError(key string, rv int64) *StorageError
func NewResourceVersionConflictsError ¶ added in v1.3.0
func NewResourceVersionConflictsError(key string, rv int64) *StorageError
func NewUnreachableError ¶ added in v1.3.0
func NewUnreachableError(key string, rv int64) *StorageError
func (*StorageError) Error ¶ added in v1.3.0
func (e *StorageError) Error() string
type TriggerPublisherFunc ¶ added in v1.4.2
type TriggerPublisherFunc func(obj runtime.Object) []MatchValue
TriggerPublisherFunc is a function that takes an object, and returns a list of pairs (<index name>, <index value for the given object>) for all indexes known to that function.
type UpdateFunc ¶
type UpdateFunc func(input runtime.Object, res ResponseMeta) (output runtime.Object, ttl *uint64, err error)
Pass an UpdateFunc to Interface.GuaranteedUpdate to make an update that is guaranteed to succeed. See the comment for GuaranteedUpdate for more details.
func SimpleUpdate ¶
func SimpleUpdate(fn SimpleUpdateFunc) UpdateFunc
SimpleUpdateFunc converts SimpleUpdateFunc into UpdateFunc
type Versioner ¶
type Versioner interface { // UpdateObject sets storage metadata into an API object. Returns an error if the object // cannot be updated correctly. May return nil if the requested object does not need metadata // from database. UpdateObject(obj runtime.Object, resourceVersion uint64) error // UpdateList sets the resource version into an API list object. Returns an error if the object // cannot be updated correctly. May return nil if the requested object does not need metadata // from database. UpdateList(obj runtime.Object, resourceVersion uint64) error // ObjectResourceVersion returns the resource version (for persistence) of the specified object. // Should return an error if the specified object does not have a persistable version. ObjectResourceVersion(obj runtime.Object) (uint64, error) }
Versioner abstracts setting and retrieving metadata fields from database response onto the object ot list.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
util
Package util holds generic etcd-related utility functions that any user of ectd might want to use, without pulling in kubernetes-specific code.
|
Package util holds generic etcd-related utility functions that any user of ectd might want to use, without pulling in kubernetes-specific code. |