mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
Update to use api.Context
This commit is contained in:
parent
b8d95ad01f
commit
ee19ba186d
@ -20,7 +20,12 @@ import (
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
// NewContext instantiates a base context object for request flows
|
||||
func NewContext() context.Context {
|
||||
return context.Background()
|
||||
// Context carries values across API boundaries.
|
||||
type Context interface {
|
||||
Value(key interface{}) interface{}
|
||||
}
|
||||
|
||||
// NewContext instantiates a base context object for request flows
|
||||
func NewContext() Context {
|
||||
return context.TODO()
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
apierrs "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
@ -89,18 +88,18 @@ type SimpleRESTStorage struct {
|
||||
injectedFunction func(obj runtime.Object) (returnObj runtime.Object, err error)
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) List(ctx context.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
result := &SimpleList{
|
||||
Items: storage.list,
|
||||
}
|
||||
return result, storage.errors["list"]
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Get(ctx context.Context, id string) (runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Get(ctx api.Context, id string) (runtime.Object, error) {
|
||||
return api.Scheme.CopyOrDie(&storage.item), storage.errors["get"]
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Delete(ctx context.Context, id string) (<-chan runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Delete(ctx api.Context, id string) (<-chan runtime.Object, error) {
|
||||
storage.deleted = id
|
||||
if err := storage.errors["delete"]; err != nil {
|
||||
return nil, err
|
||||
@ -117,7 +116,7 @@ func (storage *SimpleRESTStorage) New() runtime.Object {
|
||||
return &Simple{}
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
storage.created = obj.(*Simple)
|
||||
if err := storage.errors["create"]; err != nil {
|
||||
return nil, err
|
||||
@ -130,7 +129,7 @@ func (storage *SimpleRESTStorage) Create(ctx context.Context, obj runtime.Object
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Update(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
storage.updated = obj.(*Simple)
|
||||
if err := storage.errors["update"]; err != nil {
|
||||
return nil, err
|
||||
@ -144,7 +143,7 @@ func (storage *SimpleRESTStorage) Update(ctx context.Context, obj runtime.Object
|
||||
}
|
||||
|
||||
// Implement ResourceWatcher.
|
||||
func (storage *SimpleRESTStorage) Watch(ctx context.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
func (storage *SimpleRESTStorage) Watch(ctx api.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
storage.requestedLabelSelector = label
|
||||
storage.requestedFieldSelector = field
|
||||
storage.requestedResourceVersion = resourceVersion
|
||||
@ -156,7 +155,7 @@ func (storage *SimpleRESTStorage) Watch(ctx context.Context, label, field labels
|
||||
}
|
||||
|
||||
// Implement Redirector.
|
||||
func (storage *SimpleRESTStorage) ResourceLocation(ctx context.Context, id string) (string, error) {
|
||||
func (storage *SimpleRESTStorage) ResourceLocation(ctx api.Context, id string) (string, error) {
|
||||
storage.requestedResourceLocationID = id
|
||||
if err := storage.errors["resourceLocation"]; err != nil {
|
||||
return "", err
|
||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||
package apiserver
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.net/context"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
@ -31,20 +31,20 @@ type RESTStorage interface {
|
||||
New() runtime.Object
|
||||
|
||||
// List selects resources in the storage which match to the selector.
|
||||
List(ctx context.Context, label, field labels.Selector) (runtime.Object, error)
|
||||
List(ctx api.Context, label, field labels.Selector) (runtime.Object, error)
|
||||
|
||||
// Get finds a resource in the storage by id 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, id string) (runtime.Object, error)
|
||||
Get(ctx api.Context, id string) (runtime.Object, error)
|
||||
|
||||
// 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(ctx context.Context, id string) (<-chan runtime.Object, error)
|
||||
Delete(ctx api.Context, id string) (<-chan runtime.Object, error)
|
||||
|
||||
Create(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error)
|
||||
Update(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error)
|
||||
Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error)
|
||||
Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error)
|
||||
}
|
||||
|
||||
// ResourceWatcher should be implemented by all RESTStorage objects that
|
||||
@ -54,11 +54,11 @@ type ResourceWatcher interface {
|
||||
// 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, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
|
||||
Watch(ctx api.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
|
||||
}
|
||||
|
||||
// Redirector know how to return a remote resource's location.
|
||||
type Redirector interface {
|
||||
// ResourceLocation should return the remote location of the given resource, or an error.
|
||||
ResourceLocation(ctx context.Context, id string) (remoteLocation string, err error)
|
||||
ResourceLocation(ctx api.Context, id string) (remoteLocation string, err error)
|
||||
}
|
||||
|
@ -19,8 +19,6 @@ package master
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
@ -74,7 +72,7 @@ func (p *PodCache) updatePodInfo(host, id string) error {
|
||||
|
||||
// UpdateAllContainers updates information about all containers. Either called by Loop() below, or one-off.
|
||||
func (p *PodCache) UpdateAllContainers() {
|
||||
var ctx context.Context
|
||||
var ctx api.Context
|
||||
pods, err := p.pods.ListPods(ctx, labels.Everything())
|
||||
if err != nil {
|
||||
glog.Errorf("Error synchronizing container list: %v", err)
|
||||
|
@ -19,8 +19,6 @@ package binding
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
@ -43,17 +41,17 @@ func NewREST(bindingRegistry Registry) *REST {
|
||||
}
|
||||
|
||||
// List returns an error because bindings are write-only objects.
|
||||
func (*REST) List(ctx context.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
func (*REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
return nil, errors.NewNotFound("binding", "list")
|
||||
}
|
||||
|
||||
// Get returns an error because bindings are write-only objects.
|
||||
func (*REST) Get(ctx context.Context, id string) (runtime.Object, error) {
|
||||
func (*REST) Get(ctx api.Context, id string) (runtime.Object, error) {
|
||||
return nil, errors.NewNotFound("binding", id)
|
||||
}
|
||||
|
||||
// Delete returns an error because bindings are write-only objects.
|
||||
func (*REST) Delete(ctx context.Context, id string) (<-chan runtime.Object, error) {
|
||||
func (*REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error) {
|
||||
return nil, errors.NewNotFound("binding", id)
|
||||
}
|
||||
|
||||
@ -63,7 +61,7 @@ func (*REST) New() runtime.Object {
|
||||
}
|
||||
|
||||
// Create attempts to make the assignment indicated by the binding it recieves.
|
||||
func (b *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (b *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
binding, ok := obj.(*api.Binding)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("incorrect type: %#v", obj)
|
||||
@ -77,6 +75,6 @@ func (b *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.O
|
||||
}
|
||||
|
||||
// Update returns an error-- this object may not be updated.
|
||||
func (b *REST) Update(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (b *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
return nil, fmt.Errorf("Bindings may not be changed.")
|
||||
}
|
||||
|
@ -22,8 +22,6 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
@ -54,7 +52,7 @@ func TestNewREST(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRESTUnsupported(t *testing.T) {
|
||||
var ctx context.Context
|
||||
var ctx api.Context
|
||||
mockRegistry := MockRegistry{
|
||||
OnApplyBinding: func(b *api.Binding) error { return nil },
|
||||
}
|
||||
|
@ -30,12 +30,11 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
|
||||
"code.google.com/p/go-uuid/uuid"
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
// PodLister is anything that knows how to list pods.
|
||||
type PodLister interface {
|
||||
ListPods(ctx context.Context, labels labels.Selector) (*api.PodList, error)
|
||||
ListPods(ctx api.Context, labels labels.Selector) (*api.PodList, error)
|
||||
}
|
||||
|
||||
// REST implements apiserver.RESTStorage for the replication controller service.
|
||||
@ -55,7 +54,7 @@ func NewREST(registry Registry, podLister PodLister) *REST {
|
||||
}
|
||||
|
||||
// Create registers the given ReplicationController.
|
||||
func (rs *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
controller, ok := obj.(*api.ReplicationController)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("not a replication controller: %#v", obj)
|
||||
@ -81,14 +80,14 @@ func (rs *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.
|
||||
}
|
||||
|
||||
// Delete asynchronously deletes the ReplicationController specified by its id.
|
||||
func (rs *REST) Delete(ctx context.Context, id string) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error) {
|
||||
return apiserver.MakeAsync(func() (runtime.Object, error) {
|
||||
return &api.Status{Status: api.StatusSuccess}, rs.registry.DeleteController(id)
|
||||
}), nil
|
||||
}
|
||||
|
||||
// Get obtains the ReplicationController specified by its id.
|
||||
func (rs *REST) Get(ctx context.Context, id string) (runtime.Object, error) {
|
||||
func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
|
||||
controller, err := rs.registry.GetController(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -98,7 +97,7 @@ func (rs *REST) Get(ctx context.Context, id string) (runtime.Object, error) {
|
||||
}
|
||||
|
||||
// List obtains a list of ReplicationControllers that match selector.
|
||||
func (rs *REST) List(ctx context.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
if !field.Empty() {
|
||||
return nil, fmt.Errorf("field selector not supported yet")
|
||||
}
|
||||
@ -124,7 +123,7 @@ func (*REST) New() runtime.Object {
|
||||
|
||||
// Update replaces a given ReplicationController instance with an existing
|
||||
// instance in storage.registry.
|
||||
func (rs *REST) Update(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
controller, ok := obj.(*api.ReplicationController)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("not a replication controller: %#v", obj)
|
||||
@ -143,7 +142,7 @@ func (rs *REST) Update(ctx context.Context, obj runtime.Object) (<-chan runtime.
|
||||
|
||||
// Watch returns ReplicationController events via a watch.Interface.
|
||||
// It implements apiserver.ResourceWatcher.
|
||||
func (rs *REST) Watch(ctx context.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
func (rs *REST) Watch(ctx api.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
if !field.Empty() {
|
||||
return nil, fmt.Errorf("no field selector implemented for controllers")
|
||||
}
|
||||
@ -167,7 +166,7 @@ func (rs *REST) Watch(ctx context.Context, label, field labels.Selector, resourc
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (rs *REST) waitForController(ctx context.Context, ctrl *api.ReplicationController) (runtime.Object, error) {
|
||||
func (rs *REST) waitForController(ctx api.Context, ctrl *api.ReplicationController) (runtime.Object, error) {
|
||||
for {
|
||||
pods, err := rs.podLister.ListPods(ctx, labels.Set(ctrl.DesiredState.ReplicaSelector).AsSelector())
|
||||
if err != nil {
|
||||
@ -181,7 +180,7 @@ func (rs *REST) waitForController(ctx context.Context, ctrl *api.ReplicationCont
|
||||
return ctrl, nil
|
||||
}
|
||||
|
||||
func (rs *REST) fillCurrentState(ctx context.Context, ctrl *api.ReplicationController) error {
|
||||
func (rs *REST) fillCurrentState(ctx api.Context, ctrl *api.ReplicationController) error {
|
||||
if rs.podLister == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -24,8 +24,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
@ -330,7 +328,7 @@ type fakePodLister struct {
|
||||
s labels.Selector
|
||||
}
|
||||
|
||||
func (f *fakePodLister) ListPods(ctx context.Context, s labels.Selector) (*api.PodList, error) {
|
||||
func (f *fakePodLister) ListPods(ctx api.Context, s labels.Selector) (*api.PodList, error) {
|
||||
f.s = s
|
||||
return &f.l, f.e
|
||||
}
|
||||
|
@ -19,8 +19,6 @@ package endpoint
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
@ -40,12 +38,12 @@ func NewREST(registry Registry) *REST {
|
||||
}
|
||||
|
||||
// Get satisfies the RESTStorage interface.
|
||||
func (rs *REST) Get(ctx context.Context, id string) (runtime.Object, error) {
|
||||
func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
|
||||
return rs.registry.GetEndpoints(id)
|
||||
}
|
||||
|
||||
// List satisfies the RESTStorage interface.
|
||||
func (rs *REST) List(ctx context.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
if !label.Empty() || !field.Empty() {
|
||||
return nil, errors.New("label/field selectors are not supported on endpoints")
|
||||
}
|
||||
@ -54,22 +52,22 @@ func (rs *REST) List(ctx context.Context, label, field labels.Selector) (runtime
|
||||
|
||||
// Watch returns Endpoint events via a watch.Interface.
|
||||
// It implements apiserver.ResourceWatcher.
|
||||
func (rs *REST) Watch(ctx context.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
func (rs *REST) Watch(ctx api.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
return rs.registry.WatchEndpoints(label, field, resourceVersion)
|
||||
}
|
||||
|
||||
// Create satisfies the RESTStorage interface but is unimplemented.
|
||||
func (rs *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
}
|
||||
|
||||
// Update satisfies the RESTStorage interface but is unimplemented.
|
||||
func (rs *REST) Update(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
}
|
||||
|
||||
// Delete satisfies the RESTStorage interface but is unimplemented.
|
||||
func (rs *REST) Delete(ctx context.Context, id string) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
// TODO: Need to add a reconciler loop that makes sure that things in pods are reflected into
|
||||
@ -57,7 +55,7 @@ func makePodKey(podID string) string {
|
||||
}
|
||||
|
||||
// ListPods obtains a list of pods with labels that match selector.
|
||||
func (r *Registry) ListPods(ctx context.Context, selector labels.Selector) (*api.PodList, error) {
|
||||
func (r *Registry) ListPods(ctx api.Context, selector labels.Selector) (*api.PodList, error) {
|
||||
return r.ListPodsPredicate(func(pod *api.Pod) bool {
|
||||
return selector.Matches(labels.Set(pod.Labels))
|
||||
})
|
||||
|
@ -19,8 +19,6 @@ package minion
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
@ -40,7 +38,7 @@ func NewREST(m Registry) *REST {
|
||||
}
|
||||
}
|
||||
|
||||
func (rs *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
minion, ok := obj.(*api.Minion)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("not a minion: %#v", obj)
|
||||
@ -67,7 +65,7 @@ func (rs *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (rs *REST) Delete(ctx context.Context, id string) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error) {
|
||||
exists, err := rs.registry.Contains(id)
|
||||
if !exists {
|
||||
return nil, ErrDoesNotExist
|
||||
@ -80,7 +78,7 @@ func (rs *REST) Delete(ctx context.Context, id string) (<-chan runtime.Object, e
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (rs *REST) Get(ctx context.Context, id string) (runtime.Object, error) {
|
||||
func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
|
||||
exists, err := rs.registry.Contains(id)
|
||||
if !exists {
|
||||
return nil, ErrDoesNotExist
|
||||
@ -88,7 +86,7 @@ func (rs *REST) Get(ctx context.Context, id string) (runtime.Object, error) {
|
||||
return rs.toApiMinion(id), err
|
||||
}
|
||||
|
||||
func (rs *REST) List(ctx context.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
nameList, err := rs.registry.List()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -104,7 +102,7 @@ func (*REST) New() runtime.Object {
|
||||
return &api.Minion{}
|
||||
}
|
||||
|
||||
func (rs *REST) Update(ctx context.Context, minion runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Update(ctx api.Context, minion runtime.Object) (<-chan runtime.Object, error) {
|
||||
return nil, fmt.Errorf("Minions can only be created (inserted) and deleted.")
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,6 @@ limitations under the License.
|
||||
package pod
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.net/context"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
@ -27,7 +25,7 @@ import (
|
||||
// Registry is an interface implemented by things that know how to store Pod objects.
|
||||
type Registry interface {
|
||||
// ListPods obtains a list of pods having labels which match selector.
|
||||
ListPods(ctx context.Context, selector labels.Selector) (*api.PodList, error)
|
||||
ListPods(ctx api.Context, selector labels.Selector) (*api.PodList, error)
|
||||
// ListPodsPredicate obtains a list of pods for which filter returns true.
|
||||
ListPodsPredicate(filter func(*api.Pod) bool) (*api.PodList, error)
|
||||
// Watch for new/changed/deleted pods
|
||||
|
@ -32,8 +32,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
|
||||
"code.google.com/p/go-uuid/uuid"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
@ -69,7 +67,7 @@ func NewREST(config *RESTConfig) *REST {
|
||||
}
|
||||
}
|
||||
|
||||
func (rs *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
pod := obj.(*api.Pod)
|
||||
pod.DesiredState.Manifest.UUID = uuid.NewUUID().String()
|
||||
if len(pod.ID) == 0 {
|
||||
@ -90,13 +88,13 @@ func (rs *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (rs *REST) Delete(ctx context.Context, id string) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error) {
|
||||
return apiserver.MakeAsync(func() (runtime.Object, error) {
|
||||
return &api.Status{Status: api.StatusSuccess}, rs.registry.DeletePod(id)
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (rs *REST) Get(ctx context.Context, id string) (runtime.Object, error) {
|
||||
func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
|
||||
pod, err := rs.registry.GetPod(id)
|
||||
if err != nil {
|
||||
return pod, err
|
||||
@ -133,7 +131,7 @@ func (rs *REST) filterFunc(label, field labels.Selector) func(*api.Pod) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (rs *REST) List(ctx context.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
pods, err := rs.registry.ListPodsPredicate(rs.filterFunc(label, field))
|
||||
if err == nil {
|
||||
for i := range pods.Items {
|
||||
@ -151,7 +149,7 @@ func (rs *REST) List(ctx context.Context, label, field labels.Selector) (runtime
|
||||
}
|
||||
|
||||
// Watch begins watching for new, changed, or deleted pods.
|
||||
func (rs *REST) Watch(ctx context.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
func (rs *REST) Watch(ctx api.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
return rs.registry.WatchPods(resourceVersion, rs.filterFunc(label, field))
|
||||
}
|
||||
|
||||
@ -159,7 +157,7 @@ func (*REST) New() runtime.Object {
|
||||
return &api.Pod{}
|
||||
}
|
||||
|
||||
func (rs *REST) Update(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
pod := obj.(*api.Pod)
|
||||
if errs := validation.ValidatePod(pod); len(errs) > 0 {
|
||||
return nil, errors.NewInvalid("pod", pod.ID, errs)
|
||||
@ -279,7 +277,7 @@ func getPodStatus(pod *api.Pod, minions client.MinionInterface) (api.PodStatus,
|
||||
}
|
||||
}
|
||||
|
||||
func (rs *REST) waitForPodRunning(ctx context.Context, pod *api.Pod) (runtime.Object, error) {
|
||||
func (rs *REST) waitForPodRunning(ctx api.Context, pod *api.Pod) (runtime.Object, error) {
|
||||
for {
|
||||
podObj, err := rs.Get(ctx, pod.ID)
|
||||
if err != nil || podObj == nil {
|
||||
|
@ -22,8 +22,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
type PodRegistry struct {
|
||||
@ -59,7 +57,7 @@ func (r *PodRegistry) ListPodsPredicate(filter func(*api.Pod) bool) (*api.PodLis
|
||||
return &pods, nil
|
||||
}
|
||||
|
||||
func (r *PodRegistry) ListPods(ctx context.Context, selector labels.Selector) (*api.PodList, error) {
|
||||
func (r *PodRegistry) ListPods(ctx api.Context, selector labels.Selector) (*api.PodList, error) {
|
||||
return r.ListPodsPredicate(func(pod *api.Pod) bool {
|
||||
return selector.Matches(labels.Set(pod.Labels))
|
||||
})
|
||||
|
@ -32,8 +32,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
// REST adapts a service registry into apiserver's RESTStorage model.
|
||||
@ -52,7 +50,7 @@ func NewREST(registry Registry, cloud cloudprovider.Interface, machines minion.R
|
||||
}
|
||||
}
|
||||
|
||||
func (rs *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
srv := obj.(*api.Service)
|
||||
if errs := validation.ValidateService(srv); len(errs) > 0 {
|
||||
return nil, errors.NewInvalid("service", srv.ID, errs)
|
||||
@ -96,7 +94,7 @@ func (rs *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (rs *REST) Delete(ctx context.Context, id string) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error) {
|
||||
service, err := rs.registry.GetService(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -107,7 +105,7 @@ func (rs *REST) Delete(ctx context.Context, id string) (<-chan runtime.Object, e
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (rs *REST) Get(ctx context.Context, id string) (runtime.Object, error) {
|
||||
func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
|
||||
s, err := rs.registry.GetService(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -116,7 +114,7 @@ func (rs *REST) Get(ctx context.Context, id string) (runtime.Object, error) {
|
||||
}
|
||||
|
||||
// TODO: implement field selector?
|
||||
func (rs *REST) List(ctx context.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
list, err := rs.registry.ListServices()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -133,7 +131,7 @@ func (rs *REST) List(ctx context.Context, label, field labels.Selector) (runtime
|
||||
|
||||
// Watch returns Services events via a watch.Interface.
|
||||
// It implements apiserver.ResourceWatcher.
|
||||
func (rs *REST) Watch(ctx context.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
func (rs *REST) Watch(ctx api.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
return rs.registry.WatchServices(label, field, resourceVersion)
|
||||
}
|
||||
|
||||
@ -165,7 +163,7 @@ func GetServiceEnvironmentVariables(registry Registry, machine string) ([]api.En
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (rs *REST) Update(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
srv := obj.(*api.Service)
|
||||
if errs := validation.ValidateService(srv); len(errs) > 0 {
|
||||
return nil, errors.NewInvalid("service", srv.ID, errs)
|
||||
@ -181,7 +179,7 @@ func (rs *REST) Update(ctx context.Context, obj runtime.Object) (<-chan runtime.
|
||||
}
|
||||
|
||||
// ResourceLocation returns a URL to which one can send traffic for the specified service.
|
||||
func (rs *REST) ResourceLocation(ctx context.Context, id string) (string, error) {
|
||||
func (rs *REST) ResourceLocation(ctx api.Context, id string) (string, error) {
|
||||
e, err := rs.registry.GetEndpoints(id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
Loading…
Reference in New Issue
Block a user