Documentation
¶
Overview ¶
Package rest defines common logic around changes to Kubernetes resources.
Index ¶
- Variables
- func BeforeCreate(strategy RESTCreateStrategy, ctx api.Context, obj runtime.Object) error
- func BeforeDelete(strategy RESTDeleteStrategy, ctx api.Context, obj runtime.Object, ...) (graceful, gracefulPending bool, err error)
- func BeforeUpdate(strategy RESTUpdateStrategy, ctx api.Context, obj, old runtime.Object) error
- func CheckGeneratedNameError(strategy RESTCreateStrategy, err error, obj runtime.Object) error
- type ConnectRequest
- type Connecter
- type Creater
- type CreaterUpdater
- type Deleter
- type Getter
- type GetterWithOptions
- type GracefulDeleteAdapter
- type GracefulDeleter
- type Lister
- type NamedCreater
- type ObjectFunc
- type Patcher
- type RESTCreateStrategy
- type RESTDeleteStrategy
- type RESTUpdateStrategy
- type Redirector
- type ResourceStreamer
- type Responder
- type StandardStorage
- type Storage
- type StorageMetadata
- type Updater
- type Watcher
Constants ¶
This section is empty.
Variables ¶
var Services = svcStrategy{api.Scheme, api.SimpleNameGenerator}
Services is the default logic that applies when creating and updating Service objects.
Functions ¶
func BeforeCreate ¶
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 ¶ added in v0.14.0
func BeforeDelete(strategy RESTDeleteStrategy, ctx api.Context, obj runtime.Object, options *api.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), and 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.
func BeforeUpdate ¶ added in v0.12.0
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.
func CheckGeneratedNameError ¶
func CheckGeneratedNameError(strategy RESTCreateStrategy, err error, obj runtime.Object) error
CheckGeneratedNameError checks whether an error that occurred creating a resource is due to generation being unable to pick a valid name.
Types ¶
type ConnectRequest ¶ added in v0.18.0
type ConnectRequest struct { // Name is the name of the object on which the connect request was made Name string // Options is the options object passed to the connect request. See the NewConnectOptions method on Connecter Options runtime.Object // ResourcePath is the path for the resource in the REST server (ie. "pods/proxy") ResourcePath string }
ConnectRequest is an object passed to admission control for Connect operations
func (*ConnectRequest) IsAnAPIObject ¶ added in v0.18.0
func (*ConnectRequest) IsAnAPIObject()
IsAnAPIObject makes ConnectRequest a runtime.Object
type Connecter ¶ added in v0.16.1
type Connecter interface { // Connect returns an http.Handler that will handle the request/response for a given API invocation. // The provided responder may be used for common API responses. The responder will write both status // code and body, so the ServeHTTP method should exit after invoking the responder. The Handler will // be used for a single API request and then discarded. The Responder is guaranteed to write to the // same http.ResponseWriter passed to ServeHTTP. Connect(ctx api.Context, id string, options runtime.Object, r Responder) (http.Handler, error) // NewConnectOptions returns an empty options object that will be used to pass // options to the Connect method. If nil, then a nil options object is passed to // Connect. It may return a bool and a string. If true, the value of the request // path below the object will be included as the named string in the serialization // of the runtime object. NewConnectOptions() (runtime.Object, bool, string) // ConnectMethods returns the list of HTTP methods handled by Connect ConnectMethods() []string }
Connecter is a storage object that responds to a connection request.
type Creater ¶ added in v0.14.0
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 api.Context, obj runtime.Object) (runtime.Object, error) }
Creater is an object that can create an instance of a RESTful object.
type CreaterUpdater ¶ added in v0.14.0
type CreaterUpdater interface { Creater Update(ctx api.Context, obj runtime.Object) (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 Deleter ¶ added in v0.14.0
type Deleter interface { // Delete finds a resource in the storage and deletes 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. // Delete *may* return the object that was deleted, or a status object indicating additional // information about deletion. Delete(ctx api.Context, name string) (runtime.Object, error) }
Deleter is an object that can delete a named RESTful resource.
type Getter ¶ added in v0.14.0
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 api.Context, name string) (runtime.Object, error) }
Getter is an object that can retrieve a named RESTful resource.
type GetterWithOptions ¶ added in v0.15.0
type GetterWithOptions 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. // The options object passed to it is of the same type returned by the NewGetOptions // method. Get(ctx api.Context, name string, options runtime.Object) (runtime.Object, error) // NewGetOptions returns an empty options object that will be used to pass // options to the Get method. It may return a bool and a string, if true, the // value of the request path below the object will be included as the named // string in the serialization of the runtime object. E.g., returning "path" // will convert the trailing request scheme value to "path" in the map[string][]string // passed to the convertor. NewGetOptions() (runtime.Object, bool, string) }
GetterWithOptions is an object that retrieve a named RESTful resource and takes additional options on the get request. It allows a caller to also receive the subpath of the GET request.
type GracefulDeleteAdapter ¶ added in v0.14.0
type GracefulDeleteAdapter struct {
Deleter
}
GracefulDeleteAdapter adapts the Deleter interface to GracefulDeleter
type GracefulDeleter ¶ added in v0.14.0
type GracefulDeleter interface { // Delete finds a resource in the storage and deletes it. // 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. Delete(ctx api.Context, name string, options *api.DeleteOptions) (runtime.Object, error) }
GracefulDeleter knows how to pass deletion options to allow delayed deletion of a RESTful object.
type Lister ¶ added in v0.14.0
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 // List selects resources in the storage which match to the selector. List(ctx api.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) }
Lister is an object that can retrieve resources that match the provided field and label criteria.
type NamedCreater ¶ added in v0.17.0
type NamedCreater 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. It expects a name parameter from the path. // This is needed for create operations on subresources which include the name of the parent // resource in the path. Create(ctx api.Context, name string, obj runtime.Object) (runtime.Object, error) }
NamedCreater is an object that can create an instance of a RESTful object using a name parameter.
type ObjectFunc ¶ added in v0.12.0
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.
func AllFuncs ¶ added in v0.12.0
func AllFuncs(fns ...ObjectFunc) ObjectFunc
AllFuncs returns an ObjectFunc that attempts to run all of the provided functions in order, returning early if there are any errors.
type RESTCreateStrategy ¶
type RESTCreateStrategy interface { runtime.ObjectTyper // The name generate is used when the standard GenerateName field is set. // The NameGenerator will be invoked prior to validation. api.NameGenerator // NamespaceScoped returns true if the object must be within a namespace. NamespaceScoped() bool // 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. PrepareForCreate(obj runtime.Object) // Validate is invoked after default fields in the object have been filled in before // the object is persisted. Validate(ctx api.Context, obj runtime.Object) fielderrors.ValidationErrorList }
RESTCreateStrategy defines the minimum validation, accepted input, and name generation behavior to create an object that follows Kubernetes API conventions.
type RESTDeleteStrategy ¶ added in v0.14.0
type RESTDeleteStrategy interface { runtime.ObjectTyper // CheckGracefulDelete should return true if the object can be gracefully deleted and set // any default values on the DeleteOptions. CheckGracefulDelete(obj runtime.Object, options *api.DeleteOptions) bool }
RESTDeleteStrategy defines deletion behavior on an object that follows Kubernetes API conventions.
type RESTUpdateStrategy ¶ added in v0.12.0
type RESTUpdateStrategy interface { runtime.ObjectTyper // NamespaceScoped returns true if the object must be within a namespace. NamespaceScoped() bool // 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. PrepareForUpdate(obj, old runtime.Object) // ValidateUpdate is invoked after default fields in the object have been filled in before // the object is persisted. ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList // 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 Redirector ¶ added in v0.14.0
type Redirector interface { // ResourceLocation should return the remote location of the given resource, and an optional transport to use to request it, or an error. ResourceLocation(ctx api.Context, id string) (remoteLocation *url.URL, transport http.RoundTripper, err error) }
Redirector know how to return a remote resource's location.
type ResourceStreamer ¶ added in v0.14.0
type ResourceStreamer interface { // InputStream should return an io.ReadCloser if the provided object supports streaming. The desired // api version and a accept header (may be empty) are passed to the call. If no error occurs, // the caller may return a flag indicating whether the result should be flushed as writes occur // and a content type string that indicates the type of the stream. // If a null stream is returned, a StatusNoContent response wil be generated. InputStream(apiVersion, acceptHeader string) (stream io.ReadCloser, flush bool, mimeType string, err error) }
ResourceStreamer is an interface implemented by objects that prefer to be streamed from the server instead of decoded directly.
type Responder ¶ added in v1.2.0
type Responder interface { // Object writes the provided object to the response. Invoking this method multiple times is undefined. Object(statusCode int, obj runtime.Object) // Error writes the provided error to the response. This method may only be invoked once. Error(err error) }
Responder abstracts the normal response behavior for a REST method and is passed to callers that may wish to handle the response directly in some cases, but delegate to the normal error or object behavior in other cases.
type StandardStorage ¶ added in v0.14.0
type StandardStorage interface { Getter Lister CreaterUpdater GracefulDeleter Watcher }
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 ¶ added in v0.14.0
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 }
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 ¶ added in v0.14.0
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 }
StorageMetadata is an optional interface that callers can implement to provide additional information about their Storage objects.
type Updater ¶ added in v0.14.0
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 api.Context, obj runtime.Object) (runtime.Object, bool, error) }
Updater is an object that can update an instance of a RESTful object.
type Watcher ¶ added in v0.14.0
type Watcher interface { // '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 api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (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.