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

@@ -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

View File

@@ -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 {