Return apierrors NotFound when object not found

This commit is contained in:
Justin Santa Barbara 2017-12-01 01:53:50 -05:00
parent 7bd0a6a703
commit 65aea59418
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 != "" {
return nil, fmt.Errorf("ResourceVersion not supported in ClusterVFS::Get")
}
// TODO: Return not found
return c.find(name)
o, err := 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..

View File

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

View File

@ -19,8 +19,10 @@ package vfsclientset
import (
"fmt"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
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 != "" {
return nil, fmt.Errorf("ResourceVersion not supported in FederationVFS::Get")
}
o, err := c.get(name)
o, err := c.find(name)
if err != nil {
return nil, err
}
if o == nil {
return nil, nil
return nil, errors.NewNotFound(schema.GroupResource{Group: api.GroupName, Resource: "Federation"}, name)
}
return o.(*api.Federation), nil
}

View File

@ -20,8 +20,10 @@ import (
"fmt"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
"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")
}
o, err := c.get(name)
o, err := c.find(name)
if err != nil {
return nil, err
}
if o == nil {
return nil, nil
return nil, errors.NewNotFound(schema.GroupResource{Group: api.GroupName, Resource: "InstanceGroup"}, name)
}
ig := o.(*api.InstanceGroup)
c.addLabels(ig)