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


Golang etcd.InterpretGetError函數代碼示例

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


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

示例1: TestEtcdCreateBindingNoPod

// Ensure that when scheduler creates a binding for a pod that has already been deleted
// by the API server, API server returns not-found error.
func TestEtcdCreateBindingNoPod(t *testing.T) {
	registry, bindingRegistry, _, fakeClient, _ := newStorage(t)
	ctx := api.NewDefaultContext()
	fakeClient.TestIndex = true

	key, _ := registry.KeyFunc(ctx, "foo")
	fakeClient.Data[key] = tools.EtcdResponseWithError{
		R: &etcd.Response{
			Node: nil,
		},
		E: tools.EtcdErrorNotFound,
	}
	// Assume that a pod has undergone the following:
	// - Create (apiserver)
	// - Schedule (scheduler)
	// - Delete (apiserver)
	_, err := bindingRegistry.Create(ctx, &api.Binding{
		ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault, Name: "foo"},
		Target:     api.ObjectReference{Name: "machine"},
	})
	if err == nil {
		t.Fatalf("Expected not-found-error but got nothing")
	}
	if !errors.IsNotFound(etcderrors.InterpretGetError(err, "Pod", "foo")) {
		t.Fatalf("Unexpected error returned: %#v", err)
	}

	_, err = registry.Get(ctx, "foo")
	if err == nil {
		t.Fatalf("Expected not-found-error but got nothing")
	}
	if !errors.IsNotFound(etcderrors.InterpretGetError(err, "Pod", "foo")) {
		t.Fatalf("Unexpected error: %v", err)
	}
}
開發者ID:SivagnanamCiena,項目名稱:calico-kubernetes,代碼行數:37,代碼來源:etcd_test.go

示例2: Get

// Get returns an api.RangeAllocation that represents the current state in
// etcd. If the key does not exist, the object will have an empty ResourceVersion.
func (e *Etcd) Get() (*api.RangeAllocation, error) {
	existing := &api.RangeAllocation{}
	if err := e.helper.ExtractObj(e.baseKey, existing, true); err != nil {
		return nil, etcderr.InterpretGetError(err, e.kind, "")
	}
	return existing, nil
}
開發者ID:chenzhen411,項目名稱:kubernetes,代碼行數:9,代碼來源:etcd.go

示例3: Get

// Get retrieves the item from etcd.
func (e *Etcd) Get(ctx api.Context, id string) (runtime.Object, error) {
	obj := e.NewFunc()
	err := e.Helper.ExtractObj(e.KeyFunc(id), obj, false)
	if err != nil {
		return nil, etcderr.InterpretGetError(err, e.EndpointName, id)
	}
	return obj, nil
}
開發者ID:ericcapricorn,項目名稱:kubernetes,代碼行數:9,代碼來源:etcd.go

示例4: GetMinion

func (r *Registry) GetMinion(ctx api.Context, minionID string) (*api.Node, error) {
	var minion api.Node
	key := makeNodeKey(minionID)
	err := r.ExtractObj(key, &minion, false)
	if err != nil {
		return nil, etcderr.InterpretGetError(err, "minion", minionID)
	}
	return &minion, nil
}
開發者ID:vrosnet,項目名稱:kubernetes,代碼行數:9,代碼來源:etcd.go

示例5: GetController

// GetController gets a specific ReplicationController specified by its ID.
func (r *Registry) GetController(controllerID string) (*api.ReplicationController, error) {
	var controller api.ReplicationController
	key := makeControllerKey(controllerID)
	err := r.ExtractObj(key, &controller, false)
	if err != nil {
		return nil, etcderr.InterpretGetError(err, "replicationController", controllerID)
	}
	return &controller, nil
}
開發者ID:linuxwhy,項目名稱:kubernetes,代碼行數:10,代碼來源:etcd.go

示例6: GetEndpoints

// GetEndpoints obtains the endpoints for the service identified by 'name'.
func (r *Registry) GetEndpoints(name string) (*api.Endpoints, error) {
	key := makeServiceEndpointsKey(name)
	var endpoints api.Endpoints
	err := r.ExtractObj(key, &endpoints, false)
	if err != nil {
		return nil, etcderr.InterpretGetError(err, "endpoints", name)
	}
	return &endpoints, nil
}
開發者ID:linuxwhy,項目名稱:kubernetes,代碼行數:10,代碼來源:etcd.go

示例7: GetService

// GetService obtains a Service specified by its name.
func (r *Registry) GetService(name string) (*api.Service, error) {
	key := makeServiceKey(name)
	var svc api.Service
	err := r.ExtractObj(key, &svc, false)
	if err != nil {
		return nil, etcderr.InterpretGetError(err, "service", name)
	}
	return &svc, nil
}
開發者ID:linuxwhy,項目名稱:kubernetes,代碼行數:10,代碼來源:etcd.go

示例8: assignPod

