Use a standard Go project layout 26/76326/3
authorVictor Morales <victor.morales@intel.com>
Fri, 25 Jan 2019 01:46:43 +0000 (17:46 -0800)
committerVictor Morales <victor.morales@intel.com>
Sat, 26 Jan 2019 00:52:38 +0000 (16:52 -0800)
This project wasn't following some Standard Go Project Layout
guidelines(https://github.com/golang-standards/project-layout). This
change pretends to organize the source code and following those
guidelines.

Change-Id: I61085ac20f28069cede013f83034bed06892d87c
Signed-off-by: Victor Morales <victor.morales@intel.com>
Issue-ID: MULTICLOUD-301

35 files changed:
src/k8splugin/api/api.go
src/k8splugin/api/defhandler.go
src/k8splugin/api/defhandler_test.go
src/k8splugin/api/handler.go
src/k8splugin/api/handler_test.go
src/k8splugin/api/profilehandler.go
src/k8splugin/api/profilehandler_test.go
src/k8splugin/internal/app/client.go [moved from src/k8splugin/krd/krd.go with 99% similarity]
src/k8splugin/internal/app/client_test.go [moved from src/k8splugin/krd/krd_test.go with 91% similarity]
src/k8splugin/internal/app/vnfhelper.go [moved from src/k8splugin/csar/parser.go with 92% similarity]
src/k8splugin/internal/app/vnfhelper_test.go [moved from src/k8splugin/csar/parser_test.go with 81% similarity]
src/k8splugin/internal/db/consul.go [moved from src/k8splugin/db/consul.go with 100% similarity]
src/k8splugin/internal/db/consul_test.go [moved from src/k8splugin/db/consul_test.go with 100% similarity]
src/k8splugin/internal/db/mongo.go [moved from src/k8splugin/db/mongo.go with 100% similarity]
src/k8splugin/internal/db/mongo_test.go [moved from src/k8splugin/db/mongo_test.go with 100% similarity]
src/k8splugin/internal/db/store.go [moved from src/k8splugin/db/store.go with 100% similarity]
src/k8splugin/internal/db/store_test.go [moved from src/k8splugin/db/store_test.go with 100% similarity]
src/k8splugin/internal/db/testing.go [moved from src/k8splugin/db/testing.go with 100% similarity]
src/k8splugin/internal/rb/archive.go [moved from src/k8splugin/rb/archive.go with 100% similarity]
src/k8splugin/internal/rb/archive_test.go [moved from src/k8splugin/rb/archive_test.go with 100% similarity]
src/k8splugin/internal/rb/definition.go [moved from src/k8splugin/rb/definition.go with 99% similarity]
src/k8splugin/internal/rb/definition_test.go [moved from src/k8splugin/rb/definition_test.go with 99% similarity]
src/k8splugin/internal/rb/profile.go [moved from src/k8splugin/rb/profile.go with 99% similarity]
src/k8splugin/internal/rb/profile_test.go [moved from src/k8splugin/rb/profile_test.go with 99% similarity]
src/k8splugin/internal/utils.go [moved from src/k8splugin/krd/plugins.go with 99% similarity]
src/k8splugin/internal/utils_test.go [moved from src/k8splugin/krd/plugins_test.go with 98% similarity]
src/k8splugin/mock_files/mock_plugins/mockplugin.go
src/k8splugin/plugins/deployment/plugin.go
src/k8splugin/plugins/deployment/plugin_test.go
src/k8splugin/plugins/namespace/plugin.go
src/k8splugin/plugins/namespace/plugin_test.go
src/k8splugin/plugins/network/plugin.go
src/k8splugin/plugins/network/plugin_test.go
src/k8splugin/plugins/service/plugin.go
src/k8splugin/plugins/service/plugin_test.go

index 593e2b0..f022614 100644 (file)
@@ -14,7 +14,7 @@ limitations under the License.
 package api
 
 import (
-       "k8splugin/rb"
+       "k8splugin/internal/rb"
        "os"
        "path/filepath"
        "plugin"
@@ -23,8 +23,8 @@ import (
        "github.com/gorilla/mux"
        pkgerrors "github.com/pkg/errors"
 
-       "k8splugin/db"
-       "k8splugin/krd"
+       krd "k8splugin/internal"
+       "k8splugin/internal/db"
 )
 
 // CheckEnvVariables checks for required Environment variables
index f53acdd..21e5e76 100644 (file)
@@ -19,7 +19,7 @@ package api
 import (
        "encoding/json"
        "io/ioutil"
-       "k8splugin/rb"
+       "k8splugin/internal/rb"
        "net/http"
 
        "github.com/gorilla/mux"
index e638ca0..20ef537 100644 (file)
@@ -20,7 +20,7 @@ import (
        "bytes"
        "encoding/json"
        "io"
-       "k8splugin/rb"
+       "k8splugin/internal/rb"
        "net/http"
        "net/http/httptest"
        "reflect"
index 4c49ba7..a6db3c1 100644 (file)
@@ -25,9 +25,8 @@ import (
        pkgerrors "github.com/pkg/errors"
        "k8s.io/client-go/kubernetes"
 
-       "k8splugin/csar"
-       "k8splugin/db"
-       "k8splugin/krd"
+       helper "k8splugin/internal/app"
+       "k8splugin/internal/db"
 )
 
 //TODO: Separate the http handler code and backend code out
@@ -36,7 +35,7 @@ var tagData = "data"
 
 // GetVNFClient retrieves the client used to communicate with a Kubernetes Cluster
 var GetVNFClient = func(kubeConfigPath string) (kubernetes.Clientset, error) {
-       client, err := krd.GetKubeClient(kubeConfigPath)
+       client, err := helper.GetKubeClient(kubeConfigPath)
        if err != nil {
                return client, err
        }
@@ -105,7 +104,7 @@ func CreateHandler(w http.ResponseWriter, r *http.Request) {
                },
                nil
        */
-       externalVNFID, resourceNameMap, err := csar.CreateVNF(resource.CsarID, resource.CloudRegionID, resource.Namespace, &kubeclient)
+       externalVNFID, resourceNameMap, err := helper.CreateVNF(resource.CsarID, resource.CloudRegionID, resource.Namespace, &kubeclient)
        if err != nil {
                werr := pkgerrors.Wrap(err, "Read Kubernetes Data information error")
                http.Error(w, werr.Error(), http.StatusInternalServerError)
@@ -223,7 +222,7 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
                http.Error(w, err.Error(), http.StatusInternalServerError)
                return
        }
-       err = csar.DestroyVNF(data, namespace, &kubeclient)
+       err = helper.DestroyVNF(data, namespace, &kubeclient)
        if err != nil {
                werr := pkgerrors.Wrap(err, "Delete VNF error")
                http.Error(w, werr.Error(), http.StatusInternalServerError)
index d02b851..2bac311 100644 (file)
@@ -27,8 +27,8 @@ import (
        pkgerrors "github.com/pkg/errors"
        "k8s.io/client-go/kubernetes"
 
-       "k8splugin/csar"
-       "k8splugin/db"
+       helper "k8splugin/internal/app"
+       "k8splugin/internal/db"
 )
 
 type mockCSAR struct {
@@ -155,7 +155,7 @@ func TestCreateHandler(t *testing.T) {
                                return kubernetes.Clientset{}, testCase.mockGetVNFClientErr
                        }
                        if testCase.mockCreateVNF != nil {
-                               csar.CreateVNF = testCase.mockCreateVNF.CreateVNF
+                               helper.CreateVNF = testCase.mockCreateVNF.CreateVNF
                        }
                        if testCase.mockStore != nil {
                                db.DBconn = testCase.mockStore
@@ -328,7 +328,7 @@ func TestDeleteHandler(t *testing.T) {
                                db.DBconn = testCase.mockStore
                        }
                        if testCase.mockDeleteVNF != nil {
-                               csar.DestroyVNF = testCase.mockDeleteVNF.DestroyVNF
+                               helper.DestroyVNF = testCase.mockDeleteVNF.DestroyVNF
                        }
 
                        request, _ := http.NewRequest("DELETE", "/v1/vnf_instances/cloudregion1/testnamespace/uuid1", nil)
index 1090efe..86e0d47 100644 (file)
@@ -19,7 +19,7 @@ package api
 import (
        "encoding/json"
        "io/ioutil"
-       "k8splugin/rb"
+       "k8splugin/internal/rb"
        "net/http"
 
        "github.com/gorilla/mux"
index 49efd65..7594afe 100644 (file)
@@ -20,7 +20,7 @@ import (
        "bytes"
        "encoding/json"
        "io"
-       "k8splugin/rb"
+       "k8splugin/internal/rb"
        "net/http"
        "net/http/httptest"
        "reflect"
similarity index 99%
rename from src/k8splugin/krd/krd.go
rename to src/k8splugin/internal/app/client.go
index 2d06e10..3555afd 100644 (file)
@@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package krd
+package app
 
 import (
        "errors"
similarity index 91%
rename from src/k8splugin/krd/krd_test.go
rename to src/k8splugin/internal/app/client_test.go
index ad52f7e..9d89263 100644 (file)
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package krd
+package app
 
 import (
        "reflect"
@@ -23,7 +23,7 @@ import (
 func TestGetKubeClient(t *testing.T) {
        t.Run("Successfully create Kube Client", func(t *testing.T) {
 
-               clientset, err := GetKubeClient("../mock_files/mock_configs/mock_config")
+               clientset, err := GetKubeClient("../../mock_files/mock_configs/mock_config")
                if err != nil {
                        t.Fatalf("TestGetKubeClient returned an error (%s)", err)
                }
similarity index 92%
rename from src/k8splugin/csar/parser.go
rename to src/k8splugin/internal/app/vnfhelper.go
index c0dd6a7..3deb9f2 100644 (file)
@@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package csar
+package app
 
 import (
        "encoding/hex"
@@ -25,7 +25,7 @@ import (
        pkgerrors "github.com/pkg/errors"
        yaml "gopkg.in/yaml.v2"
 
-       "k8splugin/krd"
+       utils "k8splugin/internal"
 )
 
 func generateExternalVNFID() string {
@@ -35,7 +35,7 @@ func generateExternalVNFID() string {
 }
 
 func ensuresNamespace(namespace string, kubeclient kubernetes.Interface) error {
-       namespacePlugin, ok := krd.LoadedPlugins["namespace"]
+       namespacePlugin, ok := utils.LoadedPlugins["namespace"]
        if !ok {
                return pkgerrors.New("No plugin for namespace resource found")
        }
@@ -57,11 +57,11 @@ func ensuresNamespace(namespace string, kubeclient kubernetes.Interface) error {
                if err != nil {
                        return pkgerrors.Wrap(err, "Error fetching create namespace plugin")
                }
-               namespaceResource := &krd.ResourceData{
+               namespaceResource := &utils.ResourceData{
                        Namespace: namespace,
                }
 
-               _, err = symGetNamespaceFunc.(func(*krd.ResourceData, kubernetes.Interface) (string, error))(
+               _, err = symGetNamespaceFunc.(func(*utils.ResourceData, kubernetes.Interface) (string, error))(
                        namespaceResource, kubeclient)
                if err != nil {
                        return pkgerrors.Wrap(err, "Error creating "+namespace+" namespace")
@@ -102,13 +102,13 @@ var CreateVNF = func(csarID string, cloudRegionID string, namespace string, kube
                        }
                        log.Println("Processing file: " + path)
 
-                       genericKubeData := &krd.ResourceData{
+                       genericKubeData := &utils.ResourceData{
                                YamlFilePath: path,
                                Namespace:    namespace,
                                VnfId:        internalVNFID,
                        }
 
-                       typePlugin, ok := krd.LoadedPlugins[resource]
+                       typePlugin, ok := utils.LoadedPlugins[resource]
                        if !ok {
                                return "", nil, pkgerrors.New("No plugin for resource " + resource + " found")
                        }
@@ -118,7 +118,7 @@ var CreateVNF = func(csarID string, cloudRegionID string, namespace string, kube
                                return "", nil, pkgerrors.Wrap(err, "Error fetching "+resource+" plugin")
                        }
 
-                       internalResourceName, err := symCreateResourceFunc.(func(*krd.ResourceData, kubernetes.Interface) (string, error))(
+                       internalResourceName, err := symCreateResourceFunc.(func(*utils.ResourceData, kubernetes.Interface) (string, error))(
                                genericKubeData, kubeclient)
                        if err != nil {
                                return "", nil, pkgerrors.Wrap(err, "Error in plugin "+resource+" plugin")
@@ -142,7 +142,7 @@ var DestroyVNF = func(data map[string][]string, namespace string, kubeclient *ku
        */
 
        for resourceName, resourceList := range data {
-               typePlugin, ok := krd.LoadedPlugins[resourceName]
+               typePlugin, ok := utils.LoadedPlugins[resourceName]
                if !ok {
                        return pkgerrors.New("No plugin for resource " + resourceName + " found")
                }
similarity index 81%
rename from src/k8splugin/csar/parser_test.go
rename to src/k8splugin/internal/app/vnfhelper_test.go
index 93473bc..81bea62 100644 (file)
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package csar
+package app
 
 import (
        "io/ioutil"
@@ -22,20 +22,20 @@ import (
        "plugin"
        "testing"
 
+       yaml "gopkg.in/yaml.v2"
        "k8s.io/client-go/kubernetes"
 
        pkgerrors "github.com/pkg/errors"
-       "gopkg.in/yaml.v2"
 
-       "k8splugin/krd"
+       utils "k8splugin/internal"
 )
 
 func LoadMockPlugins(krdLoadedPlugins *map[string]*plugin.Plugin) error {
-       if _, err := os.Stat("../mock_files/mock_plugins/mockplugin.so"); os.IsNotExist(err) {
+       if _, err := os.Stat("../../mock_files/mock_plugins/mockplugin.so"); os.IsNotExist(err) {
                return pkgerrors.New("mockplugin.so does not exist. Please compile mockplugin.go to generate")
        }
 
-       mockPlugin, err := plugin.Open("../mock_files/mock_plugins/mockplugin.so")
+       mockPlugin, err := plugin.Open("../../mock_files/mock_plugins/mockplugin.so")
        if err != nil {
                return pkgerrors.Cause(err)
        }
@@ -48,15 +48,15 @@ func LoadMockPlugins(krdLoadedPlugins *map[string]*plugin.Plugin) error {
 }
 
 func TestCreateVNF(t *testing.T) {
-       oldkrdPluginData := krd.LoadedPlugins
+       oldkrdPluginData := utils.LoadedPlugins
        oldReadMetadataFile := ReadMetadataFile
 
        defer func() {
-               krd.LoadedPlugins = oldkrdPluginData
+               utils.LoadedPlugins = oldkrdPluginData
                ReadMetadataFile = oldReadMetadataFile
        }()
 
-       err := LoadMockPlugins(&krd.LoadedPlugins)
+       err := LoadMockPlugins(&utils.LoadedPlugins)
        if err != nil {
                t.Fatalf("TestCreateVNF returned an error (%s)", err)
        }
@@ -65,7 +65,7 @@ func TestCreateVNF(t *testing.T) {
                var seqFile MetadataFile
 
                if _, err := os.Stat(yamlFilePath); err == nil {
-                       rawBytes, err := ioutil.ReadFile("../mock_files/mock_yamls/metadata.yaml")
+                       rawBytes, err := ioutil.ReadFile("../../mock_files/mock_yamls/metadata.yaml")
                        if err != nil {
                                return seqFile, pkgerrors.Wrap(err, "Metadata YAML file read error")
                        }
@@ -97,13 +97,13 @@ func TestCreateVNF(t *testing.T) {
 }
 
 func TestDeleteVNF(t *testing.T) {
-       oldkrdPluginData := krd.LoadedPlugins
+       oldkrdPluginData := utils.LoadedPlugins
 
        defer func() {
-               krd.LoadedPlugins = oldkrdPluginData
+               utils.LoadedPlugins = oldkrdPluginData
        }()
 
-       err := LoadMockPlugins(&krd.LoadedPlugins)
+       err := LoadMockPlugins(&utils.LoadedPlugins)
        if err != nil {
                t.Fatalf("TestCreateVNF returned an error (%s)", err)
        }
@@ -125,7 +125,7 @@ func TestDeleteVNF(t *testing.T) {
 
 func TestReadMetadataFile(t *testing.T) {
        t.Run("Successfully read Metadata YAML file", func(t *testing.T) {
-               _, err := ReadMetadataFile("../mock_files//mock_yamls/metadata.yaml")
+               _, err := ReadMetadataFile("../../mock_files//mock_yamls/metadata.yaml")
                if err != nil {
                        t.Fatalf("TestReadMetadataFile returned an error (%s)", err)
                }
similarity index 99%
rename from src/k8splugin/rb/definition.go
rename to src/k8splugin/internal/rb/definition.go
index 084abe7..8a26332 100644 (file)
@@ -19,7 +19,7 @@ package rb
 import (
        "bytes"
        "encoding/base64"
-       "k8splugin/db"
+       "k8splugin/internal/db"
        "log"
 
        uuid "github.com/hashicorp/go-uuid"
similarity index 99%
rename from src/k8splugin/rb/definition_test.go
rename to src/k8splugin/internal/rb/definition_test.go
index f1ec18e..46ab3c0 100644 (file)
@@ -19,7 +19,7 @@
 package rb
 
 import (
-       "k8splugin/db"
+       "k8splugin/internal/db"
        "reflect"
        "sort"
        "strings"
similarity index 99%
rename from src/k8splugin/rb/profile.go
rename to src/k8splugin/internal/rb/profile.go
index bbd43fe..a0245af 100644 (file)
@@ -19,7 +19,7 @@ package rb
 import (
        "bytes"
        "encoding/base64"
-       "k8splugin/db"
+       "k8splugin/internal/db"
        "log"
 
        uuid "github.com/hashicorp/go-uuid"
similarity index 99%
rename from src/k8splugin/rb/profile_test.go
rename to src/k8splugin/internal/rb/profile_test.go
index 2540d3c..15ff895 100644 (file)
@@ -19,7 +19,7 @@
 package rb
 
 import (
-       "k8splugin/db"
+       "k8splugin/internal/db"
        "reflect"
        "sort"
        "strings"
similarity index 99%
rename from src/k8splugin/krd/plugins.go
rename to src/k8splugin/internal/utils.go
index 1086a2b..5bac7a8 100644 (file)
@@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package krd
+package utils
 
 import (
        "io/ioutil"
similarity index 98%
rename from src/k8splugin/krd/plugins_test.go
rename to src/k8splugin/internal/utils_test.go
index 46499ad..6b49d42 100644 (file)
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package krd
+package utils
 
 import (
        "strings"
@@ -39,7 +39,7 @@ func TestDecodeYAML(t *testing.T) {
                },
                {
                        label:         "Fail to read invalid YAML format",
-                       input:         "./plugins_test.go",
+                       input:         "./utils_test.go",
                        expectedError: "mapping values are not allowed in this contex",
                },
                {
index c31e4fe..80a9d59 100644 (file)
@@ -16,13 +16,13 @@ package main
 import (
        "k8s.io/client-go/kubernetes"
 
-       "k8splugin/krd"
+       utils "k8splugin/internal"
 )
 
 func main() {}
 
 // Create object in a specific Kubernetes resource
-func Create(data *krd.ResourceData, client kubernetes.Interface) (string, error) {
+func Create(data *utils.ResourceData, client kubernetes.Interface) (string, error) {
        return "externalUUID", nil
 }
 
index 84d01a7..b500c86 100644 (file)
@@ -22,16 +22,16 @@ import (
        metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
        "k8s.io/client-go/kubernetes"
 
-       "k8splugin/krd"
+       utils "k8splugin/internal"
 )
 
 // Create deployment object in a specific Kubernetes cluster
-func Create(data *krd.ResourceData, client kubernetes.Interface) (string, error) {
+func Create(data *utils.ResourceData, client kubernetes.Interface) (string, error) {
        namespace := data.Namespace
        if namespace == "" {
                namespace = "default"
        }
-       obj, err := krd.DecodeYAML(data.YamlFilePath, nil)
+       obj, err := utils.DecodeYAML(data.YamlFilePath, nil)
        if err != nil {
                return "", pkgerrors.Wrap(err, "Decode deployment object error")
        }
@@ -58,7 +58,7 @@ func List(namespace string, kubeclient kubernetes.Interface) ([]string, error) {
        }
 
        opts := metaV1.ListOptions{
-               Limit: krd.ResourcesListLimit,
+               Limit: utils.ResourcesListLimit,
        }
        opts.APIVersion = "apps/v1"
        opts.Kind = "Deployment"
@@ -68,7 +68,7 @@ func List(namespace string, kubeclient kubernetes.Interface) ([]string, error) {
                return nil, pkgerrors.Wrap(err, "Get Deployment list error")
        }
 
-       result := make([]string, 0, krd.ResourcesListLimit)
+       result := make([]string, 0, utils.ResourcesListLimit)
        if list != nil {
                for _, deployment := range list.Items {
                        log.Printf("%v", deployment.Name)
index c8dcb29..bfe5fe3 100644 (file)
@@ -20,7 +20,7 @@ import (
        "strings"
        "testing"
 
-       "k8splugin/krd"
+       utils "k8splugin/internal"
 
        appsV1 "k8s.io/api/apps/v1"
        metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -33,14 +33,14 @@ func TestCreateDeployment(t *testing.T) {
        internalVNFID := "1"
        testCases := []struct {
                label          string
-               input          *krd.ResourceData
+               input          *utils.ResourceData
                clientOutput   *appsV1.Deployment
                expectedResult string
                expectedError  string
        }{
                {
                        label: "Fail to create a deployment with invalid type",
-                       input: &krd.ResourceData{
+                       input: &utils.ResourceData{
                                YamlFilePath: "../../mock_files/mock_yamls/service.yaml",
                        },
                        clientOutput:  &appsV1.Deployment{},
@@ -48,7 +48,7 @@ func TestCreateDeployment(t *testing.T) {
                },
                {
                        label: "Successfully create a deployment",
-                       input: &krd.ResourceData{
+                       input: &utils.ResourceData{
                                VnfId:        internalVNFID,
                                YamlFilePath: "../../mock_files/mock_yamls/deployment.yaml",
                        },
index de2f4f8..6f82391 100644 (file)
@@ -23,11 +23,11 @@ import (
        coreV1 "k8s.io/api/core/v1"
        metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 
-       "k8splugin/krd"
+       utils "k8splugin/internal"
 )
 
 // Create a namespace object in a specific Kubernetes cluster
-func Create(data *krd.ResourceData, client kubernetes.Interface) (string, error) {
+func Create(data *utils.ResourceData, client kubernetes.Interface) (string, error) {
        namespace := &coreV1.Namespace{
                ObjectMeta: metaV1.ObjectMeta{
                        Name: data.Namespace,
@@ -74,7 +74,7 @@ func Delete(name string, namespace string, client kubernetes.Interface) error {
 // List of existing namespaces hosted in a specific Kubernetes cluster
 func List(namespace string, client kubernetes.Interface) ([]string, error) {
        opts := metaV1.ListOptions{
-               Limit: krd.ResourcesListLimit,
+               Limit: utils.ResourcesListLimit,
        }
        opts.APIVersion = "apps/v1"
        opts.Kind = "Namespace"
@@ -84,7 +84,7 @@ func List(namespace string, client kubernetes.Interface) ([]string, error) {
                return nil, pkgerrors.Wrap(err, "Get Namespace list error")
        }
 
-       result := make([]string, 0, krd.ResourcesListLimit)
+       result := make([]string, 0, utils.ResourcesListLimit)
        if list != nil {
                for _, deployment := range list.Items {
                        log.Printf("%v", deployment.Name)
index 8a9fc5a..2f1475d 100644 (file)
@@ -20,7 +20,7 @@ import (
        "strings"
        "testing"
 
-       "k8splugin/krd"
+       utils "k8splugin/internal"
 
        coreV1 "k8s.io/api/core/v1"
        metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -31,14 +31,14 @@ func TestCreateNamespace(t *testing.T) {
        namespace := "test1"
        testCases := []struct {
                label          string
-               input          *krd.ResourceData
+               input          *utils.ResourceData
                clientOutput   *coreV1.Namespace
                expectedResult string
                expectedError  string
        }{
                {
                        label: "Successfully create a namespace",
-                       input: &krd.ResourceData{
+                       input: &utils.ResourceData{
                                Namespace: namespace,
                        },
                        clientOutput:   &coreV1.Namespace{},
index d54fc42..fb16318 100644 (file)
@@ -14,11 +14,13 @@ limitations under the License.
 package main
 
 import (
-       pkgerrors "github.com/pkg/errors"
-       "k8s.io/client-go/kubernetes"
-       "k8splugin/krd"
        "k8splugin/plugins/network/v1"
        "regexp"
+
+       utils "k8splugin/internal"
+
+       pkgerrors "github.com/pkg/errors"
+       "k8s.io/client-go/kubernetes"
 )
 
 func extractData(data string) (vnfID, cniType, networkName string) {
@@ -34,9 +36,9 @@ func extractData(data string) (vnfID, cniType, networkName string) {
 }
 
 // Create an ONAP Network object
-func Create(data *krd.ResourceData, client kubernetes.Interface) (string, error) {
+func Create(data *utils.ResourceData, client kubernetes.Interface) (string, error) {
        network := &v1.OnapNetwork{}
-       if _, err := krd.DecodeYAML(data.YamlFilePath, network); err != nil {
+       if _, err := utils.DecodeYAML(data.YamlFilePath, network); err != nil {
                return "", pkgerrors.Wrap(err, "Decode network object error")
        }
 
@@ -46,7 +48,7 @@ func Create(data *krd.ResourceData, client kubernetes.Interface) (string, error)
        }
 
        cniType := config["cnitype"].(string)
-       typePlugin, ok := krd.LoadedPlugins[cniType+"-network"]
+       typePlugin, ok := utils.LoadedPlugins[cniType+"-network"]
        if !ok {
                return "", pkgerrors.New("No plugin for resource " + cniType + " found")
        }
@@ -72,7 +74,7 @@ func List(namespace string, kubeclient kubernetes.Interface) ([]string, error) {
 // Delete an existing Network
 func Delete(name string, namespace string, kubeclient kubernetes.Interface) error {
        _, cniType, networkName := extractData(name)
-       typePlugin, ok := krd.LoadedPlugins[cniType+"-network"]
+       typePlugin, ok := utils.LoadedPlugins[cniType+"-network"]
        if !ok {
                return pkgerrors.New("No plugin for resource " + cniType + " found")
        }
index 325de31..0239117 100644 (file)
@@ -16,13 +16,14 @@ limitations under the License.
 package main
 
 import (
-       pkgerrors "github.com/pkg/errors"
-       "k8splugin/krd"
+       utils "k8splugin/internal"
        "os"
        "plugin"
        "reflect"
        "strings"
        "testing"
+
+       pkgerrors "github.com/pkg/errors"
 )
 
 func LoadMockNetworkPlugins(krdLoadedPlugins *map[string]*plugin.Plugin, networkName, errMsg string) error {
@@ -53,15 +54,15 @@ func LoadMockNetworkPlugins(krdLoadedPlugins *map[string]*plugin.Plugin, network
 
 func TestCreateNetwork(t *testing.T) {
        internalVNFID := "1"
-       oldkrdPluginData := krd.LoadedPlugins
+       oldkrdPluginData := utils.LoadedPlugins
 
        defer func() {
-               krd.LoadedPlugins = oldkrdPluginData
+               utils.LoadedPlugins = oldkrdPluginData
        }()
 
        testCases := []struct {
                label          string
-               input          *krd.ResourceData
+               input          *utils.ResourceData
                mockError      string
                mockOutput     string
                expectedResult string
@@ -69,14 +70,14 @@ func TestCreateNetwork(t *testing.T) {
        }{
                {
                        label: "Fail to decode a network object",
-                       input: &krd.ResourceData{
+                       input: &utils.ResourceData{
                                YamlFilePath: "../../mock_files/mock_yamls/service.yaml",
                        },
                        expectedError: "Fail to decode network's configuration: Invalid configuration value",
                },
                {
                        label: "Fail to create a network",
-                       input: &krd.ResourceData{
+                       input: &utils.ResourceData{
                                YamlFilePath: "../../mock_files/mock_yamls/ovn4nfvk8s.yaml",
                        },
                        mockError:     "Internal error",
@@ -84,7 +85,7 @@ func TestCreateNetwork(t *testing.T) {
                },
                {
                        label: "Successfully create a ovn4nfv network",
-                       input: &krd.ResourceData{
+                       input: &utils.ResourceData{
                                VnfId:        internalVNFID,
                                YamlFilePath: "../../mock_files/mock_yamls/ovn4nfvk8s.yaml",
                        },
@@ -95,7 +96,7 @@ func TestCreateNetwork(t *testing.T) {
 
        for _, testCase := range testCases {
                t.Run(testCase.label, func(t *testing.T) {
-                       err := LoadMockNetworkPlugins(&krd.LoadedPlugins, testCase.mockOutput, testCase.mockError)
+                       err := LoadMockNetworkPlugins(&utils.LoadedPlugins, testCase.mockOutput, testCase.mockError)
                        if err != nil {
                                t.Fatalf("TestCreateNetwork returned an error (%s)", err)
                        }
@@ -121,10 +122,10 @@ func TestCreateNetwork(t *testing.T) {
 }
 
 func TestDeleteNetwork(t *testing.T) {
-       oldkrdPluginData := krd.LoadedPlugins
+       oldkrdPluginData := utils.LoadedPlugins
 
        defer func() {
-               krd.LoadedPlugins = oldkrdPluginData
+               utils.LoadedPlugins = oldkrdPluginData
        }()
 
        testCases := []struct {
@@ -154,7 +155,7 @@ func TestDeleteNetwork(t *testing.T) {
 
        for _, testCase := range testCases {
                t.Run(testCase.label, func(t *testing.T) {
-                       err := LoadMockNetworkPlugins(&krd.LoadedPlugins, testCase.mockOutput, testCase.mockError)
+                       err := LoadMockNetworkPlugins(&utils.LoadedPlugins, testCase.mockOutput, testCase.mockError)
                        if err != nil {
                                t.Fatalf("TestDeleteNetwork returned an error (%s)", err)
                        }
index 69acb34..e9b45fc 100644 (file)
@@ -23,16 +23,16 @@ import (
        coreV1 "k8s.io/api/core/v1"
        metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 
-       "k8splugin/krd"
+       utils "k8splugin/internal"
 )
 
 // Create a service object in a specific Kubernetes cluster
-func Create(data *krd.ResourceData, client kubernetes.Interface) (string, error) {
+func Create(data *utils.ResourceData, client kubernetes.Interface) (string, error) {
        namespace := data.Namespace
        if namespace == "" {
                namespace = "default"
        }
-       obj, err := krd.DecodeYAML(data.YamlFilePath, nil)
+       obj, err := utils.DecodeYAML(data.YamlFilePath, nil)
        if err != nil {
                return "", pkgerrors.Wrap(err, "Decode service object error")
        }
@@ -59,7 +59,7 @@ func List(namespace string, kubeclient kubernetes.Interface) ([]string, error) {
        }
 
        opts := metaV1.ListOptions{
-               Limit: krd.ResourcesListLimit,
+               Limit: utils.ResourcesListLimit,
        }
        opts.APIVersion = "apps/v1"
        opts.Kind = "Service"
@@ -69,7 +69,7 @@ func List(namespace string, kubeclient kubernetes.Interface) ([]string, error) {
                return nil, pkgerrors.Wrap(err, "Get Service list error")
        }
 
-       result := make([]string, 0, krd.ResourcesListLimit)
+       result := make([]string, 0, utils.ResourcesListLimit)
        if list != nil {
                for _, deployment := range list.Items {
                        log.Printf("%v", deployment.Name)
index 25eeb73..b919891 100644 (file)
@@ -20,7 +20,7 @@ import (
        "strings"
        "testing"
 
-       "k8splugin/krd"
+       utils "k8splugin/internal"
 
        coreV1 "k8s.io/api/core/v1"
        metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -33,14 +33,14 @@ func TestCreateService(t *testing.T) {
        internalVNFID := "1"
        testCases := []struct {
                label          string
-               input          *krd.ResourceData
+               input          *utils.ResourceData
                clientOutput   *coreV1.Service
                expectedResult string
                expectedError  string
        }{
                {
                        label: "Fail to create a service with invalid type",
-                       input: &krd.ResourceData{
+                       input: &utils.ResourceData{
                                YamlFilePath: "../../mock_files/mock_yamls/deployment.yaml",
                        },
                        clientOutput:  &coreV1.Service{},
@@ -48,7 +48,7 @@ func TestCreateService(t *testing.T) {
                },
                {
                        label: "Successfully create a service",
-                       input: &krd.ResourceData{
+                       input: &utils.ResourceData{
                                VnfId:        internalVNFID,
                                YamlFilePath: "../../mock_files/mock_yamls/service.yaml",
                        },