diff options
author | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-05-22 23:48:26 -0700 |
---|---|---|
committer | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-05-22 23:53:27 -0700 |
commit | 525023e1d288bbf9cf59584c5b5dd37d83be7a4b (patch) | |
tree | bebc995e431abe5fc6b6421fdcb80b6dce8c0ce0 /src/k8splugin/internal | |
parent | 352080a39d582a767d5908ab3372ac10d59a2261 (diff) |
Minor change to instance response
Minor change to instance response. Now it includes
the full request parameters in the response.
Issue-ID: MULTICLOUD-649
Change-Id: Ia4a7e479f842dd580bcfb13aa91dc0b0a456cf25
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal')
-rw-r--r-- | src/k8splugin/internal/app/config_backend.go | 4 | ||||
-rw-r--r-- | src/k8splugin/internal/app/instance.go | 35 | ||||
-rw-r--r-- | src/k8splugin/internal/app/instance_test.go | 174 |
3 files changed, 117 insertions, 96 deletions
diff --git a/src/k8splugin/internal/app/config_backend.go b/src/k8splugin/internal/app/config_backend.go index 763aed0d..81696b3a 100644 --- a/src/k8splugin/internal/app/config_backend.go +++ b/src/k8splugin/internal/app/config_backend.go @@ -354,7 +354,7 @@ func scheduleResources(c chan configResourceList) { log.Printf("[scheduleResources]: POST %v %v", data.profile, data.resourceTemplates) for _, inst := range resp { k8sClient := KubernetesClient{} - err = k8sClient.init(inst.CloudRegion) + err = k8sClient.init(inst.Request.CloudRegion) if err != nil { log.Printf("Getting CloudRegion Information: %s", err.Error()) //Move onto the next cloud region @@ -374,7 +374,7 @@ func scheduleResources(c chan configResourceList) { log.Printf("[scheduleResources]: DELETE %v %v", data.profile, data.resourceTemplates) for _, inst := range resp { k8sClient := KubernetesClient{} - err = k8sClient.init(inst.CloudRegion) + err = k8sClient.init(inst.Request.CloudRegion) if err != nil { log.Printf("Getting CloudRegion Information: %s", err.Error()) //Move onto the next cloud region diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go index 41eca211..fe9f3857 100644 --- a/src/k8splugin/internal/app/instance.go +++ b/src/k8splugin/internal/app/instance.go @@ -40,13 +40,10 @@ type InstanceRequest struct { // InstanceResponse contains the response from instantiation type InstanceResponse struct { - ID string `json:"id"` - RBName string `json:"rb-name"` - RBVersion string `json:"rb-version"` - ProfileName string `json:"profile-name"` - CloudRegion string `json:"cloud-region"` - Namespace string `json:"namespace"` - Resources []helm.KubernetesResource `json:"resources"` + ID string `json:"id"` + Request InstanceRequest `json:"request"` + Namespace string `json:"namespace"` + Resources []helm.KubernetesResource `json:"resources"` } // InstanceManager is an interface exposes the instantiation functionality @@ -134,13 +131,15 @@ func (v *InstanceClient) Create(i InstanceRequest) (InstanceResponse, error) { //Compose the return response resp := InstanceResponse{ - ID: id, - RBName: i.RBName, - RBVersion: i.RBVersion, - ProfileName: i.ProfileName, - CloudRegion: i.CloudRegion, - Namespace: profile.Namespace, - Resources: createdResources, + ID: id, + Request: InstanceRequest{ + RBName: i.RBName, + RBVersion: i.RBVersion, + ProfileName: i.ProfileName, + CloudRegion: i.CloudRegion, + }, + Namespace: profile.Namespace, + Resources: createdResources, } key := InstanceKey{ @@ -199,13 +198,13 @@ func (v *InstanceClient) Find(rbName string, version string, profile string) ([] return []InstanceResponse{}, pkgerrors.Wrap(err, "Unmarshaling Instance Value") } - if resp.RBName == rbName { + if resp.Request.RBName == rbName { //Check if a version is provided and if it matches if version != "" { - if resp.RBVersion == version { + if resp.Request.RBVersion == version { //Check if a profilename matches or if it is not provided - if profile == "" || resp.ProfileName == profile { + if profile == "" || resp.Request.ProfileName == profile { response = append(response, resp) } } @@ -227,7 +226,7 @@ func (v *InstanceClient) Delete(id string) error { } k8sClient := KubernetesClient{} - err = k8sClient.init(inst.CloudRegion) + err = k8sClient.init(inst.Request.CloudRegion) if err != nil { return pkgerrors.Wrap(err, "Getting CloudRegion Information") } diff --git a/src/k8splugin/internal/app/instance_test.go b/src/k8splugin/internal/app/instance_test.go index 2fa2115b..87824d74 100644 --- a/src/k8splugin/internal/app/instance_test.go +++ b/src/k8splugin/internal/app/instance_test.go @@ -203,12 +203,14 @@ func TestInstanceGet(t *testing.T) { InstanceKey{ID: "HaKpys8e"}.String(): { "instance": []byte( `{ - "profile-name":"profile1", - "id":"HaKpys8e", + "id":"HaKpys8e", + "request": { + "profile-name":"profile1", + "rb-name":"test-rbdef", + "rb-version":"v1", + "cloud-region":"region1" + }, "namespace":"testnamespace", - "rb-name":"test-rbdef", - "rb-version":"v1", - "cloud-region":"region1", "resources": [ { "GVK": { @@ -233,13 +235,14 @@ func TestInstanceGet(t *testing.T) { } expected := InstanceResponse{ - ID: "HaKpys8e", - RBName: "test-rbdef", - RBVersion: "v1", - ProfileName: "profile1", - CloudRegion: "region1", - Namespace: "testnamespace", - + ID: "HaKpys8e", + Request: InstanceRequest{ + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile1", + CloudRegion: "region1", + }, + Namespace: "testnamespace", Resources: []helm.KubernetesResource{ { GVK: schema.GroupVersionKind{ @@ -275,12 +278,14 @@ func TestInstanceGet(t *testing.T) { InstanceKey{ID: "HaKpys8e"}.String(): { "instance": []byte( `{ - "profile-name":"profile1", - "id":"HaKpys8e", + "id":"HaKpys8e", + "request": { + "profile-name":"profile1", + "rb-name":"test-rbdef", + "rb-version":"v1", + "cloud-region":"region1" + }, "namespace":"testnamespace", - "rb-name":"test-rbdef", - "rb-version":"v1", - "cloud-region":"region1", "resources": [ { "GVK": { @@ -329,12 +334,14 @@ func TestInstanceFind(t *testing.T) { InstanceKey{ID: "HaKpys8e"}.String(): { "instance": []byte( `{ - "profile-name":"profile1", - "id":"HaKpys8e", + "id":"HaKpys8e", + "request": { + "profile-name":"profile1", + "rb-name":"test-rbdef", + "rb-version":"v1", + "cloud-region":"region1" + }, "namespace":"testnamespace", - "rb-name":"test-rbdef", - "rb-version":"v1", - "cloud-region":"region1", "resources": [ { "GVK": { @@ -358,12 +365,14 @@ func TestInstanceFind(t *testing.T) { InstanceKey{ID: "HaKpys8f"}.String(): { "instance": []byte( `{ - "profile-name":"profile2", - "id":"HaKpys8f", + "id":"HaKpys8f", + "request": { + "profile-name":"profile2", + "rb-name":"test-rbdef", + "rb-version":"v1", + "cloud-region":"region1" + }, "namespace":"testnamespace", - "rb-name":"test-rbdef", - "rb-version":"v1", - "cloud-region":"region1", "resources": [ { "GVK": { @@ -387,12 +396,14 @@ func TestInstanceFind(t *testing.T) { InstanceKey{ID: "HaKpys8g"}.String(): { "instance": []byte( `{ - "profile-name":"profile1", - "id":"HaKpys8g", + "id":"HaKpys8g", + "request": { + "profile-name":"profile1", + "rb-name":"test-rbdef", + "rb-version":"v2", + "cloud-region":"region1" + }, "namespace":"testnamespace", - "rb-name":"test-rbdef", - "rb-version":"v2", - "cloud-region":"region1", "resources": [ { "GVK": { @@ -422,13 +433,14 @@ func TestInstanceFind(t *testing.T) { expected := []InstanceResponse{ { - ID: "HaKpys8e", - RBName: "test-rbdef", - RBVersion: "v1", - ProfileName: "profile1", - CloudRegion: "region1", - Namespace: "testnamespace", - + ID: "HaKpys8e", + Request: InstanceRequest{ + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile1", + CloudRegion: "region1", + }, + Namespace: "testnamespace", Resources: []helm.KubernetesResource{ { GVK: schema.GroupVersionKind{ @@ -447,13 +459,14 @@ func TestInstanceFind(t *testing.T) { }, }, { - ID: "HaKpys8f", - RBName: "test-rbdef", - RBVersion: "v1", - ProfileName: "profile2", - CloudRegion: "region1", - Namespace: "testnamespace", - + ID: "HaKpys8f", + Request: InstanceRequest{ + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile2", + CloudRegion: "region1", + }, + Namespace: "testnamespace", Resources: []helm.KubernetesResource{ { GVK: schema.GroupVersionKind{ @@ -472,13 +485,14 @@ func TestInstanceFind(t *testing.T) { }, }, { - ID: "HaKpys8g", - RBName: "test-rbdef", - RBVersion: "v2", - ProfileName: "profile1", - CloudRegion: "region1", - Namespace: "testnamespace", - + ID: "HaKpys8g", + Request: InstanceRequest{ + RBName: "test-rbdef", + RBVersion: "v2", + ProfileName: "profile1", + CloudRegion: "region1", + }, + Namespace: "testnamespace", Resources: []helm.KubernetesResource{ { GVK: schema.GroupVersionKind{ @@ -528,12 +542,14 @@ func TestInstanceFind(t *testing.T) { expected := []InstanceResponse{ { - ID: "HaKpys8e", - RBName: "test-rbdef", - RBVersion: "v1", - ProfileName: "profile1", - CloudRegion: "region1", - Namespace: "testnamespace", + ID: "HaKpys8e", + Request: InstanceRequest{ + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile1", + CloudRegion: "region1", + }, + Namespace: "testnamespace", Resources: []helm.KubernetesResource{ { @@ -553,12 +569,14 @@ func TestInstanceFind(t *testing.T) { }, }, { - ID: "HaKpys8f", - RBName: "test-rbdef", - RBVersion: "v1", - ProfileName: "profile2", - CloudRegion: "region1", - Namespace: "testnamespace", + ID: "HaKpys8f", + Request: InstanceRequest{ + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile2", + CloudRegion: "region1", + }, + Namespace: "testnamespace", Resources: []helm.KubernetesResource{ { @@ -609,12 +627,14 @@ func TestInstanceFind(t *testing.T) { expected := []InstanceResponse{ { - ID: "HaKpys8e", - RBName: "test-rbdef", - RBVersion: "v1", - ProfileName: "profile1", - CloudRegion: "region1", - Namespace: "testnamespace", + ID: "HaKpys8e", + Request: InstanceRequest{ + RBName: "test-rbdef", + RBVersion: "v1", + ProfileName: "profile1", + CloudRegion: "region1", + }, + Namespace: "testnamespace", Resources: []helm.KubernetesResource{ { @@ -726,12 +746,14 @@ func TestInstanceDelete(t *testing.T) { InstanceKey{ID: "HaKpys8e"}.String(): { "instance": []byte( `{ - "profile-name":"profile1", - "id":"HaKpys8e", + "id":"HaKpys8e", + "request": { + "profile-name":"profile1", + "rb-name":"test-rbdef", + "rb-version":"v1", + "cloud-region":"mock_connection" + }, "namespace":"testnamespace", - "rb-name":"test-rbdef", - "rb-version":"v1", - "cloud-region":"mock_connection", "resources": [ { "GVK": { |