}
// DecodeYAML reads a YAMl file to extract the Kubernetes object definition
-var DecodeYAML = func(path string, into runtime.Object) (runtime.Object, error) {
+func DecodeYAML(path string, into runtime.Object) (runtime.Object, error) {
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return nil, pkgerrors.New("File " + path + " not found")
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
- "k8s.io/client-go/kubernetes/scheme"
utils "k8splugin/internal"
"k8splugin/internal/app"
}
//Decode the yaml file to create a runtime.Object
- obj, err := utils.DecodeYAML(yamlFilePath, nil)
- if err != nil {
- return "", pkgerrors.Wrap(err, "Decode deployment object error")
- }
-
- //Convert the runtime.Object to an unstructured Object
unstruct := &unstructured.Unstructured{}
- err = scheme.Scheme.Convert(obj, unstruct, nil)
+ //Ignore the returned obj as we expect the data in unstruct
+ _, err := utils.DecodeYAML(yamlFilePath, unstruct)
if err != nil {
- return "", pkgerrors.Wrap(err, "Converting to unstructured object")
+ return "", pkgerrors.Wrap(err, "Decode deployment object error")
}
dynClient := client.GetDynamicClient()