Merge pull request #3981 from justinsb/return_not_found_error

Automatic merge from submit-queue.

Return apierrors NotFound when object not found
This commit is contained in:
Kubernetes Submit Queue 2017-12-15 15:05:46 -08:00 committed by GitHub
commit ce7fe5142c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 9 deletions

View File

@ -52,8 +52,14 @@ func (c *ClusterVFS) Get(name string, options metav1.GetOptions) (*api.Cluster,
if options.ResourceVersion != "" { if options.ResourceVersion != "" {
return nil, fmt.Errorf("ResourceVersion not supported in ClusterVFS::Get") return nil, fmt.Errorf("ResourceVersion not supported in ClusterVFS::Get")
} }
// TODO: Return not found o, err := c.find(name)
return c.find(name) if err != nil {
return nil, err
}
if o == nil {
return nil, errors.NewNotFound(schema.GroupResource{Group: api.GroupName, Resource: "Cluster"}, name)
}
return o, nil
} }
// Deprecated, but we need this for now.. // Deprecated, but we need this for now..

View File

@ -63,7 +63,7 @@ func (c *commonVFS) init(kind string, basePath vfs.Path, storeVersion runtime.Gr
c.basePath = basePath c.basePath = basePath
} }
func (c *commonVFS) get(name string) (runtime.Object, error) { func (c *commonVFS) find(name string) (runtime.Object, error) {
o, err := c.readConfig(c.basePath.Join(name)) o, err := c.readConfig(c.basePath.Join(name))
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
@ -240,7 +240,7 @@ func (c *commonVFS) readAll(items interface{}) (interface{}, error) {
} }
for _, name := range names { for _, name := range names {
o, err := c.get(name) o, err := c.find(name)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -19,8 +19,10 @@ package vfsclientset
import ( import (
"fmt" "fmt"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
api "k8s.io/kops/pkg/apis/kops" api "k8s.io/kops/pkg/apis/kops"
@ -52,12 +54,12 @@ func (c *FederationVFS) Get(name string, options metav1.GetOptions) (*api.Federa
if options.ResourceVersion != "" { if options.ResourceVersion != "" {
return nil, fmt.Errorf("ResourceVersion not supported in FederationVFS::Get") return nil, fmt.Errorf("ResourceVersion not supported in FederationVFS::Get")
} }
o, err := c.get(name) o, err := c.find(name)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if o == nil { if o == nil {
return nil, nil return nil, errors.NewNotFound(schema.GroupResource{Group: api.GroupName, Resource: "Federation"}, name)
} }
return o.(*api.Federation), nil return o.(*api.Federation), nil
} }

View File

@ -20,8 +20,10 @@ import (
"fmt" "fmt"
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
"k8s.io/kops/pkg/apis/kops" "k8s.io/kops/pkg/apis/kops"
@ -94,14 +96,13 @@ func (c *InstanceGroupVFS) Get(name string, options metav1.GetOptions) (*api.Ins
return nil, fmt.Errorf("ResourceVersion not supported in InstanceGroupVFS::Get") return nil, fmt.Errorf("ResourceVersion not supported in InstanceGroupVFS::Get")
} }
o, err := c.get(name) o, err := c.find(name)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if o == nil { if o == nil {
return nil, nil return nil, errors.NewNotFound(schema.GroupResource{Group: api.GroupName, Resource: "InstanceGroup"}, name)
} }
ig := o.(*api.InstanceGroup) ig := o.(*api.InstanceGroup)
c.addLabels(ig) c.addLabels(ig)