aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin')
-rw-r--r--src/k8splugin/api/brokerhandler_test.go20
-rw-r--r--src/k8splugin/api/instancehandler_test.go40
-rw-r--r--src/k8splugin/internal/app/config_backend.go4
-rw-r--r--src/k8splugin/internal/app/instance.go35
-rw-r--r--src/k8splugin/internal/app/instance_test.go174
5 files changed, 153 insertions, 120 deletions
diff --git a/src/k8splugin/api/brokerhandler_test.go b/src/k8splugin/api/brokerhandler_test.go
index e7ff08c4..82894412 100644
--- a/src/k8splugin/api/brokerhandler_test.go
+++ b/src/k8splugin/api/brokerhandler_test.go
@@ -112,10 +112,12 @@ func TestBrokerCreateHandler(t *testing.T) {
items: []app.InstanceResponse{
{
ID: "HaKpys8e",
- RBName: "test-rbdef",
- RBVersion: "v1",
- ProfileName: "profile1",
- CloudRegion: "region1",
+ Request: app.InstanceRequest{
+ RBName: "test-rbdef",
+ RBVersion: "v1",
+ ProfileName: "profile1",
+ CloudRegion: "region1",
+ },
Namespace: "testnamespace",
Resources: []helm.KubernetesResource{
{
@@ -195,10 +197,12 @@ func TestBrokerGetHandler(t *testing.T) {
items: []app.InstanceResponse{
{
ID: "HaKpys8e",
- RBName: "test-rbdef",
- RBVersion: "v1",
- ProfileName: "profile1",
- CloudRegion: "region1",
+ Request: app.InstanceRequest{
+ RBName: "test-rbdef",
+ RBVersion: "v1",
+ ProfileName: "profile1",
+ CloudRegion: "region1",
+ },
Namespace: "testnamespace",
Resources: []helm.KubernetesResource{
{
diff --git a/src/k8splugin/api/instancehandler_test.go b/src/k8splugin/api/instancehandler_test.go
index 6d2abf6f..2e2450ed 100644
--- a/src/k8splugin/api/instancehandler_test.go
+++ b/src/k8splugin/api/instancehandler_test.go
@@ -105,10 +105,12 @@ func TestInstanceCreateHandler(t *testing.T) {
}`)),
expected: app.InstanceResponse{
ID: "HaKpys8e",
- RBName: "test-rbdef",
- RBVersion: "v1",
- ProfileName: "profile1",
- CloudRegion: "region1",
+ Request: app.InstanceRequest{
+ RBName: "test-rbdef",
+ RBVersion: "v1",
+ ProfileName: "profile1",
+ CloudRegion: "region1",
+ },
Namespace: "testnamespace",
Resources: []helm.KubernetesResource{
{
@@ -132,10 +134,12 @@ func TestInstanceCreateHandler(t *testing.T) {
items: []app.InstanceResponse{
{
ID: "HaKpys8e",
- RBName: "test-rbdef",
- RBVersion: "v1",
- ProfileName: "profile1",
- CloudRegion: "region1",
+ Request: app.InstanceRequest{
+ RBName: "test-rbdef",
+ RBVersion: "v1",
+ ProfileName: "profile1",
+ CloudRegion: "region1",
+ },
Namespace: "testnamespace",
Resources: []helm.KubernetesResource{
{
@@ -204,10 +208,12 @@ func TestInstanceGetHandler(t *testing.T) {
expectedCode: http.StatusOK,
expectedResponse: &app.InstanceResponse{
ID: "HaKpys8e",
- RBName: "test-rbdef",
- RBVersion: "v1",
- ProfileName: "profile1",
- CloudRegion: "region1",
+ Request: app.InstanceRequest{
+ RBName: "test-rbdef",
+ RBVersion: "v1",
+ ProfileName: "profile1",
+ CloudRegion: "region1",
+ },
Namespace: "testnamespace",
Resources: []helm.KubernetesResource{
{
@@ -230,10 +236,12 @@ func TestInstanceGetHandler(t *testing.T) {
items: []app.InstanceResponse{
{
ID: "HaKpys8e",
- RBName: "test-rbdef",
- RBVersion: "v1",
- ProfileName: "profile1",
- CloudRegion: "region1",
+ Request: app.InstanceRequest{
+ RBName: "test-rbdef",
+ RBVersion: "v1",
+ ProfileName: "profile1",
+ CloudRegion: "region1",
+ },
Namespace: "testnamespace",
Resources: []helm.KubernetesResource{
{
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": {