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


Golang apiserver.NewNotFoundErr函數代碼示例

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


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

示例1: TestGetEndpointsMissingService

func TestGetEndpointsMissingService(t *testing.T) {
	registry := &registrytest.ServiceRegistry{
		Err: apiserver.NewNotFoundErr("service", "foo"),
	}
	storage := NewStorage(registry)

	// returns service not found
	_, err := storage.Get("foo")
	if !apiserver.IsNotFound(err) || !reflect.DeepEqual(err, apiserver.NewNotFoundErr("service", "foo")) {
		t.Errorf("expected NotFound error, got %#v", err)
	}

	// returns empty endpoints
	registry.Err = nil
	registry.Service = &api.Service{
		JSONBase: api.JSONBase{ID: "foo"},
	}
	obj, err := storage.Get("foo")
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if obj.(*api.Endpoints).Endpoints != nil {
		t.Errorf("unexpected endpoints: %#v", obj)
	}
}
開發者ID:nvdnkpr,項目名稱:kubernetes,代碼行數:25,代碼來源:storage_test.go

示例2: DeletePod

// DeletePod deletes an existing pod specified by its ID.
func (registry *EtcdRegistry) DeletePod(podID string) error {
	var pod api.Pod
	podKey := makePodKey(podID)
	err := registry.helper.ExtractObj(podKey, &pod, false)
	if tools.IsEtcdNotFound(err) {
		return apiserver.NewNotFoundErr("pod", podID)
	}
	if err != nil {
		return err
	}

	// First delete the pod, so a scheduler doesn't notice it getting removed from the
	// machine and attempt to put it somewhere.
	err = registry.helper.Delete(podKey, true)
	if tools.IsEtcdNotFound(err) {
		return apiserver.NewNotFoundErr("pod", podID)
	}
	if err != nil {
		return err
	}

	machine := pod.DesiredState.Host
	if machine == "" {
		// Pod was never scheduled anywhere, just return.
		return nil
	}

	// Next, remove the pod from the machine atomically.
	contKey := makeContainerKey(machine)
	return registry.helper.AtomicUpdate(contKey, &api.ContainerManifestList{}, func(in interface{}) (interface{}, error) {
		manifests := in.(*api.ContainerManifestList)
		newManifests := make([]api.ContainerManifest, 0, len(manifests.Items))
		found := false
		for _, manifest := range manifests.Items {
			if manifest.ID != podID {
				newManifests = append(newManifests, manifest)
			} else {
				found = true
			}
		}
		if !found {
			// This really shouldn't happen, it indicates something is broken, and likely
			// there is a lost pod somewhere.
			// However it is "deleted" so log it and move on
			glog.Infof("Couldn't find: %s in %#v", podID, manifests)
		}
		manifests.Items = newManifests
		return manifests, nil
	})
}
開發者ID:kei-yamazaki,項目名稱:kubernetes,代碼行數:51,代碼來源:etcdregistry.go

示例3: deletePodFromMachine

func (registry *EtcdRegistry) deletePodFromMachine(machine, podID string) error {
	// First delete the pod, so a scheduler doesn't notice it getting removed from the
	// machine and attempt to put it somewhere.
	podKey := makePodKey(machine, podID)
	_, err := registry.etcdClient.Delete(podKey, true)
	if tools.IsEtcdNotFound(err) {
		return apiserver.NewNotFoundErr("pod", podID)
	}
	if err != nil {
		return err
	}

	// Next, remove the pod from the machine atomically.
	contKey := makeContainerKey(machine)
	return registry.helper().AtomicUpdate(contKey, &[]api.ContainerManifest{}, func(in interface{}) (interface{}, error) {
		manifests := *in.(*[]api.ContainerManifest)
		newManifests := make([]api.ContainerManifest, 0, len(manifests))
		found := false
		for _, manifest := range manifests {
			if manifest.ID != podID {
				newManifests = append(newManifests, manifest)
			} else {
				found = true
			}
		}
		if !found {
			// This really shouldn't happen, it indicates something is broken, and likely
			// there is a lost pod somewhere.
			// However it is "deleted" so log it and move on
			glog.Infof("Couldn't find: %s in %#v", podID, manifests)
		}
		return newManifests, nil
	})
}
開發者ID:nqn,項目名稱:kubernetes,代碼行數:34,代碼來源:etcd_registry.go

示例4: DeleteController

func (registry *MemoryRegistry) DeleteController(controllerID string) error {
	if _, ok := registry.controllerData[controllerID]; !ok {
		return apiserver.NewNotFoundErr("replicationController", controllerID)
	}
	delete(registry.controllerData, controllerID)
	return nil
}
開發者ID:Barba-studio,項目名稱:kubernetes,代碼行數:7,代碼來源:memory_registry.go

