예제 #1
0
파일: etcd.go 프로젝트: rimey/kubernetes
func SetObjectsForKey(fakeClient *tools.FakeEtcdClient, key string, objects []runtime.Object) []runtime.Object {
	result := make([]runtime.Object, len(objects))
	if len(objects) > 0 {
		nodes := make([]*etcd.Node, len(objects))
		for i, obj := range objects {
			encoded := runtime.EncodeOrDie(testapi.Codec(), obj)
			decoded, _ := testapi.Codec().Decode([]byte(encoded))
			nodes[i] = &etcd.Node{Value: encoded}
			result[i] = decoded
		}
		fakeClient.Data[key] = tools.EtcdResponseWithError{
			R: &etcd.Response{
				Node: &etcd.Node{
					Nodes: nodes,
				},
			},
			E: nil,
		}
	} else {
		fakeClient.Data[key] = tools.EtcdResponseWithError{
			R: &etcd.Response{},
			E: fakeClient.NewError(tools.EtcdErrorCodeNotFound),
		}
	}
	return result
}
예제 #2
0
func storeToEtcd(fakeClient *tools.FakeEtcdClient, path, name string, obj interface{}) error {
	data, err := encodeToThirdParty(name, obj)
	if err != nil {
		return err
	}
	_, err = fakeClient.Set(etcdtest.PathPrefix()+path, string(data), 0)
	return err
}
예제 #3
0
파일: etcd.go 프로젝트: rimey/kubernetes
func SetObject(fakeClient *tools.FakeEtcdClient, keyFn keyFunc, ctx api.Context, obj runtime.Object) error {
	meta, err := api.ObjectMetaFor(obj)
	if err != nil {
		return err
	}
	key, err := keyFn(ctx, meta.Name)
	if err != nil {
		return err
	}
	key = etcdtest.AddPrefix(key)
	_, err = fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), obj), 0)
	return err
}
예제 #4
0
파일: etcd.go 프로젝트: rimey/kubernetes
func GetObject(fakeClient *tools.FakeEtcdClient, keyFn keyFunc, newFn newFunc, ctx api.Context, obj runtime.Object) (runtime.Object, error) {
	meta, err := api.ObjectMetaFor(obj)
	if err != nil {
		return nil, err
	}
	key, err := keyFn(ctx, meta.Name)
	if err != nil {
		return nil, err
	}
	key = etcdtest.AddPrefix(key)
	resp, err := fakeClient.Get(key, false, false)
	if err != nil {
		return nil, err
	}
	result := newFn()
	if err := testapi.Codec().DecodeInto([]byte(resp.Node.Value), result); err != nil {
		return nil, err
	}
	return result, nil
}
예제 #5
0
파일: etcd.go 프로젝트: rimey/kubernetes
func SetResourceVersion(fakeClient *tools.FakeEtcdClient, resourceVersion uint64) {
	fakeClient.ChangeIndex = resourceVersion
}