本文整理汇总了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 := ®istrytest.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)
}
}
示例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
})
}
示例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
})
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
示例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)
}
}
示例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
}
示例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)
}
}
示例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
}
示例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
}