MCPcopy
hub / github.com/vmware-tanzu/sonobuoy / CreateObject

Method CreateObject

pkg/dynamic/client.go:73–93  ·  view source on GitHub ↗

CreateObject attempts to create any kubernetes object.

(obj *unstructured.Unstructured)

Source from the content-addressed store, hash-verified

71
72// CreateObject attempts to create any kubernetes object.
73func (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.
96func (a *APIHelper) Name(obj *unstructured.Unstructured) (string, error) {

Callers 1

TestCreateObjectFunction · 0.95

Calls 7

GroupVersionKindMethod · 0.80
ResourceMethod · 0.80
NewMethod · 0.80
CreateMethod · 0.80
RESTMappingMethod · 0.65
NameMethod · 0.65
NamespaceMethod · 0.65

Tested by 1

TestCreateObjectFunction · 0.76