Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
Fix not returning errors from mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
liztio committed Jul 15, 2019
1 parent 0e7a0bf commit d39da20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
20 changes: 10 additions & 10 deletions cmd/capdctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,8 @@ func NewAPIHelper(cfg *rest.Config) (*APIHelper, error) {
}
mapper := restmapper.NewDiscoveryRESTMapper(groupResources)

client, err := rest.RESTClientFor(cfg)
if err != nil {
return nil, errors.Wrap(err, "failed to create REST client")
}

return &APIHelper{
client,
discover.RESTClient(),
mapper,
}, nil
}
Expand All @@ -243,10 +238,15 @@ func (a *APIHelper) Create(obj runtime.Object) error {
return errors.Wrap(err, "couldn't create accessor")
}

mapping, err := a.mapper.RESTMapping(
obj.GetObjectKind().GroupVersionKind().GroupKind(),
obj.GetObjectKind().GroupVersionKind().Version,
)
gvk := obj.GetObjectKind().GroupVersionKind()

mapping, err := a.mapper.RESTMapping(gvk.GroupKind(), gvk.Version)

if err != nil {
return errors.Wrapf(err, "failed to retrieve mapping for %s %s", gvk.String(), accessor.GetName())
}

fmt.Printf("Creating %s %s\n", gvk.String(), accessor.GetName())

_, err = resource.NewHelper(a.client, mapping).Create(accessor.GetNamespace(), true, obj, nil)
return errors.Wrapf(err, "failed to create object %q", accessor.GetName())
Expand Down
5 changes: 1 addition & 4 deletions objects/capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ func getCAPIYAML(version, capiImage string) (io.Reader, error) {
}
}
}
s := buf.String()
fmt.Printf("<<<<<<>>>>>>\n%s\n<<<<<<<<<>>>>>>>>\n", s)

return strings.NewReader(s), nil
return &buf, nil
}

func decodeCAPIObjects(yaml io.Reader) ([]runtime.Object, error) {
Expand Down

0 comments on commit d39da20

Please sign in to comment.