Merge pull request #5707 from endocode/kbeecher/etcd_prefix
Adds ability to define a prefix for etcd paths
This commit is contained in:
@@ -34,7 +34,7 @@ type REST struct {
|
||||
|
||||
// NewREST returns a RESTStorage object that will work against PersistentVolumeClaim objects.
|
||||
func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
|
||||
prefix := "/registry/persistentvolumeclaims"
|
||||
prefix := "/persistentvolumeclaims"
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.PersistentVolumeClaim{} },
|
||||
NewListFunc: func() runtime.Object { return &api.PersistentVolumeClaimList{} },
|
||||
|
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
@@ -40,7 +41,7 @@ type testRegistry struct {
|
||||
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, latest.Codec)
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
storage, statusStorage := NewStorage(helper)
|
||||
return storage, statusStorage, fakeEtcdClient, helper
|
||||
}
|
||||
@@ -95,6 +96,7 @@ func TestDelete(t *testing.T) {
|
||||
|
||||
pv := validChangedPersistentVolumeClaim()
|
||||
key, _ := storage.KeyFunc(ctx, pv.Name)
|
||||
key = etcdtest.AddPrefix(key)
|
||||
createFn := func() runtime.Object {
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
R: &etcd.Response{
|
||||
@@ -119,6 +121,7 @@ func TestEtcdListPersistentVolumeClaims(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
registry, _, fakeClient, _ := newStorage(t)
|
||||
key := registry.KeyRootFunc(ctx)
|
||||
key = etcdtest.AddPrefix(key)
|
||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||
R: &etcd.Response{
|
||||
Node: &etcd.Node{
|
||||
@@ -152,6 +155,7 @@ func TestEtcdGetPersistentVolumeClaims(t *testing.T) {
|
||||
persistentVolume := validNewPersistentVolumeClaim("foo", api.NamespaceDefault)
|
||||
name := persistentVolume.Name
|
||||
key, _ := registry.KeyFunc(ctx, name)
|
||||
key = etcdtest.AddPrefix(key)
|
||||
fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, persistentVolume), 0)
|
||||
|
||||
response, err := fakeClient.Get(key, false, false)
|
||||
@@ -181,6 +185,7 @@ func TestListEmptyPersistentVolumeClaimsList(t *testing.T) {
|
||||
registry, _, fakeClient, _ := newStorage(t)
|
||||
fakeClient.ChangeIndex = 1
|
||||
key := registry.KeyRootFunc(ctx)
|
||||
key = etcdtest.AddPrefix(key)
|
||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||
R: &etcd.Response{},
|
||||
E: fakeClient.NewError(tools.EtcdErrorCodeNotFound),
|
||||
@@ -204,6 +209,7 @@ func TestListPersistentVolumeClaimsList(t *testing.T) {
|
||||
registry, _, fakeClient, _ := newStorage(t)
|
||||
fakeClient.ChangeIndex = 1
|
||||
key := registry.KeyRootFunc(ctx)
|
||||
key = etcdtest.AddPrefix(key)
|
||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||
R: &etcd.Response{
|
||||
Node: &etcd.Node{
|
||||
@@ -264,6 +270,7 @@ func TestEtcdUpdatePersistentVolumeClaims(t *testing.T) {
|
||||
persistentVolume := validChangedPersistentVolumeClaim()
|
||||
|
||||
key, _ := registry.KeyFunc(ctx, "foo")
|
||||
key = etcdtest.AddPrefix(key)
|
||||
fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, validNewPersistentVolumeClaim("foo", api.NamespaceDefault)), 0)
|
||||
|
||||
_, _, err := registry.Update(ctx, persistentVolume)
|
||||
@@ -293,6 +300,7 @@ func TestDeletePersistentVolumeClaims(t *testing.T) {
|
||||
pvClaim := validNewPersistentVolumeClaim("foo", api.NamespaceDefault)
|
||||
name := pvClaim.Name
|
||||
key, _ := registry.KeyFunc(ctx, name)
|
||||
key = etcdtest.AddPrefix(key)
|
||||
fakeClient.ChangeIndex = 1
|
||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||
R: &etcd.Response{
|
||||
@@ -315,6 +323,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
|
||||
fakeClient.TestIndex = true
|
||||
|
||||
key, _ := storage.KeyFunc(ctx, "foo")
|
||||
key = etcdtest.AddPrefix(key)
|
||||
pvcStart := validNewPersistentVolumeClaim("foo", api.NamespaceDefault)
|
||||
fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, pvcStart), 1)
|
||||
|
||||
@@ -339,6 +348,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
var pvcOut api.PersistentVolumeClaim
|
||||
key, _ = storage.KeyFunc(ctx, "foo")
|
||||
if err := helper.ExtractObj(key, &pvcOut, false); err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user