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) }
func fakeUnjoinHostFactory(name string) cmdutil.Factory { urlPrefix := "/api/v1/namespaces/federation-system/secrets/" f, tf, codec, _ := cmdtesting.NewAPIFactory() ns := dynamic.ContentConfig().NegotiatedSerializer tf.ClientConfig = kubefedtesting.DefaultClientConfig() tf.Client = &fake.RESTClient{ NegotiatedSerializer: ns, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { switch p, m := req.URL.Path, req.Method; { case strings.HasPrefix(p, urlPrefix) && m == http.MethodDelete: got := strings.TrimPrefix(p, urlPrefix) if got != name { return nil, errors.NewNotFound(api.Resource("secrets"), got) } status := metav1.Status{ Status: "Success", } return &http.Response{StatusCode: http.StatusOK, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &status)}, nil default: return nil, fmt.Errorf("unexpected request: %#v\n%#v", req.URL, req) } }), } return f }
func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) { rc, err := (*r.registry).GetController(ctx, name, &metav1.GetOptions{}) if err != nil { return nil, false, errors.NewNotFound(extensions.Resource("replicationcontrollers/scale"), name) } oldScale := scaleFromRC(rc) obj, err := objInfo.UpdatedObject(ctx, oldScale) if obj == nil { return nil, false, errors.NewBadRequest(fmt.Sprintf("nil update passed to Scale")) } scale, ok := obj.(*extensions.Scale) if !ok { return nil, false, errors.NewBadRequest(fmt.Sprintf("wrong object passed to Scale update: %v", obj)) } if errs := extvalidation.ValidateScale(scale); len(errs) > 0 { return nil, false, errors.NewInvalid(extensions.Kind("Scale"), scale.Name, errs) } rc.Spec.Replicas = scale.Spec.Replicas rc.ResourceVersion = scale.ResourceVersion rc, err = (*r.registry).UpdateController(ctx, rc) if err != nil { return nil, false, errors.NewConflict(extensions.Resource("replicationcontrollers/scale"), scale.Name, err) } return scaleFromRC(rc), false, nil }
// NewNotFound is a utility function to return a well-formatted admission control error response func NewNotFound(a Attributes) error { name, resource, err := extractResourceName(a) if err != nil { return apierrors.NewInternalError(err) } return apierrors.NewNotFound(resource, name) }
func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (runtime.Object, error) { rc, err := (*r.registry).GetController(ctx, name, options) if err != nil { return nil, errors.NewNotFound(extensions.Resource("replicationcontrollers/scale"), name) } return scaleFromRC(rc), nil }
func runAppArmorTest(f *framework.Framework, shouldRun bool, profile string) v1.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(v1.SingleObject(metav1.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(schema.GroupResource{Resource: "pods"}, pod.Name) } switch t := e.Object.(type) { case *v1.Pod: if t.Status.Reason == "AppArmor" { return true, nil } } return false, nil }) framework.ExpectNoError(err) } p, err := f.PodClient().Get(pod.Name, metav1.GetOptions{}) framework.ExpectNoError(err) return p.Status }
func (c *fakeDiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error) { c.resourceCalls = c.resourceCalls + 1 if groupVersion == "a/v1" { return &metav1.APIResourceList{}, nil } return nil, errors.NewNotFound(schema.GroupResource{}, "") }
// existingController verifies if the controller already exists func (r *RollingUpdater) existingController(controller *api.ReplicationController) (*api.ReplicationController, error) { // without rc name but generate name, there's no existing rc if len(controller.Name) == 0 && len(controller.GenerateName) > 0 { return nil, errors.NewNotFound(api.Resource("replicationcontrollers"), controller.Name) } // controller name is required to get rc back return r.rcClient.ReplicationControllers(controller.Namespace).Get(controller.Name, metav1.GetOptions{}) }
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 }
// Get retrieves the Endpoints from the indexer for a given namespace and name. func (s endpointsNamespaceLister) Get(name string) (*api.Endpoints, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(api.Resource("endpoints"), name) } return obj.(*api.Endpoints), nil }
func (s storePodsNamespacer) Get(name string) (*v1.Pod, error) { obj, exists, err := s.Indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(api.Resource("pod"), name) } return obj.(*v1.Pod), nil }
func waitForPodTerminated(podClient coreclient.PodsGetter, ns, name string, out io.Writer, quiet bool) (*api.Pod, error) { pod, err := waitForPod(podClient, ns, name, conditions.PodCompleted) // fix generic not found error with empty name in PodCompleted if err != nil && errors.IsNotFound(err) { return nil, errors.NewNotFound(api.Resource("pods"), name) } return pod, err }
// InterpretGetError converts a generic error on a retrieval // operation into the appropriate API error. func InterpretGetError(err error, qualifiedResource schema.GroupResource, name string) error { switch { case storage.IsNotFound(err): return errors.NewNotFound(qualifiedResource, name) case storage.IsUnreachable(err): return errors.NewServerTimeout(qualifiedResource, "get", 2) // TODO: make configurable or handled at a higher level default: return err } }
// Get retrieves the Role from the indexer for a given namespace and name. func (s roleNamespaceLister) Get(name string) (*v1beta1.Role, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(rbac.Resource("role"), name) } return obj.(*v1beta1.Role), nil }
// Get retrieves the PodTemplate from the indexer for a given namespace and name. func (s podTemplateNamespaceLister) Get(name string) (*v1.PodTemplate, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(api.Resource("podtemplate"), name) } return obj.(*v1.PodTemplate), nil }
// Get retrieves the LimitRange from the indexer for a given namespace and name. func (s limitRangeNamespaceLister) Get(name string) (*api.LimitRange, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(api.Resource("limitrange"), name) } return obj.(*api.LimitRange), nil }
// Get retrieves the Deployment from the indexer for a given namespace and name. func (s deploymentNamespaceLister) Get(name string) (*v1beta1.Deployment, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(extensions.Resource("deployment"), name) } return obj.(*v1beta1.Deployment), nil }
// Get retrieves the LocalSubjectAccessReview from the indexer for a given namespace and name. func (s localSubjectAccessReviewNamespaceLister) Get(name string) (*v1beta1.LocalSubjectAccessReview, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(authorization.Resource("localsubjectaccessreview"), name) } return obj.(*v1beta1.LocalSubjectAccessReview), nil }
// Get retrieves the ReplicationController from the indexer for a given namespace and name. func (s replicationControllerNamespaceLister) Get(name string) (*v1.ReplicationController, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(api.Resource("replicationcontroller"), name) } return obj.(*v1.ReplicationController), nil }
// Get retrieves the HorizontalPodAutoscaler from the indexer for a given namespace and name. func (s horizontalPodAutoscalerNamespaceLister) Get(name string) (*autoscaling.HorizontalPodAutoscaler, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(autoscaling.Resource("horizontalpodautoscaler"), name) } return obj.(*autoscaling.HorizontalPodAutoscaler), nil }
// Get retrieves the Job from the indexer for a given namespace and name. func (s jobNamespaceLister) Get(name string) (*batch.Job, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(batch.Resource("job"), name) } return obj.(*batch.Job), nil }
// Get retrieves the ReplicaSet from the indexer for a given namespace and name. func (s replicaSetNamespaceLister) 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 }
// Get retrieves the Secret from the indexer for a given namespace and name. func (s secretNamespaceLister) Get(name string) (*v1.Secret, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(api.Resource("secret"), name) } return obj.(*v1.Secret), nil }
// Get retrieves the ConfigMap from the indexer for a given namespace and name. func (s configMapNamespaceLister) Get(name string) (*api.ConfigMap, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(api.Resource("configmap"), name) } return obj.(*api.ConfigMap), nil }
// Get retrieves the PersistentVolumeClaim from the indexer for a given namespace and name. func (s persistentVolumeClaimNamespaceLister) Get(name string) (*v1.PersistentVolumeClaim, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(api.Resource("persistentvolumeclaim"), name) } return obj.(*v1.PersistentVolumeClaim), nil }
func (s *genericNamespaceLister) Get(name string) (runtime.Object, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(s.resource, name) } return obj.(runtime.Object), nil }
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 }
// Get retrieves the Ingress from the indexer for a given namespace and name. func (s ingressNamespaceLister) Get(name string) (*extensions.Ingress, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(extensions.Resource("ingress"), name) } return obj.(*extensions.Ingress), nil }
// Get retrieves the Eviction from the indexer for a given namespace and name. func (s evictionNamespaceLister) Get(name string) (*policy.Eviction, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(policy.Resource("eviction"), name) } return obj.(*policy.Eviction), nil }
// Get retrieves the PodDisruptionBudget from the indexer for a given namespace and name. func (s podDisruptionBudgetNamespaceLister) Get(name string) (*v1alpha1.PodDisruptionBudget, error) { obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) if err != nil { return nil, err } if !exists { return nil, errors.NewNotFound(policy.Resource("poddisruptionbudget"), name) } return obj.(*v1alpha1.PodDisruptionBudget), nil }