package utils

import (
	"bytes"
	"io"
	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
	"k8s.io/apimachinery/pkg/runtime"
	syaml "k8s.io/apimachinery/pkg/runtime/serializer/yaml"
	"k8s.io/apimachinery/pkg/util/yaml"
)

func StrToInfo(val string) *unstructured.Unstructured {
	d := yaml.NewYAMLOrJSONDecoder(bytes.NewBufferString(val), 4096)
	var err error

	var rawObj runtime.RawExtension
	err = d.Decode(&rawObj)
	if err == io.EOF {
	}
	if err != nil {
	}
	obj := &unstructured.Unstructured{}
	syaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(rawObj.Raw, nil, obj)

	unstructuredMap, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)

	unStructureObj := &unstructured.Unstructured{Object: unstructuredMap}
	return unStructureObj

}
