Skip to content

Commit

Permalink
Merge pull request kubernetes#5429 from jszczepkowski/podfactory
Browse files Browse the repository at this point in the history
Cleanup: removed BoundPodFactory.
  • Loading branch information
satnam6502 committed Mar 13, 2015
2 parents 27c51ee + ba9d02c commit 53b25a7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 118 deletions.
4 changes: 1 addition & 3 deletions pkg/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,7 @@ func logStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter)

// init initializes master.
func (m *Master) init(c *Config) {

boundPodFactory := &pod.BasicBoundPodFactory{}
podStorage, bindingStorage, podStatusStorage := podetcd.NewREST(c.EtcdHelper, boundPodFactory)
podStorage, bindingStorage, podStatusStorage := podetcd.NewREST(c.EtcdHelper)
podRegistry := pod.NewRegistry(podStorage)

eventRegistry := event.NewEtcdRegistry(c.EtcdHelper, uint64(c.EventTTL.Seconds()))
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/etcd/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewTestEtcdRegistry(client tools.EtcdClient) *Registry {

func NewTestEtcdRegistryWithPods(client tools.EtcdClient) *Registry {
helper := tools.EtcdHelper{client, latest.Codec, tools.RuntimeVersionAdapter{latest.ResourceVersioner}}
podStorage, _, _ := podetcd.NewREST(helper, nil)
podStorage, _, _ := podetcd.NewREST(helper)
registry := NewRegistry(helper, pod.NewRegistry(podStorage))
return registry
}
Expand Down
38 changes: 0 additions & 38 deletions pkg/registry/pod/bound_pod_factory.go

This file was deleted.

53 changes: 0 additions & 53 deletions pkg/registry/pod/bound_pod_factory_test.go

This file was deleted.

9 changes: 4 additions & 5 deletions pkg/registry/pod/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type REST struct {
}

// NewREST returns a RESTStorage object that will work against pods.
func NewREST(h tools.EtcdHelper, factory pod.BoundPodFactory) (*REST, *BindingREST, *StatusREST) {
func NewREST(h tools.EtcdHelper) (*REST, *BindingREST, *StatusREST) {
prefix := "/registry/pods"
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Pod{} },
Expand Down Expand Up @@ -71,7 +71,7 @@ func NewREST(h tools.EtcdHelper, factory pod.BoundPodFactory) (*REST, *BindingRE

statusStore.UpdateStrategy = pod.StatusStrategy

return &REST{store: store}, &BindingREST{store: store, factory: factory}, &StatusREST{store: &statusStore}
return &REST{store: store}, &BindingREST{store: store}, &StatusREST{store: &statusStore}
}

// WithPodStatus returns a rest object that decorates returned responses with extra
Expand Down Expand Up @@ -130,8 +130,7 @@ func (r *REST) ResourceLocation(ctx api.Context, name string) (string, error) {

// BindingREST implements the REST endpoint for binding pods to nodes when etcd is in use.
type BindingREST struct {
store *etcdgeneric.Etcd
factory pod.BoundPodFactory
store *etcdgeneric.Etcd
}

func (r *BindingREST) New() runtime.Object {
Expand Down Expand Up @@ -167,7 +166,7 @@ func (r *BindingREST) setPodHostTo(ctx api.Context, podID, oldMachine, machine s
return nil, fmt.Errorf("unexpected object: %#v", obj)
}
if pod.Spec.Host != oldMachine || pod.Status.Host != oldMachine {
return nil, fmt.Errorf("pod %v is already assigned to host %v or %v", pod.Name, pod.Spec.Host, pod.Status.Host)
return nil, fmt.Errorf("pod %v is already assigned to host %q or %q", pod.Name, pod.Spec.Host, pod.Status.Host)
}
pod.Spec.Host = machine
pod.Status.Host = machine
Expand Down
36 changes: 18 additions & 18 deletions pkg/registry/pod/etcd/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {

func newStorage(t *testing.T) (*REST, *BindingREST, *StatusREST, *tools.FakeEtcdClient, tools.EtcdHelper) {
fakeEtcdClient, h := newHelper(t)
storage, bindingStorage, statusStorage := NewREST(h, &pod.BasicBoundPodFactory{})
storage, bindingStorage, statusStorage := NewREST(h)
storage = storage.WithPodStatus(&fakeCache{statusToReturn: &api.PodStatus{}})
return storage, bindingStorage, statusStorage, fakeEtcdClient, h
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestStorage(t *testing.T) {

func TestCreate(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{statusToReturn: &api.PodStatus{}}
storage = storage.WithPodStatus(cache)
test := resttest.New(t, storage, fakeEtcdClient.SetError)
Expand Down Expand Up @@ -142,7 +142,7 @@ func expectPod(t *testing.T, out runtime.Object) (*api.Pod, bool) {
func TestCreateRegistryError(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
fakeEtcdClient.Err = fmt.Errorf("test error")
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)

pod := validNewPod()
_, err := storage.Create(api.NewDefaultContext(), pod)
Expand All @@ -153,7 +153,7 @@ func TestCreateRegistryError(t *testing.T) {

func TestCreateSetsFields(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{statusToReturn: &api.PodStatus{}}
storage = storage.WithPodStatus(cache)
pod := validNewPod()
Expand All @@ -177,7 +177,7 @@ func TestCreateSetsFields(t *testing.T) {
func TestListError(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
fakeEtcdClient.Err = fmt.Errorf("test error")
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{}
storage = storage.WithPodStatus(cache)
pods, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestListCacheError(t *testing.T) {
},
},
}
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{errorToReturn: client.ErrPodInfoNotAvailable}
storage = storage.WithPodStatus(cache)

Expand All @@ -230,7 +230,7 @@ func TestListEmptyPodList(t *testing.T) {
E: fakeEtcdClient.NewError(tools.EtcdErrorCodeNotFound),
}

storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{}
storage = storage.WithPodStatus(cache)
pods, err := storage.List(api.NewContext(), labels.Everything(), fields.Everything())
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestListPodList(t *testing.T) {
},
},
}
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{statusToReturn: &api.PodStatus{Phase: api.PodRunning}}
storage = storage.WithPodStatus(cache)

Expand Down Expand Up @@ -319,7 +319,7 @@ func TestListPodListSelection(t *testing.T) {
},
},
}
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{statusToReturn: &api.PodStatus{Phase: api.PodRunning}}
storage = storage.WithPodStatus(cache)

Expand Down Expand Up @@ -386,7 +386,7 @@ func TestListPodListSelection(t *testing.T) {
}

func TestPodDecode(t *testing.T) {
storage, _, _ := NewREST(tools.EtcdHelper{}, nil)
storage, _, _ := NewREST(tools.EtcdHelper{})
expected := validNewPod()
body, err := latest.Codec.Encode(expected)
if err != nil {
Expand Down Expand Up @@ -415,7 +415,7 @@ func TestGet(t *testing.T) {
},
},
}
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{statusToReturn: &api.PodStatus{Phase: api.PodRunning}}
storage = storage.WithPodStatus(cache)

Expand Down Expand Up @@ -443,7 +443,7 @@ func TestGetCacheError(t *testing.T) {
},
},
}
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{errorToReturn: client.ErrPodInfoNotAvailable}
storage = storage.WithPodStatus(cache)

Expand All @@ -463,7 +463,7 @@ func TestGetCacheError(t *testing.T) {
func TestPodStorageValidatesCreate(t *testing.T) {
fakeEtcdClient, helper := newHelper(t)
fakeEtcdClient.Err = fmt.Errorf("test error")
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{statusToReturn: &api.PodStatus{}}
storage = storage.WithPodStatus(cache)

Expand All @@ -483,7 +483,7 @@ func TestPodStorageValidatesCreate(t *testing.T) {
// TODO: remove, this is covered by RESTTest.TestCreate
func TestCreatePod(t *testing.T) {
_, helper := newHelper(t)
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{statusToReturn: &api.PodStatus{}}
storage = storage.WithPodStatus(cache)

Expand All @@ -507,7 +507,7 @@ func TestCreatePod(t *testing.T) {
// TODO: remove, this is covered by RESTTest.TestCreate
func TestCreateWithConflictingNamespace(t *testing.T) {
_, helper := newHelper(t)
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{}
storage = storage.WithPodStatus(cache)

Expand Down Expand Up @@ -538,7 +538,7 @@ func TestUpdateWithConflictingNamespace(t *testing.T) {
},
},
}
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{}
storage = storage.WithPodStatus(cache)

Expand Down Expand Up @@ -650,7 +650,7 @@ func TestResourceLocation(t *testing.T) {
},
},
}
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{statusToReturn: &api.PodStatus{PodIP: expectedIP}}
storage = storage.WithPodStatus(cache)

Expand Down Expand Up @@ -684,7 +684,7 @@ func TestDeletePod(t *testing.T) {
},
},
}
storage, _, _ := NewREST(helper, nil)
storage, _, _ := NewREST(helper)
cache := &fakeCache{statusToReturn: &api.PodStatus{}}
storage = storage.WithPodStatus(cache)

Expand Down

0 comments on commit 53b25a7

Please sign in to comment.