v0.30.3 Latest Latest

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

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 40 Imported by: 3,246



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



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


This section is empty.


func NamespaceKeyFunc

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

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 context.Context, prefix string) string

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

func NoNamespaceKeyFunc

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

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

func ShouldDeleteDuringUpdate

func ShouldDeleteDuringUpdate(ctx context.Context, key string, obj, existing runtime.Object) bool

ShouldDeleteDuringUpdate is the default function for checking if an object should be deleted during an update. It checks if the new object has no finalizers, the existing object's deletionTimestamp is set, and the existing object's deletionGracePeriodSeconds is 0 or nil

func StorageWithCacher

func StorageWithCacher() generic.StorageDecorator

Creates a cacher based given storageConfig.


type AfterCreateFunc added in v0.21.0

type AfterCreateFunc func(obj runtime.Object, options *metav1.CreateOptions)

AfterCreateFunc is the type used for the Store.AfterCreate hook.

type AfterDeleteFunc added in v0.21.0

type AfterDeleteFunc func(obj runtime.Object, options *metav1.DeleteOptions)

AfterDeleteFunc is the type used for the Store.AfterDelete hook.

type AfterUpdateFunc added in v0.21.0

type AfterUpdateFunc func(obj runtime.Object, options *metav1.UpdateOptions)

AfterUpdateFunc is the type used for the Store.AfterUpdate hook.

type BeginCreateFunc added in v0.21.0

type BeginCreateFunc func(ctx context.Context, obj runtime.Object, options *metav1.CreateOptions) (FinishFunc, error)

BeginCreateFunc is the type used for the Store.BeginCreate hook.

type BeginUpdateFunc added in v0.21.0

type BeginUpdateFunc func(ctx context.Context, obj, old runtime.Object, options *metav1.UpdateOptions) (FinishFunc, error)

BeginUpdateFunc is the type used for the Store.BeginUpdate hook.

type DryRunnableStorage

type DryRunnableStorage struct {
	Storage storage.Interface
	Codec   runtime.Codec

func (*DryRunnableStorage) Count

func (s *DryRunnableStorage) Count(key string) (int64, error)

func (*DryRunnableStorage) Create

func (s *DryRunnableStorage) Create(ctx context.Context, key string, obj, out runtime.Object, ttl uint64, dryRun bool) error

func (*DryRunnableStorage) Delete

func (s *DryRunnableStorage) Delete(ctx context.Context, key string, out runtime.Object, preconditions *storage.Preconditions, deleteValidation storage.ValidateObjectFunc, dryRun bool, cachedExistingObject runtime.Object) error

func (*DryRunnableStorage) Get

func (*DryRunnableStorage) GetList added in v0.24.0

func (s *DryRunnableStorage) GetList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error

func (*DryRunnableStorage) GuaranteedUpdate

func (s *DryRunnableStorage) GuaranteedUpdate(
	ctx context.Context, key string, destination runtime.Object, ignoreNotFound bool,
	preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, dryRun bool, cachedExistingObject runtime.Object) error

func (*DryRunnableStorage) Versioner

func (s *DryRunnableStorage) Versioner() storage.Versioner

func (*DryRunnableStorage) Watch

type FinishFunc added in v0.21.0

type FinishFunc func(ctx context.Context, success bool)

FinishFunc is a function returned by Begin hooks to complete an operation.

type GenericStore

type GenericStore interface {
	GetCreateStrategy() rest.RESTCreateStrategy
	GetUpdateStrategy() rest.RESTUpdateStrategy
	GetDeleteStrategy() rest.RESTDeleteStrategy

GenericStore interface can be used for type assertions when we need to access the underlying strategies.

type Store

type Store struct {
	// 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

	// DefaultQualifiedResource is the pluralized name of the resource.
	// This field is used if there is no request info present in the context.
	// See qualifiedResourceFromContext for details.
	DefaultQualifiedResource schema.GroupResource

	// SingularQualifiedResource is the singular name of the resource.
	SingularQualifiedResource 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 context.Context) string

	// KeyFunc returns the key for a specific object in the collection.
	// KeyFunc is called 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 context.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 func(runtime.Object)

	// CreateStrategy implements resource-specific behavior during creation.
	CreateStrategy rest.RESTCreateStrategy
	// BeginCreate is an optional hook that returns a "transaction-like"
	// commit/revert function which will be called at the end of the operation,
	// but before AfterCreate and Decorator, indicating via the argument
	// whether the operation succeeded.  If this returns an error, the function
	// is not called.  Almost nobody should use this hook.
	BeginCreate BeginCreateFunc
	// AfterCreate implements a further operation to run after a resource is
	// created and before it is decorated, optional.
	AfterCreate AfterCreateFunc

	// UpdateStrategy implements resource-specific behavior during updates.
	UpdateStrategy rest.RESTUpdateStrategy
	// BeginUpdate is an optional hook that returns a "transaction-like"
	// commit/revert function which will be called at the end of the operation,
	// but before AfterUpdate and Decorator, indicating via the argument
	// whether the operation succeeded.  If this returns an error, the function
	// is not called.  Almost nobody should use this hook.
	BeginUpdate BeginUpdateFunc
	// AfterUpdate implements a further operation to run after a resource is
	// updated and before it is decorated, optional.
	AfterUpdate AfterUpdateFunc

	// DeleteStrategy implements resource-specific behavior during deletion.
	DeleteStrategy rest.RESTDeleteStrategy
	// AfterDelete implements a further operation to run after a resource is
	// deleted and before it is decorated, optional.
	AfterDelete AfterDeleteFunc
	// ReturnDeletedObject determines whether the Store returns the object
	// that was deleted. Otherwise, return a generic success status response.
	ReturnDeletedObject bool
	// ShouldDeleteDuringUpdate is an optional function to determine whether
	// an update from existing to obj should result in a delete.
	// If specified, this is checked in addition to standard finalizer,
	// deletionTimestamp, and deletionGracePeriodSeconds checks.
	ShouldDeleteDuringUpdate func(ctx context.Context, key string, obj, existing runtime.Object) bool

	// TableConvertor is an optional interface for transforming items or lists
	// of items into tabular output. If unset, the default will be used.
	TableConvertor rest.TableConvertor

	// ResetFieldsStrategy provides the fields reset by the strategy that
	// should not be modified by the user.
	ResetFieldsStrategy rest.ResetFieldsStrategy

	// Storage is the interface for the underlying storage for the
	// resource. It is wrapped into a "DryRunnableStorage" that will
	// either pass-through or simply dry-run.
	Storage DryRunnableStorage
	// StorageVersioner outputs the <group/version/kind> an object will be
	// converted to before persisted in etcd, given a list of possible
	// kinds of the object.
	// If the StorageVersioner is nil, apiserver will leave the
	// storageVersionHash as empty in the discovery document.
	StorageVersioner runtime.GroupVersioner

	// DestroyFunc cleans up clients used by the underlying Storage; optional.
	// If set, DestroyFunc has to be implemented in thread-safe way and
	// be prepared for being called more than once.
	DestroyFunc func()

Store implements 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) ConvertToTable

func (e *Store) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error)

