diff options
Diffstat (limited to 'src/k8splugin')
-rw-r--r-- | src/k8splugin/internal/app/client.go | 3 | ||||
-rw-r--r-- | src/k8splugin/internal/utils.go | 4 | ||||
-rw-r--r-- | src/k8splugin/plugins/generic/plugin.go | 11 | ||||
-rw-r--r-- | src/k8splugin/plugins/namespace/plugin.go | 3 | ||||
-rw-r--r-- | src/k8splugin/plugins/network/plugin.go | 22 | ||||
-rw-r--r-- | src/k8splugin/plugins/network/plugin_test.go | 13 | ||||
-rw-r--r-- | src/k8splugin/plugins/service/plugin.go | 3 |
7 files changed, 37 insertions, 22 deletions
diff --git a/src/k8splugin/internal/app/client.go b/src/k8splugin/internal/app/client.go index 8d2af297..d44f3505 100644 --- a/src/k8splugin/internal/app/client.go +++ b/src/k8splugin/internal/app/client.go @@ -122,8 +122,6 @@ func (k *KubernetesClient) ensureNamespace(namespace string) error { func (k *KubernetesClient) createKind(resTempl helm.KubernetesResourceTemplate, namespace string) (helm.KubernetesResource, error) { - log.Println("Processing Kind: " + resTempl.GVK.Kind) - if _, err := os.Stat(resTempl.FilePath); os.IsNotExist(err) { return helm.KubernetesResource{}, pkgerrors.New("File " + resTempl.FilePath + "does not exists") } @@ -137,6 +135,7 @@ func (k *KubernetesClient) createKind(resTempl helm.KubernetesResourceTemplate, createdResourceName, err := pluginImpl.Create(resTempl.FilePath, namespace, k) if err != nil { + log.Printf("Error: %s while creating: %s", err.Error(), resTempl.GVK.Kind) return helm.KubernetesResource{}, pkgerrors.Wrap(err, "Error in plugin "+resTempl.GVK.Kind+" plugin") } diff --git a/src/k8splugin/internal/utils.go b/src/k8splugin/internal/utils.go index 47a236c2..174f8e79 100644 --- a/src/k8splugin/internal/utils.go +++ b/src/k8splugin/internal/utils.go @@ -17,8 +17,8 @@ import ( "io/ioutil" "log" "os" - "path/filepath" "path" + "path/filepath" "plugin" "strings" @@ -52,13 +52,11 @@ func DecodeYAML(path string, into runtime.Object) (runtime.Object, error) { } } - log.Println("Reading YAML file") rawBytes, err := ioutil.ReadFile(path) if err != nil { return nil, pkgerrors.Wrap(err, "Read YAML file error") } - log.Println("Decoding deployment YAML") decode := scheme.Codecs.UniversalDeserializer().Decode obj, _, err := decode(rawBytes, nil, into) if err != nil { diff --git a/src/k8splugin/plugins/generic/plugin.go b/src/k8splugin/plugins/generic/plugin.go index b9a96ab5..cc5fcb7a 100644 --- a/src/k8splugin/plugins/generic/plugin.go +++ b/src/k8splugin/plugins/generic/plugin.go @@ -14,8 +14,6 @@ limitations under the License. package main import ( - "log" - pkgerrors "github.com/pkg/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -23,10 +21,13 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" utils "github.com/onap/multicloud-k8s/src/k8splugin/internal" - "github.com/onap/multicloud-k8s/src/k8splugin/internal/plugin" "github.com/onap/multicloud-k8s/src/k8splugin/internal/helm" + "github.com/onap/multicloud-k8s/src/k8splugin/internal/plugin" ) +// Compile time check to see if genericPlugin implements the correct interface +var _ plugin.Reference = genericPlugin{} + // ExportedVariable is what we will look for when calling the generic plugin var ExportedVariable genericPlugin @@ -94,8 +95,6 @@ func (g genericPlugin) Get(resource helm.KubernetesResource, } gvr := mapping.Resource - log.Printf("Using gvr: %s, %s, %s", gvr.Group, gvr.Version, gvr.Resource) - opts := metav1.GetOptions{} var unstruct *unstructured.Unstructured switch mapping.Scope.Name() { @@ -141,8 +140,6 @@ func (g genericPlugin) Delete(resource helm.KubernetesResource, namespace string } gvr := mapping.Resource - log.Printf("Using gvr: %s, %s, %s", gvr.Group, gvr.Version, gvr.Resource) - deletePolicy := metav1.DeletePropagationForeground opts := &metav1.DeleteOptions{ PropagationPolicy: &deletePolicy, diff --git a/src/k8splugin/plugins/namespace/plugin.go b/src/k8splugin/plugins/namespace/plugin.go index d30f55b8..feb2aa61 100644 --- a/src/k8splugin/plugins/namespace/plugin.go +++ b/src/k8splugin/plugins/namespace/plugin.go @@ -26,6 +26,9 @@ import ( "github.com/onap/multicloud-k8s/src/k8splugin/internal/plugin" ) +// Compile time check to see if namespacePlugin implements the correct interface +var _ plugin.Reference = namespacePlugin{} + // ExportedVariable is what we will look for when calling the plugin var ExportedVariable namespacePlugin diff --git a/src/k8splugin/plugins/network/plugin.go b/src/k8splugin/plugins/network/plugin.go index ca5aa959..aa0d584b 100644 --- a/src/k8splugin/plugins/network/plugin.go +++ b/src/k8splugin/plugins/network/plugin.go @@ -14,9 +14,10 @@ limitations under the License. package main import ( - v1 "github.com/onap/multicloud-k8s/src/k8splugin/plugins/network/v1" "regexp" + v1 "github.com/onap/multicloud-k8s/src/k8splugin/plugins/network/v1" + utils "github.com/onap/multicloud-k8s/src/k8splugin/internal" "github.com/onap/multicloud-k8s/src/k8splugin/internal/helm" "github.com/onap/multicloud-k8s/src/k8splugin/internal/plugin" @@ -25,20 +26,25 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" ) +// Compile time check to see if networkPlugin implements the correct interface +var _ plugin.Reference = networkPlugin{} + // ExportedVariable is what we will look for when calling the plugin 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 +88,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", }, } diff --git a/src/k8splugin/plugins/service/plugin.go b/src/k8splugin/plugins/service/plugin.go index 2fceffc0..136a1343 100644 --- a/src/k8splugin/plugins/service/plugin.go +++ b/src/k8splugin/plugins/service/plugin.go @@ -26,6 +26,9 @@ import ( "github.com/onap/multicloud-k8s/src/k8splugin/internal/plugin" ) +// Compile time check to see if servicePlugin implements the correct interface +var _ plugin.Reference = servicePlugin{} + // ExportedVariable is what we will look for when calling the plugin var ExportedVariable servicePlugin |