示例5: DeletePod

func (registry *MemoryRegistry) DeletePod(podID string) error {
	if _, ok := registry.podData[podID]; !ok {
		return apiserver.NewNotFoundErr("pod", podID)
	}
	delete(registry.podData, podID)
	return nil
}
開發者ID:Barba-studio,項目名稱:kubernetes,代碼行數:7,代碼來源:memory_registry.go

示例6: UpdatePod

func (registry *MemoryRegistry) UpdatePod(pod api.Pod) error {
	if _, ok := registry.podData[pod.ID]; !ok {
		return apiserver.NewNotFoundErr("pod", pod.ID)
	}
	registry.podData[pod.ID] = pod
	return nil
}
開發者ID:Barba-studio,項目名稱:kubernetes,代碼行數:7,代碼來源:memory_registry.go

示例7: DeleteService

func (registry *MemoryRegistry) DeleteService(name string) error {
	if _, ok := registry.serviceData[name]; !ok {
		return apiserver.NewNotFoundErr("service", name)
	}
	delete(registry.serviceData, name)
	return nil
}
開發者ID:Barba-studio,項目名稱:kubernetes,代碼行數:7,代碼來源:memory_registry.go

示例8: UpdateController

func (registry *MemoryRegistry) UpdateController(controller api.ReplicationController) error {
	if _, ok := registry.controllerData[controller.ID]; !ok {
		return apiserver.NewNotFoundErr("replicationController", controller.ID)
	}
	registry.controllerData[controller.ID] = controller
	return nil
}
開發者ID:Barba-studio,項目名稱:kubernetes,代碼行數:7,代碼來源:memory_registry.go

示例9: GetService

// GetService returns an *api.Service for the named service.
// It returns an error if the service is not found in the registry.
func (r *Registry) GetService(name string) (*api.Service, error) {
	svc, found := r.serviceData[name]
	if !found {
		return nil, apiserver.NewNotFoundErr("service", name)
	}
	return &svc, nil
}
開發者ID:GoogleButtPlatform,項目名稱:kubernetes,代碼行數:9,代碼來源:memory.go

示例10: GetController

func (registry *MemoryRegistry) GetController(controllerID string) (*api.ReplicationController, error) {
	controller, found := registry.controllerData[controllerID]
	if found {
		return &controller, nil
	} else {
		return nil, apiserver.NewNotFoundErr("replicationController", controllerID)
	}
}
開發者ID:Barba-studio,項目名稱:kubernetes,代碼行數:8,代碼來源:memory_registry.go

示例11: GetPod

func (registry *MemoryRegistry) GetPod(podID string) (*api.Pod, error) {
	pod, found := registry.podData[podID]
	if found {
		return &pod, nil
	} else {
		return nil, apiserver.NewNotFoundErr("pod", podID)
	}
}
開發者ID:Barba-studio,項目名稱:kubernetes,代碼行數:8,代碼來源:memory_registry.go

示例12: DeleteController

// DeleteController deletes a ReplicationController specified by its ID.
func (registry *EtcdRegistry) DeleteController(controllerID string) error {
	key := makeControllerKey(controllerID)
	_, err := registry.etcdClient.Delete(key, false)
	if tools.IsEtcdNotFound(err) {
		return apiserver.NewNotFoundErr("replicationController", controllerID)
	}
	return err
}
開發者ID:jamesblunt,項目名稱:kubernetes,代碼行數:9,代碼來源:etcd_registry.go

示例13: GetService

func (registry *MemoryRegistry) GetService(name string) (*api.Service, error) {
	svc, found := registry.serviceData[name]
	if found {
		return &svc, nil
	} else {
		return nil, apiserver.NewNotFoundErr("service", name)
	}
}
開發者ID:Barba-studio,項目名稱:kubernetes,代碼行數:8,代碼來源:memory_registry.go

示例14: 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 tools.IsEtcdNotFound(err) {
		return nil, apiserver.NewNotFoundErr("endpoints", name)
	}
	if err != nil {
		return nil, err
	}
	return &endpoints, nil
}
開發者ID:nvdnkpr,項目名稱:kubernetes,代碼行數:13,代碼來源:etcd.go

示例15: GetService

// GetService obtains a Service specified by its name.
func (registry *EtcdRegistry) GetService(name string) (*api.Service, error) {
	key := makeServiceKey(name)
	var svc api.Service
	err := registry.helper().ExtractObj(key, &svc, false)
	if tools.IsEtcdNotFound(err) {
		return nil, apiserver.NewNotFoundErr("service", name)
	}
	if err != nil {
		return nil, err
	}
	return &svc, nil
}
開發者ID:jamesblunt,項目名稱:kubernetes,代碼行數:13,代碼來源:etcd_registry.go


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