Skip to content

Commit

Permalink
Return apierrors NotFound when object not found
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Dec 15, 2017
1 parent 7bd0a6a commit 65aea59
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
10 changes: 8 additions & 2 deletions pkg/client/simple/vfsclientset/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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..
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/simple/vfsclientset/commonvfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/client/simple/vfsclientset/federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/client/simple/vfsclientset/instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 65aea59

Please sign in to comment.