本文整理匯總了Golang中k8s/io/client-go/pkg/api/errors.NewNotFound函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewNotFound函數的具體用法?Golang NewNotFound怎麽用?Golang NewNotFound使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewNotFound函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runAppArmorTest
func runAppArmorTest(f *framework.Framework, shouldRun bool, profile string) api.PodStatus {
pod := createPodWithAppArmor(f, profile)
if shouldRun {
// The pod needs to start before it stops, so wait for the longer start timeout.
framework.ExpectNoError(framework.WaitTimeoutForPodNoLongerRunningInNamespace(
f.ClientSet, pod.Name, f.Namespace.Name, "", framework.PodStartTimeout))
} else {
// Pod should remain in the pending state. Wait for the Reason to be set to "AppArmor".
w, err := f.PodClient().Watch(api.SingleObject(api.ObjectMeta{Name: pod.Name}))
framework.ExpectNoError(err)
_, err = watch.Until(framework.PodStartTimeout, w, func(e watch.Event) (bool, error) {
switch e.Type {
case watch.Deleted:
return false, errors.NewNotFound(unversioned.GroupResource{Resource: "pods"}, pod.Name)
}
switch t := e.Object.(type) {
case *api.Pod:
if t.Status.Reason == "AppArmor" {
return true, nil
}
}
return false, nil
})
framework.ExpectNoError(err)
}
p, err := f.PodClient().Get(pod.Name)
framework.ExpectNoError(err)
return p.Status
}
示例2: Delete
func (t *tracker) Delete(gvk schema.GroupVersionKind, ns, name string) error {
if err := checkNamespace(gvk, ns); err != nil {
return err
}
t.lock.Lock()
defer t.lock.Unlock()
found := false
for i, existingObj := range t.objects[gvk] {
objMeta, err := meta.Accessor(existingObj)
if err != nil {
return err
}
if objMeta.GetNamespace() == ns && objMeta.GetName() == name {
t.objects[gvk] = append(t.objects[gvk][:i], t.objects[gvk][i+1:]...)
found = true
break
}
}
if found {
return nil
}
return errors.NewNotFound(schema.GroupResource{Group: gvk.Group, Resource: gvk.Kind}, name)
}
示例3: Get
func (s storeReplicaSetsNamespacer) Get(name string) (*extensions.ReplicaSet, error) {
obj, exists, err := s.Indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(extensions.Resource("replicaset"), name)
}
return obj.(*extensions.ReplicaSet), nil
}
示例4: Get
func (s clusterRoleLister) Get(name string) (*rbac.ClusterRole, error) {
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(rbac.Resource("clusterrole"), name)
}
return obj.(*rbac.ClusterRole), nil
}
示例5: Get
func (i *IndexerToNamespaceLister) Get(name string) (*v1.Namespace, error) {
obj, exists, err := i.Indexer.GetByKey(name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(api.Resource("namespace"), name)
}
return obj.(*v1.Namespace), nil
}
示例6: Get
func (s storeDeploymentsNamespacer) Get(name string) (*extensions.Deployment, error) {
obj, exists, err := s.Indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(extensionsinternal.Resource("deployment"), name)
}
return obj.(*extensions.Deployment), nil
}
示例7: ServerResourcesForGroupVersion
func (c *fakeCachedDiscoveryInterface) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error) {
if c.enabledA && groupVersion == "a/v1" {
return &metav1.APIResourceList{
GroupVersion: "a/v1",
APIResources: []metav1.APIResource{
{
Name: "foo",
Kind: "Foo",
Namespaced: false,
},
},
}, nil
}
return nil, errors.NewNotFound(schema.GroupResource{}, "")
}
示例8: Get
func (t *tracker) Get(gvk schema.GroupVersionKind, ns, name string) (runtime.Object, error) {
if err := checkNamespace(gvk, ns); err != nil {
return nil, err
}
errNotFound := errors.NewNotFound(schema.GroupResource{Group: gvk.Group, Resource: gvk.Kind}, name)
t.lock.RLock()
defer t.lock.RUnlock()
objs, ok := t.objects[gvk]
if !ok {
return nil, errNotFound
}
matchingObjs, err := filterByNamespaceAndName(objs, ns, name)
if err != nil {
return nil, err
}
if len(matchingObjs) == 0 {
return nil, errNotFound
}
if len(matchingObjs) > 1 {
return nil, fmt.Errorf("more than one object matched gvk %s, ns: %q name: %q", gvk, ns, name)
}
// Only one object should match in the tracker if it works
// correctly, as Add/Update methods enforce kind/namespace/name
// uniqueness.
obj, err := t.scheme.Copy(matchingObjs[0])
if err != nil {
return nil, err
}
if status, ok := obj.(*metav1.Status); ok {
if status.Details != nil {
status.Details.Kind = gvk.Kind
}
if status.Status != metav1.StatusSuccess {
return nil, &errors.StatusError{ErrStatus: *status}
}
}
return obj, nil
}
示例9: add
func (t *tracker) add(obj runtime.Object, ns string, replaceExisting bool) error {
gvks, _, err := t.scheme.ObjectKinds(obj)
if err != nil {
return err
}
if len(gvks) == 0 {
return fmt.Errorf("no registered kinds for %v", obj)
}
t.lock.Lock()
defer t.lock.Unlock()
for _, gvk := range gvks {
gr := schema.GroupResource{Group: gvk.Group, Resource: gvk.Kind}
// To avoid the object from being accidentally modified by caller
// after it's been added to the tracker, we always store the deep
// copy.
obj, err = t.scheme.Copy(obj)
if err != nil {
return err
}
if status, ok := obj.(*metav1.Status); ok && status.Details != nil {
gvk.Kind = status.Details.Kind
}
newMeta, err := meta.Accessor(obj)
if err != nil {
return err
}
// Propagate namespace to the new object if hasn't already been set.
if len(newMeta.GetNamespace()) == 0 {
newMeta.SetNamespace(ns)
}
if ns != newMeta.GetNamespace() {
msg := fmt.Sprintf("request namespace does not match object namespace, request: %q object: %q", ns, newMeta.GetNamespace())
return errors.NewBadRequest(msg)
}
if err := checkNamespace(gvk, newMeta.GetNamespace()); err != nil {
return err
}
for i, existingObj := range t.objects[gvk] {
oldMeta, err := meta.Accessor(existingObj)
if err != nil {
return err
}
if oldMeta.GetNamespace() == newMeta.GetNamespace() && oldMeta.GetName() == newMeta.GetName() {
if replaceExisting {
t.objects[gvk][i] = obj
return nil
}
return errors.NewAlreadyExists(gr, newMeta.GetName())
}
}
if replaceExisting {
// Tried to update but no matching object was found.
return errors.NewNotFound(gr, newMeta.GetName())
}
t.objects[gvk] = append(t.objects[gvk], obj)
}
return nil
}
示例10: add
func (t *tracker) add(obj runtime.Object, replaceExisting bool) error {
if meta.IsListType(obj) {
return t.addList(obj, replaceExisting)
}
gvks, _, err := t.scheme.ObjectKinds(obj)
if err != nil {
return err
}
if len(gvks) == 0 {
return fmt.Errorf("no registered kinds for %v", obj)
}
t.lock.Lock()
defer t.lock.Unlock()
for _, gvk := range gvks {
gr := schema.GroupResource{Group: gvk.Group, Resource: gvk.Kind}
// To avoid the object from being accidentally modified by caller
// after it's been added to the tracker, we always store the deep
// copy.
obj, err = t.scheme.Copy(obj)
if err != nil {
return err
}
if status, ok := obj.(*metav1.Status); ok && status.Details != nil {
gvk.Kind = status.Details.Kind
}
newMeta, err := meta.Accessor(obj)
if err != nil {
return err
}
if err := checkNamespace(gvk, newMeta.GetNamespace()); err != nil {
return err
}
for i, existingObj := range t.objects[gvk] {
oldMeta, err := meta.Accessor(existingObj)
if err != nil {
return err
}
if oldMeta.GetNamespace() == newMeta.GetNamespace() && oldMeta.GetName() == newMeta.GetName() {
if replaceExisting {
t.objects[gvk][i] = obj
return nil
}
return errors.NewAlreadyExists(gr, newMeta.GetName())
}
}
if replaceExisting {
// Tried to update but no matching object was found.
return errors.NewNotFound(gr, newMeta.GetName())
}
t.objects[gvk] = append(t.objects[gvk], obj)
}
return nil
}