func (*Store) Create

func (e *Store) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error)

Create inserts a new item according to the unique key from the object. Note that registries may mutate the input object (e.g. in the strategy hooks). Tests which call this might want to call DeepCopy if they expect to be able to examine the input and output objects for differences.

func (*Store) Delete

func (e *Store) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions) (runtime.Object, bool, error)

Delete removes the item from storage. options can be mutated by rest.BeforeDelete due to a graceful deletion strategy.

func (*Store) DeleteCollection

func (e *Store) DeleteCollection(ctx context.Context, deleteValidation rest.ValidateObjectFunc, 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.

func (*Store) DeleteReturnsDeletedObject added in v0.18.0

func (e *Store) DeleteReturnsDeletedObject() bool

DeleteReturnsDeletedObject implements the rest.MayReturnFullObjectDeleter interface

func (*Store) Destroy added in v0.25.0

func (e *Store) Destroy()

Destroy cleans up its resources on shutdown.

func (*Store) Get

func (e *Store) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error)

Get retrieves the item from storage.

func (*Store) GetCreateStrategy

func (e *Store) GetCreateStrategy() rest.RESTCreateStrategy

GetCreateStrategy implements GenericStore.

func (*Store) GetDeleteStrategy

func (e *Store) GetDeleteStrategy() rest.RESTDeleteStrategy

GetDeleteStrategy implements GenericStore.

func (*Store) GetResetFields added in v0.21.0

func (e *Store) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set

GetResetFields implements rest.ResetFieldsStrategy

func (*Store) GetSingularName added in v0.27.0

func (e *Store) GetSingularName() string

func (*Store) GetUpdateStrategy

func (e *Store) GetUpdateStrategy() rest.RESTUpdateStrategy

GetUpdateStrategy implements GenericStore.

func (*Store) List

List returns a list of items matching labels and field according to the store's PredicateFunc.

func (*Store) ListPredicate

ListPredicate returns a list of all the items matching the given SelectionPredicate.

func (*Store) NamespaceScoped

func (e *Store) NamespaceScoped() bool

NamespaceScoped indicates whether the resource is namespaced

func (*Store) New

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

New implements RESTStorage.New.

func (*Store) NewList

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

NewList implements rest.Lister.

func (*Store) StorageVersion

func (e *Store) StorageVersion() runtime.GroupVersioner

func (*Store) Update

func (e *Store) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (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

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 context.Context, p storage.SelectionPredicate, resourceVersion string, sendInitialEvents *bool) (watch.Interface, error)

WatchPredicate starts a watch for the items that matches.

Jump to

Keyboard shortcuts

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