diff options
author | Victor Morales <victor.morales@intel.com> | 2018-09-21 14:58:25 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-21 14:58:25 +0000 |
commit | 655dfbea5a836f83a46e5e5d038f0d4180803ee7 (patch) | |
tree | 87f4f2b4daf739f71f5da842857a8e9ea62a74eb /src/k8splugin/krd | |
parent | f5972d3c34b070d55300e2e1ace7b98b5065a3f0 (diff) | |
parent | 05274b1b149139d91445ca10a73defe41f14824a (diff) |
Merge "Add UTs to plugins"
Diffstat (limited to 'src/k8splugin/krd')
-rw-r--r-- | src/k8splugin/krd/plugins.go | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/src/k8splugin/krd/plugins.go b/src/k8splugin/krd/plugins.go index 612e3f6b..41b83226 100644 --- a/src/k8splugin/krd/plugins.go +++ b/src/k8splugin/krd/plugins.go @@ -14,31 +14,46 @@ limitations under the License. package krd import ( + "io/ioutil" + "log" + "os" "plugin" - appsV1 "k8s.io/api/apps/v1" - coreV1 "k8s.io/api/core/v1" - "k8s.io/client-go/kubernetes" + pkgerrors "github.com/pkg/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/kubernetes/scheme" ) // LoadedPlugins stores references to the stored plugins var LoadedPlugins = map[string]*plugin.Plugin{} -// KubeResourceClient has the signature methods to create Kubernetes reources -type KubeResourceClient interface { - CreateResource(GenericKubeResourceData, *kubernetes.Clientset) (string, error) - ListResources(string, string) (*[]string, error) - DeleteResource(string, string, *kubernetes.Clientset) error - GetResource(string, string, *kubernetes.Clientset) (string, error) +const ResourcesListLimit = 10 + +// ResourceData stores all supported Kubernetes plugin types +type ResourceData struct { + YamlFilePath string + Namespace string + VnfId string } -// GenericKubeResourceData stores all supported Kubernetes plugin types -type GenericKubeResourceData struct { - YamlFilePath string - Namespace string - InternalVNFID string +// DecodeYAML reads a YAMl file to extract the Kubernetes object definition +var DecodeYAML = func(path string) (runtime.Object, error) { + if _, err := os.Stat(path); os.IsNotExist(err) { + return nil, pkgerrors.New("File " + path + " not found") + } + + log.Println("Reading deployment YAML") + rawBytes, err := ioutil.ReadFile(path) + if err != nil { + return nil, pkgerrors.Wrap(err, "Deployment YAML file read error") + } + + log.Println("Decoding deployment YAML") + decode := scheme.Codecs.UniversalDeserializer().Decode + obj, _, err := decode(rawBytes, nil, nil) + if err != nil { + return nil, pkgerrors.Wrap(err, "Deserialize deployment error") + } - // Add additional Kubernetes plugins below kinds - DeploymentData *appsV1.Deployment - ServiceData *coreV1.Service + return obj, nil } |