MCPcopy
hub / github.com/kubernetes/client-go / Create

Method Create

dynamic/simple.go:94–130  ·  view source on GitHub ↗
(obj *unstructured.Unstructured, opts metav1.CreateOptions, subresources ...string)

Source from the content-addressed store, hash-verified

92}
93
94func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, opts metav1.CreateOptions, subresources ...string) (*unstructured.Unstructured, error) {
95 outBytes, err := runtime.Encode(unstructured.UnstructuredJSONScheme, obj)
96 if err != nil {
97 return nil, err
98 }
99 name := ""
100 if len(subresources) > 0 {
101 accessor, err := meta.Accessor(obj)
102 if err != nil {
103 return nil, err
104 }
105 name = accessor.GetName()
106 if len(name) == 0 {
107 return nil, fmt.Errorf("name is required")
108 }
109 }
110
111 result := c.client.client.
112 Post().
113 AbsPath(append(c.makeURLSegments(name), subresources...)...).
114 Body(outBytes).
115 SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1).
116 Do()
117 if err := result.Error(); err != nil {
118 return nil, err
119 }
120
121 retBytes, err := result.Raw()
122 if err != nil {
123 return nil, err
124 }
125 uncastObj, err := runtime.Decode(unstructured.UnstructuredJSONScheme, retBytes)
126 if err != nil {
127 return nil, err
128 }
129 return uncastObj.(*unstructured.Unstructured), nil
130}
131
132func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, opts metav1.UpdateOptions, subresources ...string) (*unstructured.Unstructured, error) {
133 accessor, err := meta.Accessor(obj)

Callers

nothing calls this directly

Calls 12

makeURLSegmentsMethod · 0.95
BodyMethod · 0.80
AbsPathMethod · 0.80
RawMethod · 0.80
GetNameMethod · 0.65
ErrorfMethod · 0.65
DoMethod · 0.65
PostMethod · 0.65
ErrorMethod · 0.65
EncodeMethod · 0.45
DecodeMethod · 0.45

Tested by

no test coverage detected