Use the unstructured type for decode 83/86183/2
authorKiran Kamineni <kiran.k.kamineni@intel.com>
Wed, 24 Apr 2019 18:39:17 +0000 (11:39 -0700)
committerKiran Kamineni <kiran.k.kamineni@intel.com>
Thu, 25 Apr 2019 21:49:19 +0000 (14:49 -0700)
Use the unstructured type in the into field.
This allows us to remove the convert part of the
code and also allows decoding for CRDs.

Issue-ID: MULTICLOUD-585
Change-Id: I27ecdba7127ce63137dfbcd1c0a6938343b4e759
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
src/k8splugin/internal/utils.go
src/k8splugin/plugins/generic/plugin.go

index 7785733..681b1b5 100644 (file)
@@ -42,7 +42,7 @@ type ResourceData struct {
 }
 
 // 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")
index f3b2798..9ecaf68 100644 (file)
@@ -21,7 +21,6 @@ import (
        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"
@@ -38,16 +37,11 @@ func (g genericPlugin) Create(yamlFilePath string, namespace string, client *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()