Add context object to interfaces

This commit is contained in:
derekwaynecarr
2014-09-25 14:34:01 -04:00
parent 377a9ac3d7
commit 3e685674e7
15 changed files with 115 additions and 63 deletions

View File

@@ -17,6 +17,8 @@ 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"
@@ -25,7 +27,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(selector labels.Selector) (*api.PodList, error)
ListPods(ctx context.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,6 +32,8 @@ 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"
)
@@ -67,7 +69,7 @@ func NewREST(config *RESTConfig) *REST {
}
}
func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
pod := obj.(*api.Pod)
pod.DesiredState.Manifest.UUID = uuid.NewUUID().String()
if len(pod.ID) == 0 {
@@ -88,13 +90,13 @@ func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
}), nil
}
func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
func (rs *REST) Delete(ctx context.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(id string) (runtime.Object, error) {
func (rs *REST) Get(ctx context.Context, id string) (runtime.Object, error) {
pod, err := rs.registry.GetPod(id)
if err != nil {
return pod, err
@@ -131,7 +133,7 @@ func (rs *REST) filterFunc(label, field labels.Selector) func(*api.Pod) bool {
}
}
func (rs *REST) List(label, field labels.Selector) (runtime.Object, error) {
func (rs *REST) List(ctx context.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 {
@@ -149,7 +151,7 @@ func (rs *REST) List(label, field labels.Selector) (runtime.Object, error) {
}
// Watch begins watching for new, changed, or deleted pods.
func (rs *REST) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
func (rs *REST) Watch(ctx context.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
return rs.registry.WatchPods(resourceVersion, rs.filterFunc(label, field))
}
@@ -157,7 +159,7 @@ func (*REST) New() runtime.Object {
return &api.Pod{}
}
func (rs *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Update(ctx context.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)
@@ -277,9 +279,9 @@ func getPodStatus(pod *api.Pod, minions client.MinionInterface) (api.PodStatus,
}
}
func (rs *REST) waitForPodRunning(pod *api.Pod) (runtime.Object, error) {
func (rs *REST) waitForPodRunning(ctx context.Context, pod *api.Pod) (runtime.Object, error) {
for {
podObj, err := rs.Get(pod.ID)
podObj, err := rs.Get(ctx, pod.ID)
if err != nil || podObj == nil {
return nil, err
}