• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang tools.NewEtcdStorage函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/tools.NewEtcdStorage函数的典型用法代码示例。如果您正苦于以下问题:Golang NewEtcdStorage函数的具体用法?Golang NewEtcdStorage怎么用?Golang NewEtcdStorage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewEtcdStorage函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: NewTestEventEtcdRegistry

func NewTestEventEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, generic.Registry) {
	f := tools.NewFakeEtcdClient(t)
	f.TestIndex = true

	s := tools.NewEtcdStorage(f, testapi.Codec(), etcdtest.PathPrefix())
	return f, NewEtcdRegistry(s, testTTL)
}
开发者ID:rferris,项目名称:kubernetes,代码行数:7,代码来源:registry_test.go


示例2: newStorage

func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient, tools.StorageInterface) {
	fakeEtcdClient := tools.NewFakeEtcdClient(t)
	fakeEtcdClient.TestIndex = true
	etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
	storage, statusStorage := NewStorage(etcdStorage)
	return storage, statusStorage, fakeEtcdClient, etcdStorage
}
开发者ID:ravigadde,项目名称:kube-scheduler,代码行数:7,代码来源:etcd_test.go


示例3: NewTestEtcdRegistryWithPods

func NewTestEtcdRegistryWithPods(client tools.EtcdClient) *Registry {
	etcdStorage := tools.NewEtcdStorage(client, latest.Codec, etcdtest.PathPrefix())
	podStorage := podetcd.NewStorage(etcdStorage, nil)
	endpointStorage := endpointetcd.NewStorage(etcdStorage)
	registry := NewRegistry(etcdStorage, pod.NewRegistry(podStorage.Pod), endpoint.NewRegistry(endpointStorage))
	return registry
}
开发者ID:rferris,项目名称:kubernetes,代码行数:7,代码来源:etcd_test.go


示例4: NewEtcdStorage

// NewEtcdStorage returns a StorageInterface for the provided arguments or an error if the version
// is incorrect.
func NewEtcdStorage(client tools.EtcdClient, version string, prefix string) (etcdStorage tools.StorageInterface, err error) {
	if version == "" {
		version = latest.Version
	}
	versionInterfaces, err := latest.InterfacesFor(version)
	if err != nil {
		return etcdStorage, err
	}
	return tools.NewEtcdStorage(client, versionInterfaces.Codec, prefix), nil
}
开发者ID:TesterRandolph,项目名称:kubernetes,代码行数:12,代码来源:master.go


示例5: TestWatch

