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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package apiserver
|
|
|
|
|
|
|
|
import (
|
2014-09-26 15:46:04 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
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"
|
|
|
|
)
|
|
|
|
|
2014-09-02 10:00:28 +00:00
|
|
|
// RESTStorage 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
|
|
|
|
// that objects may implement any of the REST* interfaces.
|
|
|
|
// TODO: implement dynamic introspection (so GenericREST objects can indicate what they implement)
|
2014-07-29 21:35:46 +00:00
|
|
|
type RESTStorage 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-01-12 05:33:25 +00:00
|
|
|
type RESTLister 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
|
2014-07-29 21:35:46 +00:00
|
|
|
// List selects resources in the storage which match to the selector.
|
2014-09-26 15:46:04 +00:00
|
|
|
List(ctx api.Context, label, field labels.Selector) (runtime.Object, error)
|
2015-01-12 05:33:25 +00:00
|
|
|
}
|
2014-07-29 21:35:46 +00:00
|
|
|
|
2015-01-12 05:33:25 +00:00
|
|
|
type RESTGetter interface {
|
2014-07-29 21:35:46 +00:00
|
|
|
// Get finds a resource in the storage by id 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.
|
2014-09-26 15:46:04 +00:00
|
|
|
Get(ctx api.Context, id string) (runtime.Object, error)
|
2015-01-12 05:33:25 +00:00
|
|
|
}
|
2014-07-29 21:35:46 +00:00
|
|
|
|
2015-01-12 05:33:25 +00:00
|
|
|
type RESTDeleter 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.
|
|
|
|
Delete(ctx api.Context, id string) (runtime.Object, error)
|
2015-01-12 05:33:25 +00:00
|
|
|
}
|
2014-07-29 21:35:46 +00:00
|
|
|
|
2015-01-12 05:33:25 +00:00
|
|
|
type RESTCreater 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-01-12 05:33:25 +00:00
|
|
|
type RESTUpdater 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
|
|
|
}
|
|
|
|
|
|
|
|
// RESTResult indicates the result of a REST transformation.
|
|
|
|
type RESTResult struct {
|
|
|
|
// The result of this operation. May be nil if the operation has no meaningful
|
|
|
|
// result (like Delete)
|
|
|
|
runtime.Object
|
|
|
|
|
|
|
|
// May be set true to indicate that the Update operation resulted in the object
|
|
|
|
// being created.
|
|
|
|
Created bool
|
2014-07-29 21:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ResourceWatcher should be implemented by all RESTStorage objects that
|
|
|
|
// want to offer the ability to watch for changes through the watch api.
|
|
|
|
type ResourceWatcher 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.
|
2014-10-07 20:51:28 +00:00
|
|
|
Watch(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error)
|
2014-07-29 21:35:46 +00:00
|
|
|
}
|
2014-08-25 21:36:15 +00:00
|
|
|
|
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 {
|
|
|
|
// ResourceLocation should return the remote location of the given resource, or an error.
|
2014-09-26 15:46:04 +00:00
|
|
|
ResourceLocation(ctx api.Context, id string) (remoteLocation string, err error)
|
2014-08-25 21:36:15 +00:00
|
|
|
}
|