Skip to content

Commit

Permalink
Use the REST mapper to get an obj's resource (#471)
Browse files Browse the repository at this point in the history
Fixes #470

Signed-off-by: Chuck Ha <chuck@heptio.com>
  • Loading branch information
chuckha authored Jul 9, 2018
1 parent 4f61a01 commit 44ad2a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/client/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (c *SonobuoyClient) Run(cfg *RunConfig) error {
return errors.Wrap(err, "could not get object namespace")
}
// err is used to determine output for user; but first extract resource
newObj, err := c.dynamicClient.CreateObject(obj)
resource, err2 := c.dynamicClient.ResourceVersion(newObj)
_, err = c.dynamicClient.CreateObject(obj)
resource, err2 := c.dynamicClient.ResourceVersion(obj)
if err2 != nil {
return errors.Wrap(err, "could not get resource of object")
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/dynamic/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,9 @@ func (a *APIHelper) Namespace(obj *unstructured.Unstructured) (string, error) {

// ResourceVersion returns the resource version of a kubernetes object.
func (a *APIHelper) ResourceVersion(obj *unstructured.Unstructured) (string, error) {
return a.Accessor.ResourceVersion(obj)
restMapping, err := a.Mapper.RESTMapping(obj.GroupVersionKind().GroupKind(), obj.GroupVersionKind().Version)
if err != nil {
return "", errors.Wrap(err, "could not get restMapping")
}
return restMapping.Resource.GroupResource().Resource, nil
}

0 comments on commit 44ad2a7

Please sign in to comment.