Update to use api.Context

This commit is contained in:
derekwaynecarr 2014-09-26 11:46:04 -04:00
parent b8d95ad01f
commit ee19ba186d
15 changed files with 68 additions and 87 deletions

View File

@ -20,7 +20,12 @@ import (
"code.google.com/p/go.net/context" "code.google.com/p/go.net/context"
) )
// NewContext instantiates a base context object for request flows // Context carries values across API boundaries.
func NewContext() context.Context { type Context interface {
return context.Background() Value(key interface{}) interface{}
}
// NewContext instantiates a base context object for request flows
func NewContext() Context {
return context.TODO()
} }

View File

@ -30,7 +30,6 @@ import (
"testing" "testing"
"time" "time"
"code.google.com/p/go.net/context"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
apierrs "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" apierrs "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
@ -89,18 +88,18 @@ type SimpleRESTStorage struct {
injectedFunction func(obj runtime.Object) (returnObj runtime.Object, err error) 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{ result := &SimpleList{
Items: storage.list, Items: storage.list,
} }
return result, storage.errors["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"] 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 storage.deleted = id
if err := storage.errors["delete"]; err != nil { if err := storage.errors["delete"]; err != nil {
return nil, err return nil, err
@ -117,7 +116,7 @@ func (storage *SimpleRESTStorage) New() runtime.Object {
return &Simple{} 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) storage.created = obj.(*Simple)
if err := storage.errors["create"]; err != nil { if err := storage.errors["create"]; err != nil {
return nil, err return nil, err
@ -130,7 +129,7 @@ func (storage *SimpleRESTStorage) Create(ctx context.Context, obj runtime.Object
}), nil }), 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) storage.updated = obj.(*Simple)
if err := storage.errors["update"]; err != nil { if err := storage.errors["update"]; err != nil {
return nil, err return nil, err
@ -144,7 +143,7 @@ func (storage *SimpleRESTStorage) Update(ctx context.Context, obj runtime.Object
} }
// Implement ResourceWatcher. // 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.requestedLabelSelector = label
storage.requestedFieldSelector = field storage.requestedFieldSelector = field
storage.requestedResourceVersion = resourceVersion storage.requestedResourceVersion = resourceVersion
@ -156,7 +155,7 @@ func (storage *SimpleRESTStorage) Watch(ctx context.Context, label, field labels
} }
// Implement Redirector. // 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 storage.requestedResourceLocationID = id
if err := storage.errors["resourceLocation"]; err != nil { if err := storage.errors["resourceLocation"]; err != nil {
return "", err return "", err

View File

@ -17,7 +17,7 @@ limitations under the License.
package apiserver package apiserver
import ( 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/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
@ -31,20 +31,20 @@ type RESTStorage interface {
New() runtime.Object New() runtime.Object
// List selects resources in the storage which match to the selector. // 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. // 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 // 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. // 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. // Delete finds a resource in the storage and deletes it.
// Although it can return an arbitrary error value, IsNotFound(err) is true for the // 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. // 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) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error)
Update(ctx context.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 // 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 // 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 // isn't supported. 'resourceVersion' allows for continuing/starting a watch at a
// particular version. // 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. // Redirector know how to return a remote resource's location.
type Redirector interface { type Redirector interface {
// ResourceLocation should return the remote location of the given resource, or an error. // 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)
} }

View File

@ -19,8 +19,6 @@ package master
import ( import (
"sync" "sync"
"code.google.com/p/go.net/context"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "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. // UpdateAllContainers updates information about all containers. Either called by Loop() below, or one-off.
func (p *PodCache) UpdateAllContainers() { func (p *PodCache) UpdateAllContainers() {
var ctx context.Context var ctx api.Context
pods, err := p.pods.ListPods(ctx, labels.Everything()) pods, err := p.pods.ListPods(ctx, labels.Everything())
if err != nil { if err != nil {
glog.Errorf("Error synchronizing container list: %v", err) glog.Errorf("Error synchronizing container list: %v", err)

View File

@ -19,8 +19,6 @@ package binding
import ( import (
"fmt" "fmt"
"code.google.com/p/go.net/context"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "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. // 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") return nil, errors.NewNotFound("binding", "list")
} }
// Get returns an error because bindings are write-only objects. // 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) return nil, errors.NewNotFound("binding", id)
} }
// Delete returns an error because bindings are write-only objects. // 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) 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. // 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) binding, ok := obj.(*api.Binding)
if !ok { if !ok {
return nil, fmt.Errorf("incorrect type: %#v", obj) 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. // 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.") return nil, fmt.Errorf("Bindings may not be changed.")
} }

View File

@ -22,8 +22,6 @@ import (
"reflect" "reflect"
"testing" "testing"
"code.google.com/p/go.net/context"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
@ -54,7 +52,7 @@ func TestNewREST(t *testing.T) {
} }
func TestRESTUnsupported(t *testing.T) { func TestRESTUnsupported(t *testing.T) {
var ctx context.Context var ctx api.Context
mockRegistry := MockRegistry{ mockRegistry := MockRegistry{
OnApplyBinding: func(b *api.Binding) error { return nil }, OnApplyBinding: func(b *api.Binding) error { return nil },
} }

View File

@ -30,12 +30,11 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"code.google.com/p/go-uuid/uuid" "code.google.com/p/go-uuid/uuid"
"code.google.com/p/go.net/context"
) )
// PodLister is anything that knows how to list pods. // PodLister is anything that knows how to list pods.
type PodLister interface { 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. // 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. // 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) controller, ok := obj.(*api.ReplicationController)
if !ok { if !ok {
return nil, fmt.Errorf("not a replication controller: %#v", obj) 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. // 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 apiserver.MakeAsync(func() (runtime.Object, error) {
return &api.Status{Status: api.StatusSuccess}, rs.registry.DeleteController(id) return &api.Status{Status: api.StatusSuccess}, rs.registry.DeleteController(id)
}), nil }), nil
} }
// Get obtains the ReplicationController specified by its id. // 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) controller, err := rs.registry.GetController(id)
if err != nil { if err != nil {
return nil, err 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. // 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() { if !field.Empty() {
return nil, fmt.Errorf("field selector not supported yet") 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 // Update replaces a given ReplicationController instance with an existing
// instance in storage.registry. // 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) controller, ok := obj.(*api.ReplicationController)
if !ok { if !ok {
return nil, fmt.Errorf("not a replication controller: %#v", obj) 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. // Watch returns ReplicationController events via a watch.Interface.
// It implements apiserver.ResourceWatcher. // 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() { if !field.Empty() {
return nil, fmt.Errorf("no field selector implemented for controllers") 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 }), 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 { for {
pods, err := rs.podLister.ListPods(ctx, labels.Set(ctrl.DesiredState.ReplicaSelector).AsSelector()) pods, err := rs.podLister.ListPods(ctx, labels.Set(ctrl.DesiredState.ReplicaSelector).AsSelector())
if err != nil { if err != nil {
@ -181,7 +180,7 @@ func (rs *REST) waitForController(ctx context.Context, ctrl *api.ReplicationCont
return ctrl, nil 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 { if rs.podLister == nil {
return nil return nil
} }

View File

@ -24,8 +24,6 @@ import (
"testing" "testing"
"time" "time"
"code.google.com/p/go.net/context"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
@ -330,7 +328,7 @@ type fakePodLister struct {
s labels.Selector 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 f.s = s
return &f.l, f.e return &f.l, f.e
} }

View File

@ -19,8 +19,6 @@ package endpoint
import ( import (
"errors" "errors"
"code.google.com/p/go.net/context"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
@ -40,12 +38,12 @@ func NewREST(registry Registry) *REST {
} }
// Get satisfies the RESTStorage interface. // 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) return rs.registry.GetEndpoints(id)
} }
// List satisfies the RESTStorage interface. // 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() { if !label.Empty() || !field.Empty() {
return nil, errors.New("label/field selectors are not supported on endpoints") 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. // Watch returns Endpoint events via a watch.Interface.
// It implements apiserver.ResourceWatcher. // 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) return rs.registry.WatchEndpoints(label, field, resourceVersion)
} }
// Create satisfies the RESTStorage interface but is unimplemented. // 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") return nil, errors.New("unimplemented")
} }
// Update satisfies the RESTStorage interface but is 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") return nil, errors.New("unimplemented")
} }
// Delete satisfies the RESTStorage interface but is 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") return nil, errors.New("unimplemented")
} }

View File

@ -29,8 +29,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/golang/glog" "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 // 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. // 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 r.ListPodsPredicate(func(pod *api.Pod) bool {
return selector.Matches(labels.Set(pod.Labels)) return selector.Matches(labels.Set(pod.Labels))
}) })

View File

@ -19,8 +19,6 @@ package minion
import ( import (
"fmt" "fmt"
"code.google.com/p/go.net/context"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "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) minion, ok := obj.(*api.Minion)
if !ok { if !ok {
return nil, fmt.Errorf("not a minion: %#v", obj) 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 }), 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) exists, err := rs.registry.Contains(id)
if !exists { if !exists {
return nil, ErrDoesNotExist return nil, ErrDoesNotExist
@ -80,7 +78,7 @@ func (rs *REST) Delete(ctx context.Context, id string) (<-chan runtime.Object, e
}), nil }), 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) exists, err := rs.registry.Contains(id)
if !exists { if !exists {
return nil, ErrDoesNotExist return nil, ErrDoesNotExist
@ -88,7 +86,7 @@ func (rs *REST) Get(ctx context.Context, id string) (runtime.Object, error) {
return rs.toApiMinion(id), err 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() nameList, err := rs.registry.List()
if err != nil { if err != nil {
return nil, err return nil, err
@ -104,7 +102,7 @@ func (*REST) New() runtime.Object {
return &api.Minion{} 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.") return nil, fmt.Errorf("Minions can only be created (inserted) and deleted.")
} }

View File

@ -17,8 +17,6 @@ limitations under the License.
package pod package pod
import ( import (
"code.google.com/p/go.net/context"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "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. // Registry is an interface implemented by things that know how to store Pod objects.
type Registry interface { type Registry interface {
// ListPods obtains a list of pods having labels which match selector. // 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 obtains a list of pods for which filter returns true.
ListPodsPredicate(filter func(*api.Pod) bool) (*api.PodList, error) ListPodsPredicate(filter func(*api.Pod) bool) (*api.PodList, error)
// Watch for new/changed/deleted pods // Watch for new/changed/deleted pods

View File

@ -32,8 +32,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"code.google.com/p/go.net/context"
"code.google.com/p/go-uuid/uuid" "code.google.com/p/go-uuid/uuid"
"github.com/golang/glog" "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 := obj.(*api.Pod)
pod.DesiredState.Manifest.UUID = uuid.NewUUID().String() pod.DesiredState.Manifest.UUID = uuid.NewUUID().String()
if len(pod.ID) == 0 { if len(pod.ID) == 0 {
@ -90,13 +88,13 @@ func (rs *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.
}), nil }), 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 apiserver.MakeAsync(func() (runtime.Object, error) {
return &api.Status{Status: api.StatusSuccess}, rs.registry.DeletePod(id) return &api.Status{Status: api.StatusSuccess}, rs.registry.DeletePod(id)
}), nil }), 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) pod, err := rs.registry.GetPod(id)
if err != nil { if err != nil {
return pod, err 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)) pods, err := rs.registry.ListPodsPredicate(rs.filterFunc(label, field))
if err == nil { if err == nil {
for i := range pods.Items { 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. // 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)) return rs.registry.WatchPods(resourceVersion, rs.filterFunc(label, field))
} }
@ -159,7 +157,7 @@ func (*REST) New() runtime.Object {
return &api.Pod{} 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) pod := obj.(*api.Pod)
if errs := validation.ValidatePod(pod); len(errs) > 0 { if errs := validation.ValidatePod(pod); len(errs) > 0 {
return nil, errors.NewInvalid("pod", pod.ID, errs) 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 { for {
podObj, err := rs.Get(ctx, pod.ID) podObj, err := rs.Get(ctx, pod.ID)
if err != nil || podObj == nil { if err != nil || podObj == nil {

View File

@ -22,8 +22,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"code.google.com/p/go.net/context"
) )
type PodRegistry struct { type PodRegistry struct {
@ -59,7 +57,7 @@ func (r *PodRegistry) ListPodsPredicate(filter func(*api.Pod) bool) (*api.PodLis
return &pods, nil 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 r.ListPodsPredicate(func(pod *api.Pod) bool {
return selector.Matches(labels.Set(pod.Labels)) return selector.Matches(labels.Set(pod.Labels))
}) })

View File

@ -32,8 +32,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"code.google.com/p/go.net/context"
) )
// REST adapts a service registry into apiserver's RESTStorage model. // 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) srv := obj.(*api.Service)
if errs := validation.ValidateService(srv); len(errs) > 0 { if errs := validation.ValidateService(srv); len(errs) > 0 {
return nil, errors.NewInvalid("service", srv.ID, errs) 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 }), 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) service, err := rs.registry.GetService(id)
if err != nil { if err != nil {
return nil, err return nil, err
@ -107,7 +105,7 @@ func (rs *REST) Delete(ctx context.Context, id string) (<-chan runtime.Object, e
}), nil }), 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) s, err := rs.registry.GetService(id)
if err != nil { if err != nil {
return nil, err return nil, err
@ -116,7 +114,7 @@ func (rs *REST) Get(ctx context.Context, id string) (runtime.Object, error) {
} }
// TODO: implement field selector? // 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() list, err := rs.registry.ListServices()
if err != nil { if err != nil {
return nil, err 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. // Watch returns Services events via a watch.Interface.
// It implements apiserver.ResourceWatcher. // 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) return rs.registry.WatchServices(label, field, resourceVersion)
} }
@ -165,7 +163,7 @@ func GetServiceEnvironmentVariables(registry Registry, machine string) ([]api.En
return result, nil 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) srv := obj.(*api.Service)
if errs := validation.ValidateService(srv); len(errs) > 0 { if errs := validation.ValidateService(srv); len(errs) > 0 {
return nil, errors.NewInvalid("service", srv.ID, errs) 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. // 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) e, err := rs.registry.GetEndpoints(id)
if err != nil { if err != nil {
return "", err return "", err