MCPcopy
hub / github.com/fluid-cloudnative/fluid / FromRawToObject

Function FromRawToObject

pkg/utils/raw.go:58–86  ·  view source on GitHub ↗

FromRawToObject is used to convert from raw to the runtime object

(raw []byte)

Source from the content-addressed store, hash-verified

56
57// FromRawToObject is used to convert from raw to the runtime object
58func FromRawToObject(raw []byte) (obj runtime.Object, err error) {
59 json, err := yaml.ToJSON(raw)
60 if err != nil {
61 return
62 }
63
64 obj, err = runtime.Decode(unstructured.UnstructuredJSONScheme, json)
65 if err != nil {
66 return
67 }
68 unstructured, ok := obj.(*unstructured.Unstructured)
69 if !ok {
70 err = fmt.Errorf("unstructured.Unstructured expected")
71 return
72 }
73
74 gvk := schema.FromAPIVersionAndKind(unstructured.GetAPIVersion(), unstructured.GroupVersionKind().Kind)
75 typedObj, err := injectScheme.New(gvk)
76 if err == nil {
77 if err = yaml.Unmarshal(raw, typedObj); err != nil {
78 return nil, err
79 }
80 return typedObj, err
81 } else if runtime.IsNotRegisteredError(err) {
82 return unstructured, nil
83 }
84
85 return
86}

Callers 2

injectMethod · 0.92
TestFromRawToObjectFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestFromRawToObjectFunction · 0.68