diff options
22 files changed, 645 insertions, 79 deletions
diff --git a/deployments/_functions.sh b/deployments/_functions.sh index 7942aed0..45f2d8cf 100755 --- a/deployments/_functions.sh +++ b/deployments/_functions.sh @@ -21,11 +21,16 @@ function start_mongo { } function generate_k8sconfig { + local ovn_address + if [ -n "${OVN_CENTRAL_ADDRESS:-}" ]; then + ovn_address="\"ovn-central-address\": \"${OVN_CENTRAL_ADDRESS}\"," + fi cat << EOF > k8sconfig.json { - "database-address": "${DATABASE_IP}", + "database-address": "${DATABASE_IP}", "database-type": "mongo", "plugin-dir": "plugins", + ${ovn_address} "service-port": "9015" } EOF diff --git a/kud/README.md b/kud/README.md index 99805c3c..caa731dc 100644 --- a/kud/README.md +++ b/kud/README.md @@ -30,8 +30,8 @@ Apache-2.0 [1]: https://git.onap.org/multicloud/k8s [2]: https://github.com/kubernetes-incubator/kubespray -[3]: playbooks/configure-ovn4nfv.yml -[4]: playbooks/configure-virtlet.yml -[5]: playbooks/configure-multus.yml -[6]: playbooks/configure-nfd.yml -[7]: playbooks/configure-istio.yml +[3]: deployment_infra/playbooks/configure-ovn4nfv.yml +[4]: deployment_infra/playbooks/configure-virtlet.yml +[5]: deployment_infra/playbooks/configure-multus.yml +[6]: deployment_infra/playbooks/configure-nfd.yml +[7]: deployment_infra/playbooks/configure-istio.yml diff --git a/kud/demo/firewall/charts/packetgen/values.yaml b/kud/demo/firewall/charts/packetgen/values.yaml index d79e5485..3df94080 100644 --- a/kud/demo/firewall/charts/packetgen/values.yaml +++ b/kud/demo/firewall/charts/packetgen/values.yaml @@ -7,7 +7,7 @@ replicaCount: 1 image: repository: virtlet.cloud/ubuntu/16.04 tag: latest - pullPolicy: Always + pullPolicy: IfNotPresent nameOverride: "" fullnameOverride: "" diff --git a/kud/demo/firewall/charts/sink/values.yaml b/kud/demo/firewall/charts/sink/values.yaml index e2608e2f..8a70889a 100644 --- a/kud/demo/firewall/charts/sink/values.yaml +++ b/kud/demo/firewall/charts/sink/values.yaml @@ -7,10 +7,9 @@ replicaCount: 1 image: sinkrepo: rtsood/onap-vfw-demo-sink sinktag: 0.2.0 - pullPolicy: Always + pullPolicy: IfNotPresent darkstatrepo: electrocucaracha/darkstat darkstattag: latest - pullPolicy: Always nameOverride: "" fullnameOverride: "" diff --git a/kud/demo/firewall/values.yaml b/kud/demo/firewall/values.yaml index 4c0431be..abc39f01 100644 --- a/kud/demo/firewall/values.yaml +++ b/kud/demo/firewall/values.yaml @@ -7,7 +7,7 @@ replicaCount: 1 image: repository: virtlet.cloud/ubuntu/16.04 tag: latest - pullPolicy: Always + pullPolicy: IfNotPresent nameOverride: "" fullnameOverride: "" diff --git a/kud/deployment_infra/playbooks/configure-multus.yml b/kud/deployment_infra/playbooks/configure-multus.yml index 9cca54d1..47109162 100644 --- a/kud/deployment_infra/playbooks/configure-multus.yml +++ b/kud/deployment_infra/playbooks/configure-multus.yml @@ -62,27 +62,25 @@ mode: 0755 when: multus_source_type == "tarball" - name: create multus configuration file - blockinfile: - marker: "" - path: /etc/cni/net.d/00-multus.conf - create: yes - block: | - { - "type": "multus", - "name": "multus-cni", - "cniVersion": "0.3.1", - "kubeconfig": "/etc/kubernetes/admin.conf", - "delegates": [ - { - "type": "flannel", + copy: + dest: /etc/cni/net.d/00-multus.conf + content: | + { + "type": "multus", + "name": "multus-cni", "cniVersion": "0.3.1", - "masterplugin": true, - "delegate": { - "isDefaultGateway": true - } - } - ] - } + "kubeconfig": "/etc/kubernetes/admin.conf", + "delegates": [ + { + "type": "flannel", + "cniVersion": "0.3.1", + "masterplugin": true, + "delegate": { + "isDefaultGateway": true + } + } + ] + } - hosts: localhost pre_tasks: diff --git a/kud/tests/_functions.sh b/kud/tests/_functions.sh index 483aed5c..86636ccd 100755 --- a/kud/tests/_functions.sh +++ b/kud/tests/_functions.sh @@ -25,12 +25,36 @@ function print_msg { } function get_ovn_central_address { - ansible_ifconfig=$(ansible ovn-central[0] -i ${FUNCTIONS_DIR}/../hosting_providers/vagrant/inventory/hosts.ini -m shell -a "ifconfig ${OVN_CENTRAL_INTERFACE} |grep \"inet addr\" |awk '{print \$2}' |awk -F: '{print \$2}'") - if [[ $ansible_ifconfig != *CHANGED* ]]; then - echo "Fail to get the OVN central IP address from ${OVN_CENTRAL_INTERFACE} nic" - exit + #Reuse OVN_CENTRAL_ADDRESS if available (bypassable by --force flag) + if [[ "${1:-}" != "--force" ]] && [[ -n "${OVN_CENTRAL_ADDRESS:-}" ]]; then + echo "${OVN_CENTRAL_ADDRESS}" + return 0 + fi + + local remote_command="ip address show dev $OVN_CENTRAL_INTERFACE primary" + declare -a ansible_command=(ansible ovn-central[0] -i \ + "${FUNCTIONS_DIR}/../hosting_providers/vagrant/inventory/hosts.ini") + declare -a filter=(awk -F '[ \t/]+' \ + 'BEGIN {r=1} {for (i=1; i<=NF; i++) if ($i == "inet") {print $(i+1); r=0}} END {exit r}') + local result + + #Determine OVN_CENTRAL_INTERFACE address + if ! result="$("${ansible_command[@]}" -a "${remote_command}")"; then + echo "Ansible error for remote host ovn-central[0]" >&2 + return 1 + else + if [[ "${result}" != *CHANGED* ]]; then + echo "Failed to execute command on remote host ovn-central[0]" >&2 + return 2 + else + if ! result="$("${filter[@]}" <<< "${result}")"; then + echo "Failed to retrieve interface address from command output" >&2 + return 3 + else + echo "${result}:6641" + fi + fi fi - echo "$(echo ${ansible_ifconfig#*>>} | tr '\n' ':')6641" } function call_api { diff --git a/src/k8splugin/api/api.go b/src/k8splugin/api/api.go index 353972a1..4308db4f 100644 --- a/src/k8splugin/api/api.go +++ b/src/k8splugin/api/api.go @@ -38,6 +38,7 @@ func NewRouter(defClient rb.DefinitionManager, instHandler := instanceHandler{client: instClient} instRouter := router.PathPrefix("/v1").Subrouter() instRouter.HandleFunc("/instance", instHandler.createHandler).Methods("POST") + instRouter.HandleFunc("/instance", instHandler.listHandler).Methods("GET") instRouter.HandleFunc("/instance/{instID}", instHandler.getHandler).Methods("GET") instRouter.HandleFunc("/instance/{instID}", instHandler.deleteHandler).Methods("DELETE") // (TODO): Fix update method @@ -69,6 +70,7 @@ func NewRouter(defClient rb.DefinitionManager, resRouter.HandleFunc("/definition", defHandler.createHandler).Methods("POST") resRouter.HandleFunc("/definition/{rbname}/{rbversion}/content", defHandler.uploadHandler).Methods("POST") resRouter.HandleFunc("/definition/{rbname}", defHandler.listVersionsHandler).Methods("GET") + resRouter.HandleFunc("/definition", defHandler.listAllHandler).Methods("GET") resRouter.HandleFunc("/definition/{rbname}/{rbversion}", defHandler.getHandler).Methods("GET") resRouter.HandleFunc("/definition/{rbname}/{rbversion}", defHandler.deleteHandler).Methods("DELETE") @@ -78,6 +80,7 @@ func NewRouter(defClient rb.DefinitionManager, } profileHandler := rbProfileHandler{client: profileClient} resRouter.HandleFunc("/definition/{rbname}/{rbversion}/profile", profileHandler.createHandler).Methods("POST") + resRouter.HandleFunc("/definition/{rbname}/{rbversion}/profile", profileHandler.listHandler).Methods("GET") resRouter.HandleFunc("/definition/{rbname}/{rbversion}/profile/{prname}/content", profileHandler.uploadHandler).Methods("POST") resRouter.HandleFunc("/definition/{rbname}/{rbversion}/profile/{prname}", profileHandler.getHandler).Methods("GET") resRouter.HandleFunc("/definition/{rbname}/{rbversion}/profile/{prname}", profileHandler.deleteHandler).Methods("DELETE") diff --git a/src/k8splugin/api/defhandler.go b/src/k8splugin/api/defhandler.go index c1110a97..480d4be5 100644 --- a/src/k8splugin/api/defhandler.go +++ b/src/k8splugin/api/defhandler.go @@ -20,9 +20,10 @@ import ( "encoding/json" "io" "io/ioutil" - "github.com/onap/multicloud-k8s/src/k8splugin/internal/rb" "net/http" + "github.com/onap/multicloud-k8s/src/k8splugin/internal/rb" + "github.com/gorilla/mux" ) @@ -122,6 +123,25 @@ func (h rbDefinitionHandler) listVersionsHandler(w http.ResponseWriter, r *http. } } +// listVersionsHandler handles GET (list) operations on the endpoint +// Returns a list of rb.Definitions +func (h rbDefinitionHandler) listAllHandler(w http.ResponseWriter, r *http.Request) { + + ret, err := h.client.List("") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + // getHandler handles GET operations on a particular ids // Returns a rb.Definition func (h rbDefinitionHandler) getHandler(w http.ResponseWriter, r *http.Request) { diff --git a/src/k8splugin/api/defhandler_test.go b/src/k8splugin/api/defhandler_test.go index 077d0708..dcfea1de 100644 --- a/src/k8splugin/api/defhandler_test.go +++ b/src/k8splugin/api/defhandler_test.go @@ -240,6 +240,86 @@ func TestRBDefListVersionsHandler(t *testing.T) { } } +func TestRBDefListAllHandler(t *testing.T) { + + testCases := []struct { + label string + expected []rb.Definition + expectedCode int + rbDefClient *mockRBDefinition + }{ + { + label: "List Bundle Definitions", + expectedCode: http.StatusOK, + expected: []rb.Definition{ + { + RBName: "resourcebundle1", + RBVersion: "v1", + ChartName: "barchart", + Description: "test description for one", + }, + { + RBName: "resourcebundle2", + RBVersion: "version2", + ChartName: "foochart", + Description: "test description for two", + }, + }, + rbDefClient: &mockRBDefinition{ + // list of definitions that will be returned by the mockclient + Items: []rb.Definition{ + { + RBName: "resourcebundle1", + RBVersion: "v1", + ChartName: "barchart", + Description: "test description for one", + }, + { + RBName: "resourcebundle2", + RBVersion: "version2", + ChartName: "foochart", + Description: "test description for two", + }, + }, + }, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.label, func(t *testing.T) { + request := httptest.NewRequest("GET", "/v1/rb/definition", nil) + resp := executeRequest(request, NewRouter(testCase.rbDefClient, nil, nil, nil, nil, nil)) + + //Check returned code + if resp.StatusCode != testCase.expectedCode { + t.Fatalf("Expected %d; Got: %d", testCase.expectedCode, resp.StatusCode) + } + + //Check returned body only if statusOK + if resp.StatusCode == http.StatusOK { + got := []rb.Definition{} + json.NewDecoder(resp.Body).Decode(&got) + + // Since the order of returned slice is not guaranteed + // Check both and return error if both don't match + sort.Slice(got, func(i, j int) bool { + return got[i].RBVersion < got[j].RBVersion + }) + // Sort both as it is not expected that testCase.expected + // is sorted + sort.Slice(testCase.expected, func(i, j int) bool { + return testCase.expected[i].RBVersion < testCase.expected[j].RBVersion + }) + + if reflect.DeepEqual(testCase.expected, got) == false { + t.Errorf("listHandler returned unexpected body: got %v;"+ + " expected %v", got, testCase.expected) + } + } + }) + } +} + func TestRBDefGetHandler(t *testing.T) { testCases := []struct { diff --git a/src/k8splugin/api/instancehandler.go b/src/k8splugin/api/instancehandler.go index 42f3b212..3ec055bc 100644 --- a/src/k8splugin/api/instancehandler.go +++ b/src/k8splugin/api/instancehandler.go @@ -106,6 +106,24 @@ func (i instanceHandler) getHandler(w http.ResponseWriter, r *http.Request) { } } +// getHandler retrieves information about an instance via the ID +func (i instanceHandler) listHandler(w http.ResponseWriter, r *http.Request) { + + resp, err := i.client.List() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(resp) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + // deleteHandler method terminates an instance via the ID func (i instanceHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) diff --git a/src/k8splugin/api/instancehandler_test.go b/src/k8splugin/api/instancehandler_test.go index 35cef531..83fa3d2b 100644 --- a/src/k8splugin/api/instancehandler_test.go +++ b/src/k8splugin/api/instancehandler_test.go @@ -21,6 +21,7 @@ import ( "net/http" "net/http/httptest" "reflect" + "sort" "testing" "github.com/onap/multicloud-k8s/src/k8splugin/internal/app" @@ -38,8 +39,9 @@ type mockInstanceClient struct { app.InstanceManager // Items and err will be used to customize each test // via a localized instantiation of mockInstanceClient - items []app.InstanceResponse - err error + items []app.InstanceResponse + miniitems []app.InstanceMiniResponse + err error } func (m *mockInstanceClient) Create(inp app.InstanceRequest) (app.InstanceResponse, error) { @@ -58,6 +60,14 @@ func (m *mockInstanceClient) Get(id string) (app.InstanceResponse, error) { return m.items[0], nil } +func (m *mockInstanceClient) List() ([]app.InstanceMiniResponse, error) { + if m.err != nil { + return []app.InstanceMiniResponse{}, m.err + } + + return m.miniitems, nil +} + func (m *mockInstanceClient) Find(rbName string, ver string, profile string, labelKeys map[string]string) ([]app.InstanceResponse, error) { if m.err != nil { return nil, m.err @@ -297,6 +307,110 @@ func TestInstanceGetHandler(t *testing.T) { } } +func TestInstanceListHandler(t *testing.T) { + testCases := []struct { + label string + input string + expectedCode int + expectedResponse []app.InstanceMiniResponse + instClient *mockInstanceClient + }{ + { + label: "Fail to List Instance", + input: "HaKpys8e", + expectedCode: http.StatusInternalServerError, + instClient: &mockInstanceClient{ + err: pkgerrors.New("Internal error"), + }, + }, + { + label: "Succesful List Instances", + expectedCode: http.StatusOK, + expectedResponse: []app.InstanceMiniResponse{ + { + ID: "HaKpys8e", + Request: app.InstanceRequest{ + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile1", + CloudRegion: "region1", + }, + Namespace: "testnamespace", + }, + { + ID: "HaKpys8f", + Request: app.InstanceRequest{ + RBName: "test-rbdef-two", + RBVersion: "versionsomething", + ProfileName: "profile3", + CloudRegion: "region1", + }, + Namespace: "testnamespace-two", + }, + }, + instClient: &mockInstanceClient{ + miniitems: []app.InstanceMiniResponse{ + { + ID: "HaKpys8e", + Request: app.InstanceRequest{ + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile1", + CloudRegion: "region1", + }, + Namespace: "testnamespace", + }, + { + ID: "HaKpys8f", + Request: app.InstanceRequest{ + RBName: "test-rbdef-two", + RBVersion: "versionsomething", + ProfileName: "profile3", + CloudRegion: "region1", + }, + Namespace: "testnamespace-two", + }, + }, + }, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.label, func(t *testing.T) { + request := httptest.NewRequest("GET", "/v1/instance", nil) + resp := executeRequest(request, NewRouter(nil, nil, testCase.instClient, nil, nil, nil)) + + if testCase.expectedCode != resp.StatusCode { + t.Fatalf("Request method returned: %v and it was expected: %v", + resp.StatusCode, testCase.expectedCode) + } + if resp.StatusCode == http.StatusOK { + var response []app.InstanceMiniResponse + err := json.NewDecoder(resp.Body).Decode(&response) + if err != nil { + t.Fatalf("Parsing the returned response got an error (%s)", err) + } + + // Since the order of returned slice is not guaranteed + // Sort them first and then do deepequal + // Check both and return error if both don't match + sort.Slice(response, func(i, j int) bool { + return response[i].ID < response[j].ID + }) + + sort.Slice(testCase.expectedResponse, func(i, j int) bool { + return testCase.expectedResponse[i].ID < testCase.expectedResponse[j].ID + }) + + if reflect.DeepEqual(testCase.expectedResponse, response) == false { + t.Fatalf("TestGetHandler returned:\n result=%v\n expected=%v", + &response, testCase.expectedResponse) + } + } + }) + } +} + func TestDeleteHandler(t *testing.T) { testCases := []struct { label string diff --git a/src/k8splugin/api/profilehandler.go b/src/k8splugin/api/profilehandler.go index adb9249b..68ab77a4 100644 --- a/src/k8splugin/api/profilehandler.go +++ b/src/k8splugin/api/profilehandler.go @@ -20,9 +20,10 @@ import ( "encoding/json" "io" "io/ioutil" - "github.com/onap/multicloud-k8s/src/k8splugin/internal/rb" "net/http" + "github.com/onap/multicloud-k8s/src/k8splugin/internal/rb" + "github.com/gorilla/mux" ) @@ -119,6 +120,28 @@ func (h rbProfileHandler) getHandler(w http.ResponseWriter, r *http.Request) { } } +// getHandler handles GET operations on a particular ids +// Returns a rb.Definition +func (h rbProfileHandler) listHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + rbName := vars["rbname"] + rbVersion := vars["rbversion"] + + ret, err := h.client.List(rbName, rbVersion) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + // deleteHandler handles DELETE operations on a particular bundle definition id func (h rbProfileHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) diff --git a/src/k8splugin/api/profilehandler_test.go b/src/k8splugin/api/profilehandler_test.go index e81fb262..4dae377c 100644 --- a/src/k8splugin/api/profilehandler_test.go +++ b/src/k8splugin/api/profilehandler_test.go @@ -23,6 +23,7 @@ import ( "net/http" "net/http/httptest" "reflect" + "sort" "testing" "github.com/onap/multicloud-k8s/src/k8splugin/internal/rb" @@ -57,6 +58,14 @@ func (m *mockRBProfile) Get(rbname, rbversion, prname string) (rb.Profile, error return m.Items[0], nil } +func (m *mockRBProfile) List(rbname, rbversion string) ([]rb.Profile, error) { + if m.Err != nil { + return []rb.Profile{}, m.Err + } + + return m.Items, nil +} + func (m *mockRBProfile) Delete(rbname, rbversion, prname string) error { return m.Err } @@ -210,6 +219,98 @@ func TestRBProfileGetHandler(t *testing.T) { } } +func TestRBProfileListHandler(t *testing.T) { + + testCases := []struct { + def string + version string + label string + expected []rb.Profile + expectedCode int + rbProClient *mockRBProfile + }{ + { + def: "test-rbdef", + version: "v1", + label: "List Profiles", + expectedCode: http.StatusOK, + expected: []rb.Profile{ + { + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile1", + ReleaseName: "testprofilereleasename", + Namespace: "ns1", + KubernetesVersion: "1.12.3", + }, + { + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile2", + ReleaseName: "testprofilereleasename", + Namespace: "ns2", + KubernetesVersion: "1.12.3", + }, + }, + rbProClient: &mockRBProfile{ + // list of Profiles that will be returned by the mockclient + Items: []rb.Profile{ + { + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile1", + ReleaseName: "testprofilereleasename", + Namespace: "ns1", + KubernetesVersion: "1.12.3", + }, + { + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile2", + ReleaseName: "testprofilereleasename", + Namespace: "ns2", + KubernetesVersion: "1.12.3", + }, + }, + }, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.label, func(t *testing.T) { + request := httptest.NewRequest("GET", "/v1/rb/definition/"+testCase.def+"/"+testCase.version+"/profile", nil) + resp := executeRequest(request, NewRouter(nil, testCase.rbProClient, nil, nil, nil, nil)) + + //Check returned code + if resp.StatusCode != testCase.expectedCode { + t.Fatalf("Expected %d; Got: %d", testCase.expectedCode, resp.StatusCode) + } + + //Check returned body only if statusOK + if resp.StatusCode == http.StatusOK { + got := []rb.Profile{} + json.NewDecoder(resp.Body).Decode(&got) + + // Since the order of returned slice is not guaranteed + // Check both and return error if both don't match + sort.Slice(got, func(i, j int) bool { + return got[i].ProfileName < got[j].ProfileName + }) + // Sort both as it is not expected that testCase.expected + // is sorted + sort.Slice(testCase.expected, func(i, j int) bool { + return testCase.expected[i].ProfileName < testCase.expected[j].ProfileName + }) + + if reflect.DeepEqual(testCase.expected, got) == false { + t.Errorf("listHandler returned unexpected body: got %v;"+ + " expected %v", got, testCase.expected) + } + } + }) + } +} + func TestRBProfileDeleteHandler(t *testing.T) { testCases := []struct { diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go index 5272d60f..d28fe799 100644 --- a/src/k8splugin/internal/app/instance.go +++ b/src/k8splugin/internal/app/instance.go @@ -19,6 +19,7 @@ package app import ( "encoding/base64" "encoding/json" + "log" "math/rand" "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" @@ -46,10 +47,20 @@ type InstanceResponse struct { Resources []helm.KubernetesResource `json:"resources"` } +// InstanceMiniResponse contains the response from instantiation +// It does NOT include the created resources. +// Use the regular GET to get the created resources for a particular instance +type InstanceMiniResponse struct { + ID string `json:"id"` + Request InstanceRequest `json:"request"` + Namespace string `json:"namespace"` +} + // InstanceManager is an interface exposes the instantiation functionality type InstanceManager interface { Create(i InstanceRequest) (InstanceResponse, error) Get(id string) (InstanceResponse, error) + List() ([]InstanceMiniResponse, error) Find(rbName string, ver string, profile string, labelKeys map[string]string) ([]InstanceResponse, error) Delete(id string) error } @@ -171,6 +182,37 @@ func (v *InstanceClient) Get(id string) (InstanceResponse, error) { return InstanceResponse{}, pkgerrors.New("Error getting Instance") } +// List returns the instance for corresponding ID +// Empty string returns all +func (v *InstanceClient) List() ([]InstanceMiniResponse, error) { + + dbres, err := db.DBconn.ReadAll(v.storeName, v.tagInst) + if err != nil || len(dbres) == 0 { + return []InstanceMiniResponse{}, pkgerrors.Wrap(err, "Listing Instances") + } + + var results []InstanceMiniResponse + for key, value := range dbres { + //value is a byte array + if value != nil { + resp := InstanceResponse{} + err = db.DBconn.Unmarshal(value, &resp) + if err != nil { + log.Printf("[Instance] Error: %s Unmarshaling Instance: %s", err.Error(), key) + } + + miniresp := InstanceMiniResponse{ + ID: resp.ID, + Request: resp.Request, + Namespace: resp.Namespace, + } + results = append(results, miniresp) + } + } + + return results, nil +} + // Find returns the instances that match the given criteria // If version is empty, it will return all instances for a given rbName // If profile is empty, it will return all instances for a given rbName+version diff --git a/src/k8splugin/internal/app/instance_test.go b/src/k8splugin/internal/app/instance_test.go index 24558a44..3cb62ee1 100644 --- a/src/k8splugin/internal/app/instance_test.go +++ b/src/k8splugin/internal/app/instance_test.go @@ -51,7 +51,7 @@ func TestInstanceCreate(t *testing.T) { Items: map[string]map[string][]byte{ rb.ProfileKey{RBName: "test-rbdef", RBVersion: "v1", ProfileName: "profile1"}.String(): { - "metadata": []byte( + "profilemetadata": []byte( "{\"profile-name\":\"profile1\"," + "\"release-name\":\"testprofilereleasename\"," + "\"namespace\":\"testnamespace\"," + @@ -59,7 +59,7 @@ func TestInstanceCreate(t *testing.T) { "\"rb-version\":\"v1\"," + "\"kubernetesversion\":\"1.12.3\"}"), // base64 encoding of vagrant/tests/vnfs/testrb/helm/profile - "content": []byte("H4sICLmjT1wAA3Byb2ZpbGUudGFyAO1Y32/bNhD2s/6Kg/KyYZZsy" + + "profilecontent": []byte("H4sICLmjT1wAA3Byb2ZpbGUudGFyAO1Y32/bNhD2s/6Kg/KyYZZsy" + "78K78lLMsxY5gRxmqIYhoKWaJsYJWokZdfo+r/vSFmunCZNBtQJ1vF7sXX36e54vDN5T" + "knGFlTpcEtS3jgO2ohBr2c/EXc/29Gg1+h0e1F32Ol1B1Gj3Ymifr8B7SPFc4BCaSIBG" + "lII/SXeY/r/KIIg8NZUKiayEaw7nt7mdOQBrAkvqBqBL1ArWULflRJbJz4SYpEt2FJSJ" + @@ -84,13 +84,13 @@ func TestInstanceCreate(t *testing.T) { "yJ66WPQwcHBwcHBwcHBwcHBwcHBwcHhm8Q/mTHqWgAoAAA="), }, rb.DefinitionKey{RBName: "test-rbdef", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"test-rbdef\"," + "\"rb-version\":\"v1\"," + "\"chart-name\":\"vault-consul-dev\"," + "\"description\":\"testresourcebundle\"}"), // base64 encoding of vagrant/tests/vnfs/testrb/helm/vault-consul-dev - "content": []byte("H4sICEetS1wAA3ZhdWx0LWNvbnN1bC1kZXYudGFyAO0c7XLbNjK/+R" + + "defcontent": []byte("H4sICEetS1wAA3ZhdWx0LWNvbnN1bC1kZXYudGFyAO0c7XLbNjK/+R" + "QYujdJehatb+V4czPnOmnPk9bO2Gk7nbaTgUhIxpgiGAK0o3P9QPca92S3C5AU9GXZiax" + "c7rA/LJEAFovdxX4AK1/RIlGNSKSySBoxuzp4sn1oAgx6Pf0JsPipv7c63XZ70O61W4Mn" + "zVZ7MGg9Ib1HoGUJCqloTsiTXAh1V79N7V8oXC3K/+iC5iqY0kmytTlQwP1ud538W51Wf" + diff --git a/src/k8splugin/internal/config/config.go b/src/k8splugin/internal/config/config.go index 90204c99..ac653282 100644 --- a/src/k8splugin/internal/config/config.go +++ b/src/k8splugin/internal/config/config.go @@ -85,7 +85,7 @@ func defaultConfiguration() *Configuration { EtcdCert: "etcd.cert", EtcdKey: "etcd.key", EtcdCAFile: "etcd-ca.cert", - OVNCentralAddress: "127.0.0.1", + OVNCentralAddress: "127.0.0.1:6641", ServicePort: "9015", } } diff --git a/src/k8splugin/internal/rb/definition.go b/src/k8splugin/internal/rb/definition.go index 476e40ee..65ae8e00 100644 --- a/src/k8splugin/internal/rb/definition.go +++ b/src/k8splugin/internal/rb/definition.go @@ -79,8 +79,8 @@ type DefinitionClient struct { func NewDefinitionClient() *DefinitionClient { return &DefinitionClient{ storeName: "rbdef", - tagMeta: "metadata", - tagContent: "content", + tagMeta: "defmetadata", + tagContent: "defcontent", } } @@ -121,10 +121,13 @@ func (v *DefinitionClient) List(name string) ([]Definition, error) { log.Printf("[Definition] Error Unmarshaling value for: %s", key) continue } + //Select only the definitions that match name provided - if def.RBName == name { + //If name is empty, return all + if def.RBName == name || name == "" { results = append(results, def) } + } } diff --git a/src/k8splugin/internal/rb/definition_test.go b/src/k8splugin/internal/rb/definition_test.go index 054da2cd..0140b459 100644 --- a/src/k8splugin/internal/rb/definition_test.go +++ b/src/k8splugin/internal/rb/definition_test.go @@ -113,14 +113,14 @@ func TestListDefinition(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + "\"chart-name\":\"testchart\"}"), }, DefinitionKey{RBName: "testresourcebundle", RBVersion: "v2"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle_version2\"," + "\"rb-version\":\"v2\"," + @@ -196,7 +196,7 @@ func TestGetDefinition(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + @@ -326,7 +326,7 @@ func TestUploadDefinition(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"}"), @@ -362,7 +362,7 @@ func TestUploadDefinition(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + @@ -400,7 +400,7 @@ func TestUploadDefinition(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + @@ -438,7 +438,7 @@ func TestUploadDefinition(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + @@ -459,7 +459,7 @@ func TestUploadDefinition(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + @@ -551,12 +551,12 @@ func TestDownloadDefinition(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + "\"chart-name\":\"firewall\"}"), - "content": []byte("H4sICLBr9FsAA3Rlc3QudGFyAO3OQQrCMBCF4aw9RU5" + + "defcontent": []byte("H4sICLBr9FsAA3Rlc3QudGFyAO3OQQrCMBCF4aw9RU5" + "QEtLE40igAUtSC+2IHt9IEVwIpYtShP/bvGFmFk/SLI08Re3IVCG077Rn" + "b75zYZ2yztVV8N7XP9vWSWmzZ6mP+yxx0lrF7pJzjkN/Sz//1u5/6ppKG" + "R/jVLrT0VUAAAAAAAAAAAAAAAAAABu8ALXoSvkAKAAA"), @@ -572,7 +572,7 @@ func TestDownloadDefinition(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + diff --git a/src/k8splugin/internal/rb/profile.go b/src/k8splugin/internal/rb/profile.go index 37e9aba8..49768d4b 100644 --- a/src/k8splugin/internal/rb/profile.go +++ b/src/k8splugin/internal/rb/profile.go @@ -20,6 +20,7 @@ import ( "bytes" "encoding/base64" "encoding/json" + "log" "path/filepath" "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" @@ -44,6 +45,7 @@ type Profile struct { type ProfileManager interface { Create(def Profile) (Profile, error) Get(rbName, rbVersion, prName string) (Profile, error) + List(rbName, rbVersion string) ([]Profile, error) Delete(rbName, rbVersion, prName string) error Upload(rbName, rbVersion, prName string, inp []byte) error } @@ -78,8 +80,8 @@ type ProfileClient struct { func NewProfileClient() *ProfileClient { return &ProfileClient{ storeName: "rbdef", - tagMeta: "metadata", - tagContent: "content", + tagMeta: "profilemetadata", + tagContent: "profilecontent", manifestName: "manifest.yaml", } } @@ -148,6 +150,38 @@ func (v *ProfileClient) Get(rbName, rbVersion, prName string) (Profile, error) { return Profile{}, pkgerrors.New("Error getting Resource Bundle Profile") } +// List returns the Resource Bundle Profile for corresponding ID +func (v *ProfileClient) List(rbName, rbVersion string) ([]Profile, error) { + + //Get all profiles + dbres, err := db.DBconn.ReadAll(v.storeName, v.tagMeta) + if err != nil || len(dbres) == 0 { + return []Profile{}, pkgerrors.Wrap(err, "No Profiles Found") + } + + var results []Profile + for key, value := range dbres { + //value is a byte array + if value != nil { + pr := Profile{} + err = db.DBconn.Unmarshal(value, &pr) + if err != nil { + log.Printf("[Profile] Error: %s Unmarshaling value for: %s", err.Error(), key) + continue + } + if pr.RBName == rbName && pr.RBVersion == rbVersion { + results = append(results, pr) + } + } + } + + if len(results) == 0 { + return results, pkgerrors.New("No Profiles Found for Definition and Version") + } + + return results, nil +} + // Delete the Resource Bundle Profile from database func (v *ProfileClient) Delete(rbName, rbVersion, prName string) error { key := ProfileKey{ diff --git a/src/k8splugin/internal/rb/profile_test.go b/src/k8splugin/internal/rb/profile_test.go index 29efb506..26b0161d 100644 --- a/src/k8splugin/internal/rb/profile_test.go +++ b/src/k8splugin/internal/rb/profile_test.go @@ -18,11 +18,13 @@ package rb import ( "bytes" - "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" "reflect" + "sort" "strings" "testing" + "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" + pkgerrors "github.com/pkg/errors" ) @@ -56,7 +58,7 @@ func TestCreateProfile(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + @@ -79,7 +81,7 @@ func TestCreateProfile(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ DefinitionKey{RBName: "testresourcebundle", RBVersion: "v2"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"description\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + @@ -145,7 +147,7 @@ func TestGetProfile(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile1"}.String(): { - "metadata": []byte( + "profilemetadata": []byte( "{\"profile-name\":\"testprofile1\"," + "\"release-name\":\"testprofilereleasename\"," + "\"namespace\":\"testnamespace\"," + @@ -187,6 +189,106 @@ func TestGetProfile(t *testing.T) { } } +func TestListProfile(t *testing.T) { + + testCases := []struct { + label string + name string + rbdef string + version string + expectedError string + mockdb *db.MockDB + expected []Profile + }{ + { + label: "List Resource Bundle Profile", + name: "testresourcebundle", + rbdef: "testresourcebundle", + version: "v1", + expected: []Profile{ + { + ProfileName: "testprofile1", + ReleaseName: "testprofilereleasename", + Namespace: "testnamespace", + KubernetesVersion: "1.12.3", + RBName: "testresourcebundle", + RBVersion: "v1", + }, + { + ProfileName: "testprofile2", + ReleaseName: "testprofilereleasename2", + Namespace: "testnamespace2", + KubernetesVersion: "1.12.3", + RBName: "testresourcebundle", + RBVersion: "v1", + }, + }, + expectedError: "", + mockdb: &db.MockDB{ + Items: map[string]map[string][]byte{ + ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile1"}.String(): { + "profilemetadata": []byte( + "{\"profile-name\":\"testprofile1\"," + + "\"release-name\":\"testprofilereleasename\"," + + "\"namespace\":\"testnamespace\"," + + "\"rb-name\":\"testresourcebundle\"," + + "\"rb-version\":\"v1\"," + + "\"kubernetes-version\":\"1.12.3\"}"), + }, + ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile2"}.String(): { + "profilemetadata": []byte( + "{\"profile-name\":\"testprofile2\"," + + "\"release-name\":\"testprofilereleasename2\"," + + "\"namespace\":\"testnamespace2\"," + + "\"rb-name\":\"testresourcebundle\"," + + "\"rb-version\":\"v1\"," + + "\"kubernetes-version\":\"1.12.3\"}"), + }, + }, + }, + }, + { + label: "List Error", + expectedError: "DB Error", + mockdb: &db.MockDB{ + Err: pkgerrors.New("DB Error"), + }, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.label, func(t *testing.T) { + db.DBconn = testCase.mockdb + impl := NewProfileClient() + got, err := impl.List(testCase.rbdef, testCase.version) + if err != nil { + if testCase.expectedError == "" { + t.Fatalf("List returned an unexpected error %s", err) + } + if strings.Contains(err.Error(), testCase.expectedError) == false { + t.Fatalf("List returned an unexpected error %s", err) + } + } else { + // Since the order of returned slice is not guaranteed + // Check both and return error if both don't match + sort.Slice(got, func(i, j int) bool { + return got[i].ProfileName < got[j].ProfileName + }) + // Sort both as it is not expected that testCase.expected + // is sorted + sort.Slice(testCase.expected, func(i, j int) bool { + return testCase.expected[i].ProfileName < testCase.expected[j].ProfileName + }) + + if reflect.DeepEqual(testCase.expected, got) == false { + t.Errorf("List Resource Bundle returned unexpected body: got %v;"+ + " expected %v", got, testCase.expected) + } + } + }) + } +} + func TestDeleteProfile(t *testing.T) { testCases := []struct { @@ -265,7 +367,7 @@ func TestUploadProfile(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile1"}.String(): { - "metadata": []byte( + "profilemetadata": []byte( "{\"profile-name\":\"testprofile1\"," + "\"release-name\":\"testprofilereleasename\"," + "\"namespace\":\"testnamespace\"," + @@ -306,7 +408,7 @@ func TestUploadProfile(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile2"}.String(): { - "metadata": []byte( + "profilemetadata": []byte( "{\"profile-name\":\"testprofile1\"," + "\"release-name\":\"testprofilereleasename\"," + "\"namespace\":\"testnamespace\"," + @@ -330,7 +432,7 @@ func TestUploadProfile(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile1"}.String(): { - "metadata": []byte( + "profilemetadata": []byte( "{\"profile-name\":\"testprofile1\"," + "\"release-name\":\"testprofilereleasename\"," + "\"namespace\":\"testnamespace\"," + @@ -425,14 +527,14 @@ func TestDownloadProfile(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile1"}.String(): { - "metadata": []byte( + "profilemetadata": []byte( "{\"profile-name\":\"testprofile1\"," + "\"release-name\":\"testprofilereleasename\"," + "\"namespace\":\"testnamespace\"," + "\"rb-name\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + "\"kubernetesversion\":\"1.12.3\"}"), - "content": []byte("H4sICLBr9FsAA3Rlc3QudGFyAO3OQQrCMBCF4aw9RU5" + + "profilecontent": []byte("H4sICLBr9FsAA3Rlc3QudGFyAO3OQQrCMBCF4aw9RU5" + "QEtLE40igAUtSC+2IHt9IEVwIpYtShP/bvGFmFk/SLI08Re3IVCG077Rn" + "b75zYZ2yztVV8N7XP9vWSWmzZ6mP+yxx0lrF7pJzjkN/Sz//1u5/6ppKG" + "R/jVLrT0VUAAAAAAAAAAAAAAAAAABu8ALXoSvkAKAAA"), @@ -449,7 +551,7 @@ func TestDownloadProfile(t *testing.T) { mockdb: &db.MockDB{ Items: map[string]map[string][]byte{ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile2"}.String(): { - "metadata": []byte( + "profilemetadata": []byte( "{\"profile-name\":\"testprofile1\"," + "\"release-name\":\"testprofilereleasename\"," + "\"namespace\":\"testnamespace\"," + @@ -512,7 +614,7 @@ func TestResolveProfile(t *testing.T) { Items: map[string]map[string][]byte{ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "profile1"}.String(): { - "metadata": []byte( + "profilemetadata": []byte( "{\"profile-name\":\"profile1\"," + "\"release-name\":\"testprofilereleasename\"," + "\"namespace\":\"testnamespace\"," + @@ -520,7 +622,7 @@ func TestResolveProfile(t *testing.T) { "\"rb-version\":\"v1\"," + "\"kubernetesversion\":\"1.12.3\"}"), // base64 encoding of vagrant/tests/vnfs/testrb/helm/profile - "content": []byte("H4sICLmjT1wAA3Byb2ZpbGUudGFyAO1Y32/bNhD2s/6Kg/KyYZZsy" + + "profilecontent": []byte("H4sICLmjT1wAA3Byb2ZpbGUudGFyAO1Y32/bNhD2s/6Kg/KyYZZsy" + "78K78lLMsxY5gRxmqIYhoKWaJsYJWokZdfo+r/vSFmunCZNBtQJ1vF7sXX36e54vDN5T" + "knGFlTpcEtS3jgO2ohBr2c/EXc/29Gg1+h0e1F32Ol1B1Gj3Ymifr8B7SPFc4BCaSIBG" + "lII/SXeY/r/KIIg8NZUKiayEaw7nt7mdOQBrAkvqBqBL1ArWULflRJbJz4SYpEt2FJSJ" + @@ -545,13 +647,13 @@ func TestResolveProfile(t *testing.T) { "yJ66WPQwcHBwcHBwcHBwcHBwcHBwcHhm8Q/mTHqWgAoAAA="), }, DefinitionKey{RBName: "testresourcebundle", RBVersion: "v1"}.String(): { - "metadata": []byte( + "defmetadata": []byte( "{\"rb-name\":\"testresourcebundle\"," + "\"rb-version\":\"v1\"," + "\"chart-name\":\"vault-consul-dev\"," + "\"description\":\"testresourcebundle\"}"), // base64 encoding of vagrant/tests/vnfs/testrb/helm/vault-consul-dev - "content": []byte("H4sICEetS1wAA3ZhdWx0LWNvbnN1bC1kZXYudGFyAO0c7XLbNjK/+R" + + "defcontent": []byte("H4sICEetS1wAA3ZhdWx0LWNvbnN1bC1kZXYudGFyAO0c7XLbNjK/+R" + "QYujdJehatb+V4czPnOmnPk9bO2Gk7nbaTgUhIxpgiGAK0o3P9QPca92S3C5AU9GXZiax" + "c7rA/LJEAFovdxX4AK1/RIlGNSKSySBoxuzp4sn1oAgx6Pf0JsPipv7c63XZ70O61W4Mn" + "zVZ7MGg9Ib1HoGUJCqloTsiTXAh1V79N7V8oXC3K/+iC5iqY0kmytTlQwP1ud538W51Wf" + diff --git a/src/k8splugin/plugins/network/plugin.go b/src/k8splugin/plugins/network/plugin.go index e69a075b..ca5aa959 100644 --- a/src/k8splugin/plugins/network/plugin.go +++ b/src/k8splugin/plugins/network/plugin.go @@ -18,8 +18,8 @@ import ( "regexp" utils "github.com/onap/multicloud-k8s/src/k8splugin/internal" - "github.com/onap/multicloud-k8s/src/k8splugin/internal/app" "github.com/onap/multicloud-k8s/src/k8splugin/internal/helm" + "github.com/onap/multicloud-k8s/src/k8splugin/internal/plugin" pkgerrors "github.com/pkg/errors" "k8s.io/apimachinery/pkg/runtime/schema" @@ -43,7 +43,7 @@ func extractData(data string) (cniType, networkName string) { } // Create an ONAP Network object -func (p networkPlugin) Create(yamlFilePath string, namespace string, client *app.KubernetesClient) (string, error) { +func (p networkPlugin) Create(yamlFilePath string, namespace string, client plugin.KubernetesConnector) (string, error) { network := &v1.OnapNetwork{} if _, err := utils.DecodeYAML(yamlFilePath, network); err != nil { return "", pkgerrors.Wrap(err, "Decode network object error") @@ -69,19 +69,19 @@ func (p networkPlugin) Create(yamlFilePath string, namespace string, client *app } // Get a Network -func (p networkPlugin) Get(resource helm.KubernetesResource, namespace string, client *app.KubernetesClient) (string, error) { +func (p networkPlugin) Get(resource helm.KubernetesResource, namespace string, client plugin.KubernetesConnector) (string, error) { return "", nil } // List of Networks func (p networkPlugin) List(gvk schema.GroupVersionKind, namespace string, - client *app.KubernetesClient) ([]helm.KubernetesResource, error) { + client plugin.KubernetesConnector) ([]helm.KubernetesResource, error) { return nil, nil } // Delete an existing Network -func (p networkPlugin) Delete(resource helm.KubernetesResource, namespace string, client *app.KubernetesClient) error { +func (p networkPlugin) Delete(resource helm.KubernetesResource, namespace string, client plugin.KubernetesConnector) error { cniType, networkName := extractData(resource.Name) typePlugin, ok := utils.LoadedPlugins[cniType+"-network"] if !ok { |