mirror of
https://github.com/paralus/paralus.git
synced 2026-03-05 10:30:25 +00:00
44 lines
796 B
Go
44 lines
796 B
Go
package util
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/RafaySystems/rcloud-base/components/common/pkg/controller/scheme"
|
|
|
|
apiv2 "github.com/RafaySystems/rcloud-base/components/common/proto/types/controller"
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"sigs.k8s.io/yaml"
|
|
)
|
|
|
|
func loadRuntimeObject(path string) runtime.Object {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
yb, err := ioutil.ReadAll(f)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
jb, err := yaml.YAMLToJSON(yb)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
var so apiv2.StepObject
|
|
err = json.Unmarshal(jb, &so)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
o, _, err := scheme.Serializer.Decode(so.Raw, nil, &unstructured.Unstructured{})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return o
|
|
}
|