// assignPod assigns the given pod to the given machine.
func (r *BindingREST) assignPod(ctx api.Context, podID string, machine string, annotations map[string]string) (err error) {
	if _, err = r.setPodHostAndAnnotations(ctx, podID, "", machine, annotations); err != nil {
		err = etcderr.InterpretGetError(err, "pod", podID)
		err = etcderr.InterpretUpdateError(err, "pod", podID)
		if _, ok := err.(*errors.StatusError); !ok {
			err = errors.NewConflict("binding", podID, err)
		}
	}
	return
}
開發者ID:cjnygard,項目名稱:origin,代碼行數:11,代碼來源:etcd.go

示例9: GetPod

// GetPod gets a specific pod specified by its ID.
func (r *Registry) GetPod(ctx api.Context, id string) (*api.Pod, error) {
	var pod api.Pod
	key, err := makePodKey(ctx, id)
	if err != nil {
		return nil, err
	}
	if err = r.ExtractObj(key, &pod, false); err != nil {
		return nil, etcderr.InterpretGetError(err, "pod", id)
	}
	return &pod, nil
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:12,代碼來源:etcd.go

示例10: GetPod

// GetPod gets a specific pod specified by its ID.
func (r *Registry) GetPod(podID string) (*api.Pod, error) {
	var pod api.Pod
	if err := r.ExtractObj(makePodKey(podID), &pod, false); err != nil {
		return nil, etcderr.InterpretGetError(err, "pod", podID)
	}
	// TODO: Currently nothing sets CurrentState.Host. We need a feedback loop that sets
	// the CurrentState.Host and Status fields. Here we pretend that reality perfectly
	// matches our desires.
	pod.CurrentState.Host = pod.DesiredState.Host
	return &pod, nil
}
開發者ID:linuxwhy,項目名稱:kubernetes,代碼行數:12,代碼來源:etcd.go

示例11: GetService

// GetService obtains a Service specified by its name.
func (r *Registry) GetService(ctx api.Context, name string) (*api.Service, error) {
	key, err := makeServiceKey(ctx, name)
	if err != nil {
		return nil, err
	}
	var svc api.Service
	err = r.Get(key, &svc, false)
	if err != nil {
		return nil, etcderr.InterpretGetError(err, "service", name)
	}
	return &svc, nil
}
開發者ID:Ima8,項目名稱:kubernetes,代碼行數:13,代碼來源:etcd.go

示例12: GetRoute

// GetRoute gets a specific Route specified by its ID.
func (registry *Etcd) GetRoute(ctx kapi.Context, routeID string) (*api.Route, error) {
	route := api.Route{}
	key, err := makeRouteKey(ctx, routeID)
	if err != nil {
		return nil, err
	}
	err = registry.Get(key, &route, false)
	if err != nil {
		return nil, etcderr.InterpretGetError(err, "route", routeID)
	}
	return &route, nil
}
開發者ID:dustintownsend,項目名稱:origin,代碼行數:13,代碼來源:etcd.go

示例13: GetBuildConfig

// GetBuildConfig gets a specific BuildConfig specified by its ID.
func (r *Etcd) GetBuildConfig(ctx kapi.Context, id string) (*api.BuildConfig, error) {
	var config api.BuildConfig
	key, err := makeBuildConfigKey(ctx, id)
	if err != nil {
		return nil, err
	}
	err = r.ExtractObj(key, &config, false)
	if err != nil {
		return nil, etcderr.InterpretGetError(err, "buildConfig", id)
	}
	return &config, nil
}
開發者ID:pombredanne,項目名稱:atomic-enterprise,代碼行數:13,代碼來源:etcd.go

示例14: GetBuild

// GetBuild gets a specific Build specified by its ID.
func (r *Etcd) GetBuild(ctx kapi.Context, id string) (*api.Build, error) {
	var build api.Build
	key, err := makeBuildKey(ctx, id)
	if err != nil {
		return nil, err
	}
	err = r.ExtractObj(key, &build, false)
	if err != nil {
		return nil, etcderr.InterpretGetError(err, "build", id)
	}
	setDuration(&build)
	return &build, nil
}
開發者ID:pombredanne,項目名稱:atomic-enterprise,代碼行數:14,代碼來源:etcd.go

示例15: Refresh

// Refresh reloads the RangeAllocation from etcd.
func (e *Etcd) Refresh() (*api.RangeAllocation, error) {
	e.lock.Lock()
	defer e.lock.Unlock()

	existing := &api.RangeAllocation{}
	if err := e.helper.ExtractObj(e.baseKey, existing, false); err != nil {
		if tools.IsEtcdNotFound(err) {
			return nil, nil
		}
		return nil, etcderr.InterpretGetError(err, e.kind, "")
	}

	return existing, nil
}
開發者ID:chenzhen411,項目名稱:kubernetes,代碼行數:15,代碼來源:etcd.go


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