func TestWatch(t *testing.T) {
	client := framework.NewEtcdClient()
	etcdStorage := tools.NewEtcdStorage(client, testapi.Codec(), etcdtest.PathPrefix())
	framework.WithEtcdKey(func(key string) {
		key = etcdtest.AddPrefix(key)
		resp, err := client.Set(key, runtime.EncodeOrDie(testapi.Codec(), &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		expectedVersion := resp.Node.ModifiedIndex

		// watch should load the object at the current index
		w, err := etcdStorage.Watch(key, 0, tools.Everything)
		if err != nil {
			t.Fatalf("Unexpected error: %v", err)
		}

		event := <-w.ResultChan()
		if event.Type != watch.Added || event.Object == nil {
			t.Fatalf("expected first value to be set to ADDED, got %#v", event)
		}

		// version should match what we set
		pod := event.Object.(*api.Pod)
		if pod.ResourceVersion != strconv.FormatUint(expectedVersion, 10) {
			t.Errorf("expected version %d, got %#v", expectedVersion, pod)
		}

		// should be no events in the stream
		select {
		case event, ok := <-w.ResultChan():
			if !ok {
				t.Fatalf("channel closed unexpectedly")
			}
			t.Fatalf("unexpected object in channel: %#v", event)
		default:
		}

		// should return the previously deleted item in the watch, but with the latest index
		resp, err = client.Delete(key, false)
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		expectedVersion = resp.Node.ModifiedIndex
		event = <-w.ResultChan()
		if event.Type != watch.Deleted {
			t.Errorf("expected deleted event %#v", event)
		}
		pod = event.Object.(*api.Pod)
		if pod.ResourceVersion != strconv.FormatUint(expectedVersion, 10) {
			t.Errorf("expected version %d, got %#v", expectedVersion, pod)
		}
	})
}
开发者ID:ravigadde,项目名称:kube-scheduler,代码行数:54,代码来源:etcd_tools_test.go


示例6: TestGetServersToValidate

func TestGetServersToValidate(t *testing.T) {
	master := Master{}
	config := Config{}
	fakeClient := tools.NewFakeEtcdClient(t)
	fakeClient.Machines = []string{"http://machine1:4001", "http://machine2", "http://machine3:4003"}
	config.DatabaseStorage = tools.NewEtcdStorage(fakeClient, latest.Codec, etcdtest.PathPrefix())

	master.nodeRegistry = registrytest.NewMinionRegistry([]string{"node1", "node2"}, api.NodeResources{})

	servers := master.getServersToValidate(&config)

	if len(servers) != 5 {
		t.Errorf("unexpected server list: %#v", servers)
	}
	for _, server := range []string{"scheduler", "controller-manager", "etcd-0", "etcd-1", "etcd-2"} {
		if _, ok := servers[server]; !ok {
			t.Errorf("server list missing: %s", server)
		}
	}
}
开发者ID:ravigadde,项目名称:kube-scheduler,代码行数:20,代码来源:master_test.go


示例7: TestSetObj

func TestSetObj(t *testing.T) {
	client := framework.NewEtcdClient()
	etcdStorage := tools.NewEtcdStorage(client, testapi.Codec(), "")
	framework.WithEtcdKey(func(key string) {
		testObject := api.ServiceAccount{ObjectMeta: api.ObjectMeta{Name: "foo"}}
		if err := etcdStorage.SetObj(key, &testObject, nil, 0); err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		resp, err := client.Get(key, false, false)
		if err != nil || resp.Node == nil {
			t.Fatalf("unexpected error: %v %v", err, resp)
		}
		decoded, err := testapi.Codec().Decode([]byte(resp.Node.Value))
		if err != nil {
			t.Fatalf("unexpected response: %#v", resp.Node)
		}
		result := *decoded.(*api.ServiceAccount)
		if !api.Semantic.DeepEqual(testObject, result) {
			t.Errorf("expected: %#v got: %#v", testObject, result)
		}
	})
}
开发者ID:ravigadde,项目名称:kube-scheduler,代码行数:22,代码来源:etcd_tools_test.go


示例8: NewTestGenericEtcdRegistry

func NewTestGenericEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, *Etcd) {
	f := tools.NewFakeEtcdClient(t)
	f.TestIndex = true
	s := tools.NewEtcdStorage(f, testapi.Codec(), etcdtest.PathPrefix())
	strategy := &testRESTStrategy{api.Scheme, api.SimpleNameGenerator, true, false, true}
	podPrefix := "/pods"
	return f, &Etcd{
		NewFunc:        func() runtime.Object { return &api.Pod{} },
		NewListFunc:    func() runtime.Object { return &api.PodList{} },
		EndpointName:   "pods",
		CreateStrategy: strategy,
		UpdateStrategy: strategy,
		KeyRootFunc: func(ctx api.Context) string {
			return podPrefix
		},
		KeyFunc: func(ctx api.Context, id string) (string, error) {
			return path.Join(podPrefix, id), nil
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) { return obj.(*api.Pod).Name, nil },
		Storage:        s,
	}
}
开发者ID:rferris,项目名称:kubernetes,代码行数:22,代码来源:etcd_test.go


示例9: TestExtractObj

func TestExtractObj(t *testing.T) {
	client := framework.NewEtcdClient()
	etcdStorage := tools.NewEtcdStorage(client, testapi.Codec(), "")
	framework.WithEtcdKey(func(key string) {
		testObject := api.ServiceAccount{ObjectMeta: api.ObjectMeta{Name: "foo"}}
		coded, err := testapi.Codec().Encode(&testObject)
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		_, err = client.Set(key, string(coded), 0)
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		result := api.ServiceAccount{}
		if err := etcdStorage.ExtractObj(key, &result, false); err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		// Propagate ResourceVersion (it is set automatically).
		testObject.ObjectMeta.ResourceVersion = result.ObjectMeta.ResourceVersion
		if !api.Semantic.DeepEqual(testObject, result) {
			t.Errorf("expected: %#v got: %#v", testObject, result)
		}
	})
}
开发者ID:ravigadde,项目名称:kube-scheduler,代码行数:24,代码来源:etcd_tools_test.go


示例10: newEtcdStorage

func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
	fakeEtcdClient := tools.NewFakeEtcdClient(t)
	fakeEtcdClient.TestIndex = true
	etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
	return fakeEtcdClient, etcdStorage
}
开发者ID:rferris,项目名称:kubernetes,代码行数:6,代码来源:etcd_test.go


示例11: NewTestEtcdRegistry

func NewTestEtcdRegistry(client tools.EtcdClient) *Registry {
	storage := tools.NewEtcdStorage(client, latest.Codec, etcdtest.PathPrefix())
	registry := NewRegistry(storage, nil, nil)
	return registry
}
开发者ID:rferris,项目名称:kubernetes,代码行数:5,代码来源:etcd_test.go



注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/tools.NewEtcdStorage函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang tools.NewFakeEtcdClient函数代码示例发布时间:2022-05-23
下一篇:
Golang tools.NewEtcdHelper函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap