summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/plugins/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/plugins/network')
-rw-r--r--src/k8splugin/plugins/network/plugin.go39
-rw-r--r--src/k8splugin/plugins/network/plugin_test.go33
2 files changed, 39 insertions, 33 deletions
diff --git a/src/k8splugin/plugins/network/plugin.go b/src/k8splugin/plugins/network/plugin.go
index 74ac3473..5cc57e87 100644
--- a/src/k8splugin/plugins/network/plugin.go
+++ b/src/k8splugin/plugins/network/plugin.go
@@ -14,31 +14,38 @@ limitations under the License.
package main
import (
- "k8splugin/plugins/network/v1"
+ v1 "k8splugin/plugins/network/v1"
"regexp"
utils "k8splugin/internal"
+ "k8splugin/internal/app"
+ "k8splugin/internal/helm"
pkgerrors "github.com/pkg/errors"
- "k8s.io/client-go/kubernetes"
+ "k8s.io/apimachinery/pkg/runtime/schema"
)
-func extractData(data string) (vnfID, cniType, networkName string) {
+// ExportedVariable is what we will look for when calling the plugin
+var ExportedVariable networkPlugin
+
+type networkPlugin struct {
+}
+
+func extractData(data string) (cniType, networkName string) {
re := regexp.MustCompile("_")
split := re.Split(data, -1)
if len(split) != 3 {
return
}
- vnfID = split[0]
cniType = split[1]
networkName = split[2]
return
}
// Create an ONAP Network object
-func Create(data *utils.ResourceData, client kubernetes.Interface) (string, error) {
+func (p networkPlugin) Create(yamlFilePath string, namespace string, client *app.KubernetesClient) (string, error) {
network := &v1.OnapNetwork{}
- if _, err := utils.DecodeYAML(data.YamlFilePath, network); err != nil {
+ if _, err := utils.DecodeYAML(yamlFilePath, network); err != nil {
return "", pkgerrors.Wrap(err, "Decode network object error")
}
@@ -58,17 +65,24 @@ func Create(data *utils.ResourceData, client kubernetes.Interface) (string, erro
return "", pkgerrors.Wrap(err, "Error during the creation for "+cniType+" plugin")
}
- return data.VnfId + "_" + cniType + "_" + name, nil
+ return cniType + "_" + name, nil
+}
+
+// Get a Network
+func (p networkPlugin) Get(resource helm.KubernetesResource, namespace string, client *app.KubernetesClient) (string, error) {
+ return "", nil
}
// List of Networks
-func List(namespace string, kubeclient kubernetes.Interface) ([]string, error) {
+func (p networkPlugin) List(gvk schema.GroupVersionKind, namespace string,
+ client *app.KubernetesClient) ([]helm.KubernetesResource, error) {
+
return nil, nil
}
// Delete an existing Network
-func Delete(name string, namespace string, kubeclient kubernetes.Interface) error {
- _, cniType, networkName := extractData(name)
+func (p networkPlugin) Delete(resource helm.KubernetesResource, namespace string, client *app.KubernetesClient) error {
+ cniType, networkName := extractData(resource.Name)
typePlugin, ok := utils.LoadedPlugins[cniType+"-network"]
if !ok {
return pkgerrors.New("No plugin for resource " + cniType + " found")
@@ -85,8 +99,3 @@ func Delete(name string, namespace string, kubeclient kubernetes.Interface) erro
return nil
}
-
-// Get an existing Network
-func Get(name string, namespace string, kubeclient kubernetes.Interface) (string, error) {
- return "", nil
-}
diff --git a/src/k8splugin/plugins/network/plugin_test.go b/src/k8splugin/plugins/network/plugin_test.go
index e8e113b2..5a8ce4db 100644
--- a/src/k8splugin/plugins/network/plugin_test.go
+++ b/src/k8splugin/plugins/network/plugin_test.go
@@ -15,6 +15,7 @@ package main
import (
utils "k8splugin/internal"
+ "k8splugin/internal/helm"
"os"
"plugin"
"reflect"
@@ -22,6 +23,7 @@ import (
"testing"
pkgerrors "github.com/pkg/errors"
+ "k8s.io/apimachinery/pkg/runtime/schema"
)
func LoadMockNetworkPlugins(krdLoadedPlugins *map[string]*plugin.Plugin, networkName, errMsg string) error {
@@ -51,7 +53,6 @@ func LoadMockNetworkPlugins(krdLoadedPlugins *map[string]*plugin.Plugin, network
}
func TestCreateNetwork(t *testing.T) {
- internalVNFID := "1"
oldkrdPluginData := utils.LoadedPlugins
defer func() {
@@ -60,34 +61,27 @@ func TestCreateNetwork(t *testing.T) {
testCases := []struct {
label string
- input *utils.ResourceData
+ input string
mockError string
mockOutput string
expectedResult string
expectedError string
}{
{
- label: "Fail to decode a network object",
- input: &utils.ResourceData{
- YamlFilePath: "../../mock_files/mock_yamls/service.yaml",
- },
+ label: "Fail to decode a network object",
+ input: "../../mock_files/mock_yamls/service.yaml",
expectedError: "No plugin for resource",
},
{
- label: "Fail to create a network",
- input: &utils.ResourceData{
- YamlFilePath: "../../mock_files/mock_yamls/ovn4nfvk8s.yaml",
- },
+ label: "Fail to create a network",
+ input: "../../mock_files/mock_yamls/ovn4nfvk8s.yaml",
mockError: "Internal error",
expectedError: "Error during the creation for ovn4nfvk8s plugin: Internal error",
},
{
- label: "Successfully create a ovn4nfv network",
- input: &utils.ResourceData{
- VnfId: internalVNFID,
- YamlFilePath: "../../mock_files/mock_yamls/ovn4nfvk8s.yaml",
- },
- expectedResult: internalVNFID + "_ovn4nfvk8s_myNetwork",
+ label: "Successfully create a ovn4nfv network",
+ input: "../../mock_files/mock_yamls/ovn4nfvk8s.yaml",
+ expectedResult: "ovn4nfvk8s_myNetwork",
mockOutput: "myNetwork",
},
}
@@ -98,7 +92,7 @@ func TestCreateNetwork(t *testing.T) {
if err != nil {
t.Fatalf("TestCreateNetwork returned an error (%s)", err)
}
- result, err := Create(testCase.input, nil)
+ result, err := networkPlugin{}.Create(testCase.input, "", nil)
if err != nil {
if testCase.expectedError == "" {
t.Fatalf("Create method return an un-expected (%s)", err)
@@ -157,7 +151,10 @@ func TestDeleteNetwork(t *testing.T) {
if err != nil {
t.Fatalf("TestDeleteNetwork returned an error (%s)", err)
}
- err = Delete(testCase.input, "", nil)
+ err = networkPlugin{}.Delete(helm.KubernetesResource{
+ GVK: schema.GroupVersionKind{Group: "", Version: "", Kind: "Network"},
+ Name: testCase.input,
+ }, "", nil)
if err != nil {
if testCase.expectedError == "" {
t.Fatalf("Create method return an un-expected (%s)", err)