rest

package
v0.0.0-...-a134451 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SchemeGroupVersion = schema.GroupVersion{Group: constant.GroupName, Version: runtime.APIVersionInternal}

SchemeGroupVersion is group version used to register these objects

Functions

func BeforeCreate

func BeforeCreate(strategy RESTCreateStrategy, ctx context.Context, obj runtime.Object) error

BeforeCreate ensures that common operations for all resources are performed on creation. It only returns errors that can be converted to api.Status. It invokes PrepareForCreate, then GenerateName, then Validate. It returns nil if the object should be created.

func BeforeDelete

func BeforeDelete(strategy RESTDeleteStrategy, ctx context.Context, obj runtime.Object, options *meta.DeleteOptions) (graceful, gracefulPending bool, err error)

BeforeDelete tests whether the object can be gracefully deleted. If graceful is set, the object should be gracefully deleted. If gracefulPending is set, the object has already been gracefully deleted (and the provided grace period is longer than the time to deletion). An error is returned if the condition cannot be checked or the gracePeriodSeconds is invalid. The options argument may be updated with default values if graceful is true. Second place where we set deletionTimestamp is pkg/registry/generic/registry/store.go. This function is responsible for setting deletionTimestamp during gracefulDeletion, other one for cascading deletions.

func BeforeUpdate

func BeforeUpdate(strategy RESTUpdateStrategy, ctx context.Context, obj, old runtime.Object) error

BeforeUpdate ensures that common operations for all resources are performed on update. It only returns errors that can be converted to api.Status. It will invoke update validation with the provided existing and updated objects. It sets zero values only if the object does not have a zero value for the respective field.

func FillObjectMetaSystemFields

func FillObjectMetaSystemFields(o meta.Object)

FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta.

func Int64

func Int64(i int64) *int64

Int64 returns a pointer to an int64.

func Kind

func Kind(kind string) schema.GroupKind

Kind takes an unqualified kind and returns a Group qualified GroupKind

func Resource

func Resource(resource string) schema.GroupResource

Resource takes an unqualified resource and returns a Group qualified GroupResource

func ValidateAllObjectFunc

func ValidateAllObjectFunc(ctx context.Context, obj runtime.Object) error

ValidateAllObjectFunc is a "admit everything" instance of ValidateObjectFunc.

func ValidateAllObjectUpdateFunc

func ValidateAllObjectUpdateFunc(ctx context.Context, obj, old runtime.Object) error

ValidateAllObjectUpdateFunc is a "admit everything" instance of ValidateObjectUpdateFunc.

func WithPrefix

func WithPrefix(path string) string

Types

type CollectionDeleter

type CollectionDeleter interface {
	// DeleteCollection selects all resources in the storage matching given 'listOptions'
	// and deletes them. To delete attempt is validated by the deleteValidation first.
	// If 'options' are provided, the resource will attempt to honor them or return an
	// invalid request error.
	// DeleteCollection may not be atomic - i.e. it may delete some objects and still
	// return an error after it. On success, returns a list of deleted objects.
	DeleteCollection(ctx context.Context, deleteValidation ValidateObjectFunc, options *meta.DeleteOptions, listOptions *meta.ListOptions) (runtime.Object, error)
}

CollectionDeleter is an object that can delete a collection of RESTful resources.

type Creater

type Creater interface {
	// New returns an empty object that can be used with Create after request data has been put into it.
	// This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object)
	New() runtime.Object

	// Create creates a new version of a resource.
	Create(ctx context.Context, obj runtime.Object, createValidation ValidateObjectFunc, options *meta.CreateOptions) (runtime.Object, error)
}

Creater is an object that can create an instance of a RESTful object.

type CreaterUpdater

type CreaterUpdater interface {
	Creater
	Update(ctx context.Context, name string, objInfo runtime.Object, createValidation ValidateObjectFunc, updateValidation ValidateObjectUpdateFunc, forceAllowCreate bool, options *meta.UpdateOptions) (runtime.Object, bool, error)
}

CreaterUpdater is a storage object that must support both create and update. Go prevents embedded interfaces that implement the same method.

type DefaultCreateStrategy

type DefaultCreateStrategy struct{}

func (DefaultCreateStrategy) PrepareForCreate

func (d DefaultCreateStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object)

func (DefaultCreateStrategy) Validate

func (d DefaultCreateStrategy) Validate(ctx context.Context, obj runtime.Object) []error

func (DefaultCreateStrategy) WarningsOnCreate

