當前位置: 首頁>>代碼示例>>Golang>>正文


Golang tools.EtcdHelper類代碼示例

本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/tools.EtcdHelper的典型用法代碼示例。如果您正苦於以下問題:Golang EtcdHelper類的具體用法?Golang EtcdHelper怎麽用?Golang EtcdHelper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了EtcdHelper類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestWatch

func TestWatch(t *testing.T) {
	client := newEtcdClient()
	helper := tools.EtcdHelper{Client: client, Codec: runtime.DefaultCodec, ResourceVersioner: runtime.DefaultResourceVersioner}
	withEtcdKey(func(key string) {
		resp, err := client.Set(key, runtime.DefaultScheme.EncodeOrDie(&api.Pod{JSONBase: api.JSONBase{ID: "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 := helper.Watch(key, 0)
		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 != expectedVersion {
			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 != expectedVersion {
			t.Errorf("expected version %d, got %#v", expectedVersion, pod)
		}
	})
}
開發者ID:asim,項目名稱:kubernetes,代碼行數:52,代碼來源:etcd_tools_test.go

示例2: synchronize

func (rm *ReplicationManager) synchronize() {
	var controllerSpecs []api.ReplicationController
	helper := tools.EtcdHelper{rm.etcdClient}
	err := helper.ExtractList("/registry/controllers", &controllerSpecs)
	if err != nil {
		glog.Errorf("Synchronization error: %v (%#v)", err, err)
		return
	}
	for _, controllerSpec := range controllerSpecs {
		err = rm.syncHandler(controllerSpec)
		if err != nil {
			glog.Errorf("Error synchronizing: %#v", err)
		}
	}
}
開發者ID:hknochi,項目名稱:kubernetes,代碼行數:15,代碼來源:replication_controller.go

示例3: TestSetObj

func TestSetObj(t *testing.T) {
	client := newEtcdClient()
	helper := tools.EtcdHelper{Client: client, Codec: stringCodec{}}
	withEtcdKey(func(key string) {
		if err := helper.SetObj(key, "object"); 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)
		}
		if resp.Node.Value != "object" {
			t.Errorf("unexpected response: %#v", resp.Node)
		}
	})
}
開發者ID:K-A-Z,項目名稱:kubernetes,代碼行數:16,代碼來源:etcd_tools_test.go

示例4: TestExtractObj

func TestExtractObj(t *testing.T) {
	client := framework.NewEtcdClient()
	helper := tools.EtcdHelper{Client: client, Codec: stringCodec{}}
	framework.WithEtcdKey(func(key string) {
		_, err := client.Set(key, "object", 0)
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		s := fakeAPIObject("")
		if err := helper.ExtractObj(key, &s, false); err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		if s != "object" {
			t.Errorf("unexpected response: %#v", s)
		}
	})
}
開發者ID:chenzhen411,項目名稱:kubernetes,代碼行數:17,代碼來源:etcd_tools_test.go

示例5: synchronize

func (rm *ReplicationManager) synchronize() {
	var controllerSpecs []api.ReplicationController
	helper := tools.EtcdHelper{rm.etcdClient}
	err := helper.ExtractList("/registry/controllers", &controllerSpecs)
	if err != nil {
		glog.Errorf("Synchronization error: %v (%#v)", err, err)
		return
	}
	wg := sync.WaitGroup{}
	wg.Add(len(controllerSpecs))
	for ix := range controllerSpecs {
		go func(ix int) {
			defer wg.Done()
			err := rm.syncHandler(controllerSpecs[ix])
			if err != nil {
				glog.Errorf("Error synchronizing: %#v", err)
			}
		}(ix)
	}
	wg.Wait()
}
開發者ID:nqn,項目名稱:kubernetes,代碼行數:21,代碼來源:replication_controller.go

示例6: makeEtcdWatch

// makeEtcdWatch starts watching via etcd.
func (rm *ReplicationManager) makeEtcdWatch() (watch.Interface, error) {
	helper := tools.EtcdHelper{rm.etcdClient}
	return helper.WatchList("/registry/controllers", tools.Everything)
}
開發者ID:htomika,項目名稱:kubernetes,代碼行數:5,代碼來源:replication_controller.go


注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/tools.EtcdHelper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。