Documentation
¶
Overview ¶
Package etcd has a generic implementation of a registry that stores things in etcd.
Index ¶
- Constants
- func NamespaceKeyFunc(ctx genericapirequest.Context, prefix string, name string) (string, error)
- func NamespaceKeyRootFunc(ctx genericapirequest.Context, prefix string) string
- func NoNamespaceKeyFunc(ctx genericapirequest.Context, prefix string, name string) (string, error)
- func StorageWithCacher(copier runtime.ObjectCopier, storageConfig *storagebackend.Config, ...) (storage.Interface, factory.DestroyFunc)
- type ObjectFunc
- type Store
- func (e *Store) CompleteWithOptions(options *generic.StoreOptions) error
- func (e *Store) Create(ctx genericapirequest.Context, obj runtime.Object) (runtime.Object, error)
- func (e *Store) Delete(ctx genericapirequest.Context, name string, options *metav1.DeleteOptions) (runtime.Object, error)
- func (e *Store) DeleteCollection(ctx genericapirequest.Context, options *metav1.DeleteOptions, ...) (runtime.Object, error)
- func (e *Store) Export(ctx genericapirequest.Context, name string, opts metav1.ExportOptions) (runtime.Object, error)
- func (e *Store) Get(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (runtime.Object, error)
- func (e *Store) List(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (runtime.Object, error)
- func (e *Store) ListPredicate(ctx genericapirequest.Context, p storage.SelectionPredicate, ...) (runtime.Object, error)
- func (e *Store) New() runtime.Object
- func (e *Store) NewList() runtime.Object
- func (e *Store) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error)
- func (e *Store) Watch(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
- func (e *Store) WatchPredicate(ctx genericapirequest.Context, p storage.SelectionPredicate, ...) (watch.Interface, error)
Constants ¶
const DefaultWatchCacheSize = 100
defaultWatchCacheSize is the default size of a watch catch per resource in number of entries.
const OptimisticLockErrorMsg = "the object has been modified; please apply your changes to the latest version and try again"
Variables ¶
This section is empty.
Functions ¶
func NamespaceKeyFunc ¶
NamespaceKeyFunc is the default function for constructing storage paths to a resource relative to the given prefix enforcing namespace rules. If the context does not contain a namespace, it errors.
func NamespaceKeyRootFunc ¶
func NamespaceKeyRootFunc(ctx genericapirequest.Context, prefix string) string
NamespaceKeyRootFunc is the default function for constructing storage paths to resource directories enforcing namespace rules.
func NoNamespaceKeyFunc ¶
NoNamespaceKeyFunc is the default function for constructing storage paths to a resource relative to the given prefix without a namespace.
func StorageWithCacher ¶
func StorageWithCacher( copier runtime.ObjectCopier, storageConfig *storagebackend.Config, capacity int, objectType runtime.Object, resourcePrefix string, keyFunc func(obj runtime.Object) (string, error), newListFunc func() runtime.Object, getAttrsFunc storage.AttrFunc, triggerFunc storage.TriggerPublisherFunc) (storage.Interface, factory.DestroyFunc)
Creates a cacher based given storageConfig.
Types ¶
type ObjectFunc ¶
ObjectFunc is a function to act on a given object. An error may be returned if the hook cannot be completed. An ObjectFunc may transform the provided object.
type Store ¶
type Store struct { // Copier is used to make some storage caching decorators work Copier runtime.ObjectCopier // NewFunc returns a new instance of the type this registry returns for a // GET of a single object, e.g.: // // curl GET /apis/group/version/namespaces/my-ns/myresource/name-of-object NewFunc func() runtime.Object // NewListFunc returns a new list of the type this registry; it is the // type returned when the resource is listed, e.g.: // // curl GET /apis/group/version/namespaces/my-ns/myresource NewListFunc func() runtime.Object // QualifiedResource is the pluralized name of the resource. QualifiedResource schema.GroupResource // KeyRootFunc returns the root etcd key for this resource; should not // include trailing "/". This is used for operations that work on the // entire collection (listing and watching). // // KeyRootFunc and KeyFunc must be supplied together or not at all. KeyRootFunc func(ctx genericapirequest.Context) string // KeyFunc returns the key for a specific object in the collection. // KeyFund is dalled for Create/Update/Get/Delete. Note that 'namespace' // can be gotten from ctx. // // KeyFunc and KeyRootFunc must be supplied together or not at all. KeyFunc func(ctx genericapirequest.Context, name string) (string, error) // ObjectNameFunc returns the name of an object or an error. ObjectNameFunc func(obj runtime.Object) (string, error) // TTLFunc returns the TTL (time to live) that objects should be persisted // with. The existing parameter is the current TTL or the default for this // operation. The update parameter indicates whether this is an operation // against an existing object. // // Objects that are persisted with a TTL are evicted once the TTL expires. TTLFunc func(obj runtime.Object, existing uint64, update bool) (uint64, error) // PredicateFunc returns a matcher corresponding to the provided labels // and fields. The SelectionPredicate returned should return true if the // object matches the given field and label selectors. PredicateFunc func(label labels.Selector, field fields.Selector) storage.SelectionPredicate // EnableGarbageCollection affects the handling of Update and Delete // requests. Enabling garbage collection allows finalizers to do work to // finalize this object before the store deletes it. // // If any store has garbage collection enabled, it must also be enabled in // the kube-controller-manager. EnableGarbageCollection bool // DeleteCollectionWorkers is the maximum number of workers in a single // DeleteCollection call. Delete requests for the items in a collection // are issued in parallel. DeleteCollectionWorkers int // Decorator is an optional exit hook on an object returned from the // underlying storage. The returned object could be an individual object // (e.g. Pod) or a list type (e.g. PodList). Decorator is intended for // integrations that are above storage and should only be used for // specific cases where storage of the value is not appropriate, since // they cannot be watched. Decorator ObjectFunc // CreateStrategy implements resource-specific behavior during creation. CreateStrategy rest.RESTCreateStrategy // AfterCreate implements a further operation to run after a resource is // created and before it is decorated, optional. AfterCreate ObjectFunc // UpdateStrategy implements resource-specific behavior during updates. UpdateStrategy rest.RESTUpdateStrategy // AfterUpdate implements a further operation to run after a resource is // updated and before it is decorated, optional. AfterUpdate ObjectFunc // DeleteStrategy implements resource-specific behavior during deletion, // optional. DeleteStrategy rest.RESTDeleteStrategy // AfterDelete implements a further operation to run after a resource is // deleted and before it is decorated, optional. AfterDelete ObjectFunc // ReturnDeletedObject determines whether the Store returns the object // that was deleted. Otherwise, return a generic success status response. ReturnDeletedObject bool // ExportStrategy implements resource-specific behavior during export, // optional. Exported objects are not decorated. ExportStrategy rest.RESTExportStrategy // Storage is the interface for the underlying storage for the resource. Storage storage.Interface // Called to cleanup clients used by the underlying Storage; optional. DestroyFunc func() // Maximum size of the watch history cached in memory, in number of entries. // A zero value here means that a default is used. This value is ignored if // Storage is non-nil. WatchCacheSize int }
Store implements pkg/api/rest.StandardStorage. It's intended to be embeddable and allows the consumer to implement any non-generic functions that are required. This object is intended to be copyable so that it can be used in different ways but share the same underlying behavior.
All fields are required unless specified.
The intended use of this type is embedding within a Kind specific RESTStorage implementation. This type provides CRUD semantics on a Kubelike resource, handling details like conflict detection with ResourceVersion and semantics. The RESTCreateStrategy, RESTUpdateStrategy, and RESTDeleteStrategy are generic across all backends, and encapsulate logic specific to the API.
TODO: make the default exposed methods exactly match a generic RESTStorage
func (*Store) CompleteWithOptions ¶
func (e *Store) CompleteWithOptions(options *generic.StoreOptions) error
CompleteWithOptions updates the store with the provided options and defaults common fields.
func (*Store) Delete ¶
func (e *Store) Delete(ctx genericapirequest.Context, name string, options *metav1.DeleteOptions) (runtime.Object, error)
Delete removes the item from storage.
func (*Store) DeleteCollection ¶
func (e *Store) DeleteCollection(ctx genericapirequest.Context, options *metav1.DeleteOptions, listOptions *metainternalversion.ListOptions) (runtime.Object, error)
DeleteCollection removes all items returned by List with a given ListOptions from storage.
DeleteCollection is currently NOT atomic. It can happen that only subset of objects will be deleted from storage, and then an error will be returned. In case of success, the list of deleted objects will be returned.
TODO: Currently, there is no easy way to remove 'directory' entry from storage (if we are removing all objects of a given type) with the current API (it's technically possibly with storage API, but watch is not delivered correctly then). It will be possible to fix it with v3 etcd API.
func (*Store) Export ¶
func (e *Store) Export(ctx genericapirequest.Context, name string, opts metav1.ExportOptions) (runtime.Object, error)
Export implements the rest.Exporter interface
func (*Store) Get ¶
func (e *Store) Get(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (runtime.Object, error)
Get retrieves the item from storage.
func (*Store) List ¶
func (e *Store) List(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (runtime.Object, error)
List returns a list of items matching labels and field according to the store's PredicateFunc.
func (*Store) ListPredicate ¶
func (e *Store) ListPredicate(ctx genericapirequest.Context, p storage.SelectionPredicate, options *metainternalversion.ListOptions) (runtime.Object, error)
ListPredicate returns a list of all the items matching the given SelectionPredicate.
func (*Store) Update ¶
func (e *Store) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error)
Update performs an atomic update and set of the object. Returns the result of the update or an error. If the registry allows create-on-update, the create flow will be executed. A bool is returned along with the object and any errors, to indicate object creation.
func (*Store) Watch ¶
func (e *Store) Watch(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
Watch makes a matcher for the given label and field, and calls WatchPredicate. If possible, you should customize PredicateFunc to produce a matcher that matches by key. SelectionPredicate does this for you automatically.
func (*Store) WatchPredicate ¶
func (e *Store) WatchPredicate(ctx genericapirequest.Context, p storage.SelectionPredicate, resourceVersion string) (watch.Interface, error)
WatchPredicate starts a watch for the items that m matches.