registry

package
v1.3.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2016 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package etcd has a generic implementation of a registry that stores things in etcd.

Index

Constants

View Source
const OptimisticLockErrorMsg = "the object has been modified; please apply your changes to the latest version and try again"

Variables

View Source
var EnableGarbageCollector bool

EnableGarbageCollector affects the handling of Update and Delete requests. It must be synced with the corresponding flag in kube-controller-manager.

Functions

func NamespaceKeyFunc

func NamespaceKeyFunc(ctx api.Context, prefix string, name string) (string, error)

NamespaceKeyFunc is the default function for constructing storage paths to a resource relative to prefix enforcing namespace rules. If no namespace is on context, it errors.

func NamespaceKeyRootFunc

func NamespaceKeyRootFunc(ctx api.Context, prefix string) string

NamespaceKeyRootFunc is the default function for constructing storage paths to resource directories enforcing namespace rules.

func NoNamespaceKeyFunc

func NoNamespaceKeyFunc(ctx api.Context, prefix string, name string) (string, error)

NoNamespaceKeyFunc is the default function for constructing storage paths to a resource relative to prefix without a namespace

func StorageWithCacher

func StorageWithCacher(
	storageInterface storage.Interface,
	capacity int,
	objectType runtime.Object,
	resourcePrefix string,
	scopeStrategy rest.NamespaceScopedStrategy,
	newListFunc func() runtime.Object) storage.Interface

Creates a cacher on top of the given 'storageInterface'.

Types

type Store

type Store struct {
	// Called to make a new object, should return e.g., &api.Pod{}
	NewFunc func() runtime.Object

	// Called to make a new listing object, should return e.g., &api.PodList{}
	NewListFunc func() runtime.Object

	// Used for error reporting
	QualifiedResource unversioned.GroupResource

	// Used for listing/watching; should not include trailing "/"
	KeyRootFunc func(ctx api.Context) string

	// Called for Create/Update/Get/Delete. Note that 'namespace' can be
	// gotten from ctx.
	KeyFunc func(ctx api.Context, name string) (string, error)

	// Called to get the name of an object
	ObjectNameFunc func(obj runtime.Object) (string, error)

	// Return the TTL objects should be persisted with. Update is true if this
	// is an operation against an existing object. Existing is the current TTL
	// or the default for this operation.
	TTLFunc func(obj runtime.Object, existing uint64, update bool) (uint64, error)

	// Returns a matcher corresponding to the provided labels and fields.
	PredicateFunc func(label labels.Selector, field fields.Selector) generic.Matcher

	// DeleteCollectionWorkers is the maximum number of workers in a single
	// DeleteCollection call.
	DeleteCollectionWorkers int

	// Called on all objects returned from the underlying store, after
	// the exit hooks are invoked. Decorators are 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 rest.ObjectFunc
	// Allows extended behavior during creation, required
	CreateStrategy rest.RESTCreateStrategy
	// On create of an object, attempt to run a further operation.
	AfterCreate rest.ObjectFunc
	// Allows extended behavior during updates, required
	UpdateStrategy rest.RESTUpdateStrategy
	// On update of an object, attempt to run a further operation.
	AfterUpdate rest.ObjectFunc
	// Allows extended behavior during updates, optional
	DeleteStrategy rest.RESTDeleteStrategy
	// On deletion of an object, attempt to run a further operation.
	AfterDelete rest.ObjectFunc
	// If true, return the object that was deleted. Otherwise, return a generic
	// success status response.
	ReturnDeletedObject bool
	// Allows extended behavior during export, optional
	ExportStrategy rest.RESTExportStrategy

	// Used for all storage access functions
	Storage storage.Interface
}

Store implements generic.Registry. It's intended to be embeddable, so that you can implement any non-generic functions if needed. You must supply a value for every field below before use; these are left public as it's meant to be overridable if need be. This object is intended to be copyable so that it can be used in different ways but share the same underlying behavior.

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 and RESTUpdateStrategy 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) Create

func (e *Store) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error)

Create inserts a new item according to the unique key from the object.

func (*Store) Delete

func (e *Store) Delete(ctx api.Context, name string, options *api.DeleteOptions) (runtime.Object, error)

Delete removes the item from storage.

func (*Store) DeleteCollection

func (e *Store) DeleteCollection(ctx api.Context, options *api.DeleteOptions, listOptions *api.ListOptions) (runtime.Object, error)

DeleteCollection remove 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 api.Context, name string, opts unversioned.ExportOptions) (runtime.Object, error)

Implements the rest.Exporter interface

func (*Store) Get

func (e *Store) Get(ctx api.Context, name string) (runtime.Object, error)

Get retrieves the item from storage.

func (*Store) List

func (e *Store) List(ctx api.Context, options *api.ListOptions) (runtime.Object, error)

List returns a list of items matching labels and field

func (*Store) ListPredicate

func (e *Store) ListPredicate(ctx api.Context, m generic.Matcher, options *api.ListOptions) (runtime.Object, error)

ListPredicate returns a list of all the items matching m.

func (*Store) New

func (e *Store) New() runtime.Object

New implements RESTStorage

func (*Store) NewList

func (e *Store) NewList() runtime.Object

NewList implements RESTLister

func (*Store) Update

func (e *Store) Update(ctx api.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 api.Context, options *api.ListOptions) (watch.Interface, error)

Watch makes a matcher for the given label and field, and calls WatchPredicate. If possible, you should customize PredicateFunc to produre a matcher that matches by key. generic.SelectionPredicate does this for you automatically.

func (*Store) WatchPredicate

func (e *Store) WatchPredicate(ctx api.Context, m generic.Matcher, resourceVersion string) (watch.Interface, error)

WatchPredicate starts a watch for the items that m matches.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL