aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/k8splugin/plugins/network/plugin.go16
-rw-r--r--src/k8splugin/plugins/network/plugin_test.go13
2 files changed, 20 insertions, 9 deletions
diff --git a/src/k8splugin/plugins/network/plugin.go b/src/k8splugin/plugins/network/plugin.go
index ca5aa959..84a5fe51 100644
--- a/src/k8splugin/plugins/network/plugin.go
+++ b/src/k8splugin/plugins/network/plugin.go
@@ -31,14 +31,16 @@ var ExportedVariable networkPlugin
type networkPlugin struct {
}
-func extractData(data string) (cniType, networkName string) {
+func extractData(data string) (cniType, networkName string, err error) {
re := regexp.MustCompile("_")
split := re.Split(data, -1)
- if len(split) != 3 {
+ if len(split) != 2 {
+ err = pkgerrors.New("Couldn't split resource '" + data +
+ "' into CNI type and Network name")
return
}
- cniType = split[1]
- networkName = split[2]
+ cniType = split[0]
+ networkName = split[1]
return
}
@@ -82,7 +84,11 @@ func (p networkPlugin) List(gvk schema.GroupVersionKind, namespace string,
// Delete an existing Network
func (p networkPlugin) Delete(resource helm.KubernetesResource, namespace string, client plugin.KubernetesConnector) error {
- cniType, networkName := extractData(resource.Name)
+ cniType, networkName, err := extractData(resource.Name)
+ if err != nil {
+ return pkgerrors.Wrap(err, "Error extracting CNI type from resource")
+ }
+
typePlugin, ok := utils.LoadedPlugins[cniType+"-network"]
if !ok {
return pkgerrors.New("No plugin for resource " + cniType + " found")
diff --git a/src/k8splugin/plugins/network/plugin_test.go b/src/k8splugin/plugins/network/plugin_test.go
index 586bccb8..33cae1c7 100644
--- a/src/k8splugin/plugins/network/plugin_test.go
+++ b/src/k8splugin/plugins/network/plugin_test.go
@@ -130,18 +130,23 @@ func TestDeleteNetwork(t *testing.T) {
}{
{
label: "Fail to load non-existing plugin",
- input: "test",
- expectedError: "No plugin for resource",
+ input: "non-existing-cni_test",
+ expectedError: "No plugin for resource non-existing-cni",
},
{
- label: "Fail to delete a network",
+ label: "Fail to extract cni from network name",
input: "1_ovn4nfvk8s_test",
+ expectedError: "Error extracting CNI type from resource: Couldn't split resource '1_ovn4nfvk8s_test' into CNI type and Network name",
+ },
+ {
+ label: "Fail to delete a network",
+ input: "ovn4nfvk8s_test",
mockError: "Internal error",
expectedError: "Error during the deletion for ovn4nfvk8s plugin: Internal error",
},
{
label: "Successfully delete a ovn4nfv network",
- input: "1_ovn4nfvk8s_test",
+ input: "ovn4nfvk8s_test",
},
}