aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal
diff options
context:
space:
mode:
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"