CreateObject attempts to create any kubernetes object.
(obj *unstructured.Unstructured)
| 71 | |
| 72 | // CreateObject attempts to create any kubernetes object. |
| 73 | func (a *APIHelper) CreateObject(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) { |
| 74 | restMapping, err := a.Mapper.RESTMapping(obj.GroupVersionKind().GroupKind(), obj.GroupVersionKind().Version) |
| 75 | if err != nil { |
| 76 | return nil, errors.Wrap(err, "could not get restMapping") |
| 77 | } |
| 78 | name, err := a.Accessor.Name(obj) |
| 79 | if err != nil { |
| 80 | return nil, errors.Wrap(err, "could not get name for object") |
| 81 | } |
| 82 | namespace, err := a.Accessor.Namespace(obj) |
| 83 | if err != nil { |
| 84 | return nil, errors.Wrapf(err, "couldn't get namespace for object %s", name) |
| 85 | } |
| 86 | |
| 87 | rsc := a.Client.Resource(restMapping.Resource) |
| 88 | if rsc == nil { |
| 89 | return nil, errors.New("failed to get a resource interface") |
| 90 | } |
| 91 | ri := rsc.Namespace(namespace) |
| 92 | return ri.Create(context.TODO(), obj, metav1.CreateOptions{}) |
| 93 | } |
| 94 | |
| 95 | // Name returns the name of the kubernetes object. |
| 96 | func (a *APIHelper) Name(obj *unstructured.Unstructured) (string, error) { |