rest

package
v0.0.0-...-1692a82 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 16 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 Validate. It returns nil if the object should be created.

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 EnsureObjectNamespaceMatchesRequestNamespace

func EnsureObjectNamespaceMatchesRequestNamespace(requestNamespace string, obj metav1.Object) error

EnsureObjectNamespaceMatchesRequestNamespace returns an error if obj.Namespace and requestNamespace are both populated and do not match. If either is unpopulated, it modifies obj as needed to ensure obj.GetNamespace() == requestNamespace.

func ExpectedNamespaceForScope

func ExpectedNamespaceForScope(requestNamespace string, namespaceScoped bool) string

ExpectedNamespaceForScope returns the expected namespace for a resource, given the request namespace and resource scope.

func FinishNothing

func FinishNothing(context.Context, bool)

FinishNothing is a do-nothing FinishFunc.

Types

type FinishFunc

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

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

type RESTCreateStrategy

type RESTCreateStrategy interface {
	runtime.ObjectTyper
	// The name generator is used when the standard GenerateName field is set.
	// The NameGenerator will be invoked prior to validation.
	names.NameGenerator

	// NamespaceScoped returns true if the object must be within a namespace.
	NamespaceScoped() bool
	// BeginCreate is an optional hook that can be used to indicate the method is supported
	BeginCreate(ctx context.Context) error

	// 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) field.ErrorList
	// WarningsOnCreate returns warnings to the client performing a create.
	// 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)

	Create(ctx context.Context, key types.NamespacedName, obj runtime.Object, dryrun bool) error
}

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

	// BeginDelete is an optional hook that can be used to indicate the method is supported
	BeginDelete(ctx context.Context) error

	Delete(ctx context.Context, key types.NamespacedName, obj runtime.Object, dryrun bool) error
}

RESTDeleteStrategy defines deletion behavior on an object that follows Kubernetes API conventions.

type RESTGetStrategy

type RESTGetStrategy interface {
	Get(ctx context.Context, key types.NamespacedName) (runtime.Object, error)
}

type RESTListStrategy

type RESTListStrategy interface {
	List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error)
}

type RESTUpdateStrategy

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
	// BeginUpdate is an optional hook that can be used to indicate the method is supported
	BeginUpdate(ctx context.Context) error

	// 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) field.ErrorList
	// 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

	Update(ctx context.Context, key types.NamespacedName, obj, old runtime.Object, dryrun bool) (runtime.Object, error)
}

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 RESTWatchStrategy

type RESTWatchStrategy interface {
	runtime.ObjectTyper

	// BeginWatch is an optional hook that can be used to indicate the method is supported
	BeginWatch(ctx context.Context) error

	Watch(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
}

RESWatchStrategy defines watch behavior on an object that follows Kubernetes API conventions.

Jump to

Keyboard shortcuts

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