func (d DefaultCreateStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string

type DefaultRESTCanonicalize

type DefaultRESTCanonicalize struct {
}

func (DefaultRESTCanonicalize) Canonicalize

func (d DefaultRESTCanonicalize) Canonicalize(obj runtime.Object)

type DefaultRESTUpdateStrategy

type DefaultRESTUpdateStrategy struct {
}

func (DefaultRESTUpdateStrategy) AllowCreateOnUpdate

func (d DefaultRESTUpdateStrategy) AllowCreateOnUpdate() bool

func (DefaultRESTUpdateStrategy) AllowUnconditionalUpdate

func (d DefaultRESTUpdateStrategy) AllowUnconditionalUpdate() bool

func (DefaultRESTUpdateStrategy) PrepareForUpdate

func (d DefaultRESTUpdateStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object)

func (DefaultRESTUpdateStrategy) ValidateUpdate

func (d DefaultRESTUpdateStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) []error

func (DefaultRESTUpdateStrategy) WarningsOnUpdate

func (d DefaultRESTUpdateStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string

type DefaultResetFieldsStrategy

type DefaultResetFieldsStrategy struct{}

func (DefaultResetFieldsStrategy) GetResetFields

func (d DefaultResetFieldsStrategy) GetResetFields() map[string]interface{}

type Deleter

type Deleter interface {
	// Delete finds a resource in the storage and deletes it.
	// To delete attempt is validated by the deleteValidation first.
	// If options are provided, the resource will attempt to honor them or return an invalid
	// request error.
	// Although it can return an arbitrary error value, IsNotFound(err) is true for the
	// returned error value err when the specified resource is not found.
	// Delete *may* return the object that was deleted, or a status object indicating additional
	// information about deletion.
	// It also returns a boolean which is set to true if the resource was instantly
	// deleted or false if it will be deleted asynchronously.
	Delete(ctx context.Context, name string, deleteValidation ValidateObjectFunc, options *meta.DeleteOptions) (runtime.Object, bool, error)
}

Deleter knows how to pass deletion options to allow delayed deletion of a RESTful object.

type Getter

type Getter interface {
	// Get finds a resource in the storage by name and returns it.
	// Although it can return an arbitrary error value, IsNotFound(err) is true for the
	// returned error value err when the specified resource is not found.
	Get(ctx context.Context, name string, options *meta.GetOptions) (runtime.Object, error)
}

Getter is an object that can retrieve a named RESTful resource.

type Lister

type Lister interface {
	// NewList returns an empty object that can be used with the List call.
	// This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object)
	NewList() runtime.Object
	// NewListStruct return struct
	NewListStruct() interface{}
	// List selects resources in the storage which match to the selector. 'options' can be nil.
	List(ctx context.Context, options *meta.ListOptions) (runtime.Object, error)
}

Lister is an object that can retrieve resources that match the provided field and label criteria.

type Patcher

type Patcher interface {
	Getter
	Updater
}

Patcher is a storage object that supports both get and update.

type RESTCreateStrategy

type RESTCreateStrategy interface {
	runtime.ObjectTyper

	// PrepareForCreate is invoked on create before validation to normalize
	// the object.  For example: remove fields that are not to be persisted,
	// sort order-insensitive list fields, etc.  This should not remove fields
	// whose presence would be considered a validation error.
	//
	// Often implemented as a type check and an initailization or clearing of
	// status. Clear the status because status changes are internal. External
	// callers of an api (users) should not be setting an initial status on
	// newly created objects.
	PrepareForCreate(ctx context.Context, obj runtime.Object)
	// Validate returns an ErrorList with validation errors or nil.  Validate
	// is invoked after default fields in the object have been filled in
	// before the object is persisted.  This method should not mutate the
	// object.
	Validate(ctx context.Context, obj runtime.Object) []error
	// WarningsOnCreate returns warnings to the client performing a creation.
	// WarningsOnCreate is invoked after default fields in the object have been filled in
	// and after Validate has passed, before Canonicalize is called, and the object is persisted.
	// This method must not mutate the object.
	//
	// Be brief; limit warnings to 120 characters if possible.
	// Don't include a "Warning:" prefix in the message (that is added by clients on output).
	// Warnings returned about a specific field should be formatted as "path.to.field: message".
	// For example: `spec.imagePullSecrets[0].name: invalid empty name ""`
	//
	// Use warning messages to describe problems the client making the API request should correct or be aware of.
	// For example:
	// - use of deprecated fields/labels/annotations that will stop working in a future release
	// - use of obsolete fields/labels/annotations that are non-functional
	// - malformed or invalid specifications that prevent successful handling of the submitted object,
	//   but are not rejected by validation for compatibility reasons
	//
	// Warnings should not be returned for fields which cannot be resolved by the caller.
	// For example, do not warn about spec fields in a subresource creation request.
	WarningsOnCreate(ctx context.Context, obj runtime.Object) []string
	// Canonicalize allows an object to be mutated into a canonical form. This
	// ensures that code that operates on these objects can rely on the common
	// form for things like comparison.  Canonicalize is invoked after
	// validation has succeeded but before the object has been persisted.
	// This method may mutate the object. Often implemented as a type check or
	// empty method.
	Canonicalize(obj runtime.Object)
}

RESTCreateStrategy defines the minimum validation, accepted input, and name generation behavior to create an object that follows Kubernetes API conventions.

type RESTDeleteStrategy

type RESTDeleteStrategy interface {
	runtime.ObjectTyper
}

type RESTGracefulDeleteStrategy

type RESTGracefulDeleteStrategy interface {
	// CheckGracefulDelete should return true if the object can be gracefully deleted and set
	// any default values on the DeleteOptions.
	// NOTE: if return true, `options.GracePeriodSeconds` must be non-nil (nil will fail),
	// that's what tells the deletion how "graceful" to be.
	CheckGracefulDelete(ctx context.Context, obj runtime.Object, options *meta.DeleteOptions) bool
}

RESTGracefulDeleteStrategy must be implemented by the registry that supports graceful deletion.

type RESTUpdateStrategy

type RESTUpdateStrategy interface {
	runtime.ObjectTyper
	// AllowCreateOnUpdate returns true if the object can be created by a PUT.
	AllowCreateOnUpdate() bool
	// PrepareForUpdate is invoked on update before validation to normalize
	// the object.  For example: remove fields that are not to be persisted,
	// sort order-insensitive list fields, etc.  This should not remove fields
	// whose presence would be considered a validation error.
	PrepareForUpdate(ctx context.Context, obj, old runtime.Object)
	// ValidateUpdate is invoked after default fields in the object have been
	// filled in before the object is persisted.  This method should not mutate
	// the object.
	ValidateUpdate(ctx context.Context, obj, old runtime.Object) []error
	// WarningsOnUpdate returns warnings to the client performing the update.
	// WarningsOnUpdate is invoked after default fields in the object have been filled in
	// and after ValidateUpdate has passed, before Canonicalize is called, and before the object is persisted.
	// This method must not mutate either object.
	//
	// Be brief; limit warnings to 120 characters if possible.
	// Don't include a "Warning:" prefix in the message (that is added by clients on output).
	// Warnings returned about a specific field should be formatted as "path.to.field: message".
	// For example: `spec.imagePullSecrets[0].name: invalid empty name ""`
	//
	// Use warning messages to describe problems the client making the API request should correct or be aware of.
	// For example:
	// - use of deprecated fields/labels/annotations that will stop working in a future release
	// - use of obsolete fields/labels/annotations that are non-functional
	// - malformed or invalid specifications that prevent successful handling of the submitted object,
	//   but are not rejected by validation for compatibility reasons
	//
	// Warnings should not be returned for fields which cannot be resolved by the caller.
	// For example, do not warn about spec fields in a status update.
	WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string
	// Canonicalize allows an object to be mutated into a canonical form. This
	// ensures that code that operates on these objects can rely on the common
	// form for things like comparison.  Canonicalize is invoked after
	// validation has succeeded but before the object has been persisted.
	// This method may mutate the object.
	Canonicalize(obj runtime.Object)
	// AllowUnconditionalUpdate returns true if the object can be updated
	// unconditionally (irrespective of the latest resource version), when
	// there is no resource version specified in the object.
	AllowUnconditionalUpdate() bool
}

RESTUpdateStrategy defines the minimum validation, accepted input, and name generation behavior to update an object that follows Kubernetes API conventions. A resource may have many UpdateStrategies, depending on the call pattern in use.

type ResetFieldsStrategy

type ResetFieldsStrategy interface {
	GetResetFields() map[string]interface{}
}

ResetFieldsStrategy is an optional interface that a storage object can implement if it wishes to provide the fields reset by its strategies.

type StandardStorage

type StandardStorage interface {
	Getter
	Lister
	CreaterUpdater
	Deleter
	Watcher

	// Destroy cleans up its resources on shutdown.
	// Destroy has to be implemented in thread-safe way and be prepared
	// for being called more than once.
	Destroy()
}

StandardStorage is an interface covering the common verbs. Provided for testing whether a resource satisfies the normal storage methods. Use Storage when passing opaque storage objects.

type Storage

type Storage interface {
	// New returns an empty object that can be used with Create and Update after request data has been put into it.
	// This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object)
	New() runtime.Object
	// NewStruct return struct
	NewStruct() interface{}

	// Destroy cleans up its resources on shutdown.
	// Destroy has to be implemented in thread-safe way and be prepared
	// for being called more than once.
	Destroy()
}

Storage is a generic interface for RESTful storage services. Resources which are exported to the RESTful API of apiserver need to implement this interface. It is expected that objects may implement any of the below interfaces.

type StorageMetadata

type StorageMetadata interface {
	// ProducesMIMETypes returns a list of the MIME types the specified HTTP verb (GET, POST, DELETE,
	// PATCH) can respond with.
	ProducesMIMETypes(verb string) []string

	// ProducesObject returns an object the specified HTTP verb respond with. It will overwrite storage object if
	// it is not nil. Only the type of the return object matters, the value will be ignored.
	ProducesObject(verb string) interface{}
}

StorageMetadata is an optional interface that callers can implement to provide additional information about their Storage objects.

type SubResourceAction

type SubResourceAction struct {
	Verb         string               // Verb identifying the action ("GET", "POST", "WATCH", "PROXY", etc).
	SubResource  string               // The path of the action
	Params       []*restful.Parameter // List of parameters associated with the action.
	ReadSample   interface{}
	WriteSample  interface{}
	ReturnSample interface{}
}

type SubResourceRoute

type SubResourceRoute struct {
	Verb        string
	SubResource string
	Req         *restful.Request
	Resp        *restful.Response
	// contains filtered or unexported fields
}

func NewSubResourceRoute

func NewSubResourceRoute(verb string, subResource string, req *restful.Request, resp *restful.Response) *SubResourceRoute

func (*SubResourceRoute) Match

func (r *SubResourceRoute) Match(verb, subresource string, rf restful.RouteFunction)

func (*SubResourceRoute) Matched

func (r *SubResourceRoute) Matched() bool

type SubResourceStorage

type SubResourceStorage interface {
	StandardStorage

	Actions() []SubResourceAction

	Handle(verb, subresource string, req *restful.Request, resp *restful.Response)
}

type TransformFunc

type TransformFunc func(ctx context.Context, newObj runtime.Object, oldObj runtime.Object) (transformedNewObj runtime.Object, err error)

TransformFunc is a function to transform and return newObj

type UpdatedObjectInfo

type UpdatedObjectInfo interface {
	// Preconditions Returns preconditions built from the updated object, if applicable.
	// May return nil, or a preconditions object containing nil fields,
	// if no preconditions can be determined from the updated object.
	Preconditions() *meta.Preconditions

	// UpdatedObject returns the updated object, given a context and old object.
	// The only time an empty oldObj should be passed in is if a "create on update" is occurring (there is no oldObj).
	UpdatedObject(ctx context.Context, oldObj runtime.Object) (newObj runtime.Object, err error)
}

UpdatedObjectInfo provides information about an updated object to an Updater. It requires access to the old object in order to return the newly updated object.

func DefaultUpdatedObjectInfo

func DefaultUpdatedObjectInfo(obj runtime.Object, transformers ...TransformFunc) UpdatedObjectInfo

DefaultUpdatedObjectInfo returns an UpdatedObjectInfo impl based on the specified object.

type Updater

type Updater interface {
	// New returns an empty object that can be used with Update after request data has been put into it.
	// This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object)
	New() runtime.Object

	// Update finds a resource in the storage and updates it. Some implementations
	// may allow updates creates the object - they should set the created boolean
	// to true.
	Update(ctx context.Context, name string, objInfo runtime.Object, createValidation ValidateObjectFunc, updateValidation ValidateObjectUpdateFunc, forceAllowCreate bool, options *meta.UpdateOptions) (runtime.Object, bool, error)
}

Updater is an object that can update an instance of a RESTful object.

type ValidateObjectFunc

type ValidateObjectFunc func(ctx context.Context, obj runtime.Object) error

ValidateObjectFunc is a function to act on a given object. An error may be returned if the hook cannot be completed. A ValidateObjectFunc may NOT transform the provided object.

type ValidateObjectUpdateFunc

type ValidateObjectUpdateFunc func(ctx context.Context, obj, old runtime.Object) error

ValidateObjectUpdateFunc is a function to act on a given object and its predecessor. An error may be returned if the hook cannot be completed. An UpdateObjectFunc may NOT transform the provided object.

type Watcher

type Watcher interface {
	// Watch 'label' selects on labels; 'field' selects on the object's fields. Not all fields
	// are supported; an error should be returned if 'field' tries to select on a field that
	// isn't supported. 'resourceVersion' allows for continuing/starting a watch at a
	// particular version.
	Watch(ctx context.Context, options *meta.ListOptions) (watch.Interface, error)
}

Watcher should be implemented by all Storage objects that want to offer the ability to watch for changes through the watch api.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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