summaryrefslogtreecommitdiffstats
path: root/src/k8splugin
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin')
-rw-r--r--src/k8splugin/api/api.go4
-rw-r--r--src/k8splugin/api/confighandler.go15
-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
5 files changed, 60 insertions, 21 deletions
diff --git a/src/k8splugin/api/api.go b/src/k8splugin/api/api.go
index 5fed28a0..0ddbcf83 100644
--- a/src/k8splugin/api/api.go
+++ b/src/k8splugin/api/api.go
@@ -25,7 +25,7 @@ import (
func NewRouter(defClient rb.DefinitionManager,
profileClient rb.ProfileManager,
instClient app.InstanceManager,
- configClient rb.ConfigManager,
+ configClient app.ConfigManager,
templateClient rb.ConfigTemplateManager) *mux.Router {
router := mux.NewRouter()
@@ -91,7 +91,7 @@ func NewRouter(defClient rb.DefinitionManager,
// Config value
if configClient == nil {
- configClient = rb.NewConfigClient()
+ configClient = app.NewConfigClient()
}
configHandler := rbConfigHandler{client: configClient}
resRouter.HandleFunc("/definition/{rbname}/{rbversion}/profile/{prname}/config", configHandler.createHandler).Methods("POST")
diff --git a/src/k8splugin/api/confighandler.go b/src/k8splugin/api/confighandler.go
index 93098d61..9bd9db83 100644
--- a/src/k8splugin/api/confighandler.go
+++ b/src/k8splugin/api/confighandler.go
@@ -18,9 +18,10 @@ package api
import (
"encoding/json"
- "k8splugin/internal/rb"
"net/http"
+ "k8splugin/internal/app"
+
"github.com/gorilla/mux"
)
@@ -29,12 +30,12 @@ import (
type rbConfigHandler struct {
// Interface that implements bundle Definition operations
// We will set this variable with a mock interface for testing
- client rb.ConfigManager
+ client app.ConfigManager
}
// createHandler handles creation of the definition entry in the database
func (h rbConfigHandler) createHandler(w http.ResponseWriter, r *http.Request) {
- var p rb.Config
+ var p app.Config
vars := mux.Vars(r)
rbName := vars["rbname"]
rbVersion := vars["rbversion"]
@@ -73,7 +74,7 @@ func (h rbConfigHandler) createHandler(w http.ResponseWriter, r *http.Request) {
}
// getHandler handles GET operations on a particular config
-// Returns a rb.Definition
+// Returns a app.Definition
func (h rbConfigHandler) getHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
rbName := vars["rbname"]
@@ -128,7 +129,7 @@ func (h rbConfigHandler) updateHandler(w http.ResponseWriter, r *http.Request) {
prName := vars["prname"]
cfgName := vars["cfgname"]
- var p rb.Config
+ var p app.Config
if r.Body == nil {
http.Error(w, "Empty body", http.StatusBadRequest)
@@ -168,7 +169,7 @@ func (h rbConfigHandler) rollbackHandler(w http.ResponseWriter, r *http.Request)
return
}
- var p rb.ConfigRollback
+ var p app.ConfigRollback
err := json.NewDecoder(r.Body).Decode(&p)
if err != nil {
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
@@ -194,7 +195,7 @@ func (h rbConfigHandler) tagitHandler(w http.ResponseWriter, r *http.Request) {
return
}
- var p rb.ConfigTagit
+ var p app.ConfigTagit
err := json.NewDecoder(r.Body).Decode(&p)
if err != nil {
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
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"