2014-07-29 21:35:46 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
package rest
|
2014-07-29 21:35:46 +00:00
|
|
|
|
|
|
|
import (
|
2015-03-22 03:25:38 +00:00
|
|
|
"io"
|
2015-03-23 18:42:39 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
|
2014-09-26 15:46:04 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
2015-03-06 23:29:03 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
2014-07-29 21:35:46 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
2014-09-06 02:22:03 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
2014-07-29 21:35:46 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
|
|
|
)
|
|
|
|
|
2015-04-06 16:58:00 +00:00
|
|
|
// Storage is a generic interface for RESTful storage services.
|
2015-01-12 05:33:25 +00:00
|
|
|
// Resources which are exported to the RESTful API of apiserver need to implement this interface. It is expected
|
2015-03-21 16:24:16 +00:00
|
|
|
// that objects may implement any of the below interfaces.
|
|
|
|
type Storage interface {
|
2014-08-06 03:10:48 +00:00
|
|
|
// New returns an empty object that can be used with Create and Update after request data has been put into it.
|
2014-09-06 02:22:03 +00:00
|
|
|
// This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object)
|
|
|
|
New() runtime.Object
|
2015-01-12 05:33:25 +00:00
|
|
|
}
|
2014-08-06 03:10:48 +00:00
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// Lister is an object that can retrieve resources that match the provided field and label criteria.
|
|
|
|
type Lister interface {
|
2015-01-12 05:33:25 +00:00
|
|
|
// 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
|
2014-07-29 21:35:46 +00:00
|
|
|
// List selects resources in the storage which match to the selector.
|
2015-03-06 23:29:03 +00:00
|
|
|
List(ctx api.Context, label labels.Selector, field fields.Selector) (runtime.Object, error)
|
2015-01-12 05:33:25 +00:00
|
|
|
}
|
2014-07-29 21:35:46 +00:00
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// Getter is an object that can retrieve a named RESTful resource.
|
|
|
|
type Getter interface {
|
|
|
|
// Get finds a resource in the storage by name and returns it.
|
2014-08-06 21:55:37 +00:00
|
|
|
// 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.
|
2015-03-21 16:24:16 +00:00
|
|
|
Get(ctx api.Context, name string) (runtime.Object, error)
|
2015-01-12 05:33:25 +00:00
|
|
|
}
|
2014-07-29 21:35:46 +00:00
|
|
|
|
2015-04-06 16:58:00 +00:00
|
|
|
// GetterWithOptions is an object that retrieve a named RESTful resource and takes
|
|
|
|
// additional options on the get request
|
|
|
|
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.
|
|
|
|
NewGetOptions() runtime.Object
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// Deleter is an object that can delete a named RESTful resource.
|
|
|
|
type Deleter interface {
|
2014-07-29 21:35:46 +00:00
|
|
|
// Delete finds a resource in the storage and deletes it.
|
2014-08-06 21:55:37 +00:00
|
|
|
// 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.
|
2015-02-10 14:26:26 +00:00
|
|
|
// Delete *may* return the object that was deleted, or a status object indicating additional
|
|
|
|
// information about deletion.
|
2015-03-21 16:24:16 +00:00
|
|
|
Delete(ctx api.Context, name string) (runtime.Object, error)
|
2015-01-12 05:33:25 +00:00
|
|
|
}
|
2014-07-29 21:35:46 +00:00
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// GracefulDeleter knows how to pass deletion options to allow delayed deletion of a
|
|
|
|
// RESTful object.
|
|
|
|
type GracefulDeleter interface {
|
2015-03-05 03:34:31 +00:00
|
|
|
// 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.
|
2015-03-21 16:24:16 +00:00
|
|
|
Delete(ctx api.Context, name string, options *api.DeleteOptions) (runtime.Object, error)
|
2015-03-05 03:34:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// GracefulDeleteAdapter adapts the Deleter interface to GracefulDeleter
|
2015-03-05 03:34:31 +00:00
|
|
|
type GracefulDeleteAdapter struct {
|
2015-03-21 16:24:16 +00:00
|
|
|
Deleter
|
2015-03-05 03:34:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// Delete implements RESTGracefulDeleter in terms of Deleter
|
|
|
|
func (w GracefulDeleteAdapter) Delete(ctx api.Context, name string, options *api.DeleteOptions) (runtime.Object, error) {
|
|
|
|
return w.Deleter.Delete(ctx, name)
|
2015-03-05 03:34:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// Creater is an object that can create an instance of a RESTful object.
|
|
|
|
type Creater interface {
|
2015-02-09 14:47:13 +00:00
|
|
|
// 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
|
|
|
|
|
2014-10-24 17:16:02 +00:00
|
|
|
// Create creates a new version of a resource.
|
2015-02-10 14:26:26 +00:00
|
|
|
Create(ctx api.Context, obj runtime.Object) (runtime.Object, error)
|
2015-01-12 05:33:25 +00:00
|
|
|
}
|
2014-10-24 17:16:02 +00:00
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// Updater is an object that can update an instance of a RESTful object.
|
|
|
|
type Updater interface {
|
2015-02-09 14:47:13 +00:00
|
|
|
// 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
|
|
|
|
|
2014-10-24 17:16:02 +00:00
|
|
|
// Update finds a resource in the storage and updates it. Some implementations
|
2015-02-10 14:26:26 +00:00
|
|
|
// 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)
|
2014-10-24 17:16:02 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// CreaterUpdater is a storage object that must support both create and update.
|
|
|
|
// Go prevents embedded interfaces that implement the same method.
|
|
|
|
type CreaterUpdater interface {
|
|
|
|
Creater
|
|
|
|
Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error)
|
2015-02-21 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// CreaterUpdater must satisfy the Updater interface.
|
|
|
|
var _ Updater = CreaterUpdater(nil)
|
2014-10-24 17:16:02 +00:00
|
|
|
|
2015-04-06 16:58:00 +00:00
|
|
|
// Patcher is a storage object that supports both get and update.
|
2015-03-21 16:24:16 +00:00
|
|
|
type Patcher interface {
|
|
|
|
Getter
|
|
|
|
Updater
|
2014-07-29 21:35:46 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// Watcher should be implemented by all Storage objects that
|
2014-07-29 21:35:46 +00:00
|
|
|
// want to offer the ability to watch for changes through the watch api.
|
2015-03-21 16:24:16 +00:00
|
|
|
type Watcher interface {
|
2014-08-06 21:55:37 +00:00
|
|
|
// '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.
|
2015-03-06 23:29:03 +00:00
|
|
|
Watch(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
|
2014-07-29 21:35:46 +00:00
|
|
|
}
|
2014-08-25 21:36:15 +00:00
|
|
|
|
2015-03-21 16:24:16 +00:00
|
|
|
// 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 StandardStorage interface {
|
|
|
|
Getter
|
|
|
|
Lister
|
|
|
|
CreaterUpdater
|
|
|
|
GracefulDeleter
|
|
|
|
Watcher
|
|
|
|
}
|
|
|
|
|
2014-09-02 10:00:28 +00:00
|
|
|
// Redirector know how to return a remote resource's location.
|
2014-08-25 21:36:15 +00:00
|
|
|
type Redirector interface {
|
2015-03-23 18:42:39 +00:00
|
|
|
// 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)
|
2014-08-25 21:36:15 +00:00
|
|
|
}
|
2015-03-22 03:25:38 +00:00
|
|
|
|
|
|
|
// ResourceStreamer is an interface implemented by objects that prefer to be streamed from the server
|
|
|
|
// instead of decoded directly.
|
|
|
|
type ResourceStreamer interface {
|
2015-04-06 16:58:00 +00:00
|
|
|
// InputStream should return an io.ReadCloser if the provided object supports streaming. The desired
|
2015-03-22 03:25:38 +00:00
|
|
|
// api version and a accept header (may be empty) are passed to the call. If no error occurs,
|
2015-04-06 16:58:00 +00:00
|
|
|
// 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)
|
2015-03-22 03:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StorageMetadata is an optional interface that callers can implement to provide additional
|
|
|
|
// information about their Storage objects.
|
|
|
|
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
|
|
|
|
}
|