summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-05-15 16:47:39 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-05-15 16:47:49 -0700
commit401aba14c5f5e55480afb491af2bf953cabc6ac2 (patch)
tree0a0d855f97f749ed3b8020ac4f5d99528948fa8a /src/k8splugin/internal
parent881bb510d7f0b7a3f1110589e8aa3596e655e38c (diff)
Move config to app and connect to instance
Move config instantiation to app and connect it to the instance to allow updates and so on. Issue-ID: MULTICLOUD-464 Change-Id: Ic994ef78a6e0d2db5e695e33b7b8a302c74c10da Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal')
-rw-r--r--src/k8splugin/internal/app/config.go (renamed from src/k8splugin/internal/rb/config.go)8
-rw-r--r--src/k8splugin/internal/app/config_backend.go (renamed from src/k8splugin/internal/rb/config_backend.go)52
-rw-r--r--src/k8splugin/internal/app/config_test.go (renamed from src/k8splugin/internal/rb/config_test.go)2
3 files changed, 50 insertions, 12 deletions
diff --git a/src/k8splugin/internal/rb/config.go b/src/k8splugin/internal/app/config.go
index 3bd8347b..f7e81358 100644
--- a/src/k8splugin/internal/rb/config.go
+++ b/src/k8splugin/internal/app/config.go
@@ -14,13 +14,15 @@
* limitations under the License.
*/
-package rb
+package app
import (
- pkgerrors "github.com/pkg/errors"
- "k8splugin/internal/db"
"strconv"
"strings"
+
+ "k8splugin/internal/db"
+
+ pkgerrors "github.com/pkg/errors"
)
// Config contains the parameters needed for configuration
diff --git a/src/k8splugin/internal/rb/config_backend.go b/src/k8splugin/internal/app/config_backend.go
index e2fa5b3c..763aed0d 100644
--- a/src/k8splugin/internal/rb/config_backend.go
+++ b/src/k8splugin/internal/app/config_backend.go
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package rb
+package app
import (
"bytes"
@@ -25,9 +25,11 @@ import (
"strconv"
"strings"
"sync"
+ "time"
"k8splugin/internal/db"
"k8splugin/internal/helm"
+ "k8splugin/internal/rb"
"github.com/ghodss/yaml"
pkgerrors "github.com/pkg/errors"
@@ -57,7 +59,8 @@ type ConfigVersionStore struct {
type configResourceList struct {
resourceTemplates []helm.KubernetesResourceTemplate
- profile Profile
+ createdResources []helm.KubernetesResource
+ profile rb.Profile
action string
}
@@ -339,17 +342,50 @@ func scheduleResources(c chan configResourceList) {
for {
data := <-c
//TODO: ADD Check to see if Application running
+ ic := NewInstanceClient()
+ resp, err := ic.Find(data.profile.RBName, data.profile.RBVersion, data.profile.ProfileName)
+ if err != nil || len(resp) == 0 {
+ log.Println("Error finding a running instance. Retrying later...")
+ time.Sleep(time.Second * 10)
+ continue
+ }
switch {
case data.action == "POST":
log.Printf("[scheduleResources]: POST %v %v", data.profile, data.resourceTemplates)
+ for _, inst := range resp {
+ k8sClient := KubernetesClient{}
+ err = k8sClient.init(inst.CloudRegion)
+ if err != nil {
+ log.Printf("Getting CloudRegion Information: %s", err.Error())
+ //Move onto the next cloud region
+ continue
+ }
+ data.createdResources, err = k8sClient.createResources(data.resourceTemplates, inst.Namespace)
+ if err != nil {
+ log.Printf("Error Creating resources: %s", err.Error())
+ continue
+ }
+ }
//TODO: Needs to add code to call Kubectl create
case data.action == "PUT":
log.Printf("[scheduleResources]: PUT %v %v", data.profile, data.resourceTemplates)
//TODO: Needs to add code to call Kubectl apply
case data.action == "DELETE":
log.Printf("[scheduleResources]: DELETE %v %v", data.profile, data.resourceTemplates)
- //TODO: Needs to add code to call Kubectl delete
-
+ for _, inst := range resp {
+ k8sClient := KubernetesClient{}
+ err = k8sClient.init(inst.CloudRegion)
+ if err != nil {
+ log.Printf("Getting CloudRegion Information: %s", err.Error())
+ //Move onto the next cloud region
+ continue
+ }
+ err = k8sClient.deleteResources(data.createdResources, inst.Namespace)
+ if err != nil {
+ log.Printf("Error Deleting resources: %s", err.Error())
+ continue
+ }
+ }
}
}
}
@@ -360,12 +396,12 @@ var resolve = func(rbName, rbVersion, profileName string, p Config) (configResou
var resTemplates []helm.KubernetesResourceTemplate
- profile, err := NewProfileClient().Get(rbName, rbVersion, profileName)
+ profile, err := rb.NewProfileClient().Get(rbName, rbVersion, profileName)
if err != nil {
return configResourceList{}, pkgerrors.Wrap(err, "Reading Profile Data")
}
- t, err := NewConfigTemplateClient().Get(rbName, rbVersion, p.TemplateName)
+ t, err := rb.NewConfigTemplateClient().Get(rbName, rbVersion, p.TemplateName)
if err != nil {
return configResourceList{}, pkgerrors.Wrap(err, "Getting Template")
}
@@ -373,7 +409,7 @@ var resolve = func(rbName, rbVersion, profileName string, p Config) (configResou
return configResourceList{}, pkgerrors.New("Invalid template no Chart.yaml file found")
}
- def, err := NewConfigTemplateClient().Download(rbName, rbVersion, p.TemplateName)
+ def, err := rb.NewConfigTemplateClient().Download(rbName, rbVersion, p.TemplateName)
if err != nil {
return configResourceList{}, pkgerrors.Wrap(err, "Downloading Template")
}
@@ -398,7 +434,7 @@ var resolve = func(rbName, rbVersion, profileName string, p Config) (configResou
}
defer outputfile.Close()
- chartBasePath, err := ExtractTarBall(bytes.NewBuffer(def))
+ chartBasePath, err := rb.ExtractTarBall(bytes.NewBuffer(def))
if err != nil {
return configResourceList{}, pkgerrors.Wrap(err, "Extracting Template")
}
diff --git a/src/k8splugin/internal/rb/config_test.go b/src/k8splugin/internal/app/config_test.go
index 9bf97a51..11a300ff 100644
--- a/src/k8splugin/internal/rb/config_test.go
+++ b/src/k8splugin/internal/app/config_test.go
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package rb
+package app
import (
"k8splugin/internal/db"