summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/rb
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@orange.com>2022-02-03 19:18:07 +0100
committerLukasz Rajewski <lukasz.rajewski@orange.com>2022-02-23 14:27:01 +0100
commit88ecb1f9dfeded36e7fd74c776daefcaf67f8ae2 (patch)
tree321eb34967dd32a43d7e3ac62b5fd664e5b2231b /src/k8splugin/internal/rb
parent1f92a0ec4ea037089b82e3f80bb030f34fab64f0 (diff)
ConfigAPI and Query API improvements
- Config Template create from the definition content - Missing CRUD Config handlers added - Improved Rollback and Config delete - Query API name filtering improved Issue-ID: MULTICLOUD-1437 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com> Change-Id: Iec8ec6d03746085f294d9318a252f1ae45d3b9c8
Diffstat (limited to 'src/k8splugin/internal/rb')
-rw-r--r--src/k8splugin/internal/rb/config_template.go31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/k8splugin/internal/rb/config_template.go b/src/k8splugin/internal/rb/config_template.go
index 97fe0fb4..06576e5d 100644
--- a/src/k8splugin/internal/rb/config_template.go
+++ b/src/k8splugin/internal/rb/config_template.go
@@ -36,14 +36,20 @@ import (
type ConfigTemplate struct {
TemplateName string `json:"template-name"`
Description string `json:"description"`
- ChartName string
+ ChartName string `json:"chart-name"`
+ HasContent bool `json:"has-content"`
+}
+
+type ConfigTemplateList struct {
+ TemplateName string `json:"template-name"`
+ Description string `json:"description"`
}
// ConfigTemplateManager is an interface exposes the resource bundle ConfigTemplate functionality
type ConfigTemplateManager interface {
CreateOrUpdate(rbName, rbVersion string, p ConfigTemplate, update bool) error
Get(rbName, rbVersion, templateName string) (ConfigTemplate, error)
- List(rbName, rbVersion string) ([]ConfigTemplate, error)
+ List(rbName, rbVersion string) ([]ConfigTemplateList, error)
Delete(rbName, rbVersion, templateName string) error
Upload(rbName, rbVersion, templateName string, inp []byte) error
}
@@ -94,7 +100,7 @@ func (v *ConfigTemplateClient) CreateOrUpdate(rbName, rbVersion string, p Config
}
//Check if ConfigTemplate already exists
- _, err := v.Get(rbName, rbVersion, p.TemplateName)
+ prev, err := v.Get(rbName, rbVersion, p.TemplateName)
if err == nil && !update {
return pkgerrors.New(" ConfigTemplate already exists for this Definition")
}
@@ -103,7 +109,7 @@ func (v *ConfigTemplateClient) CreateOrUpdate(rbName, rbVersion string, p Config
}
//Check if provided resource bundle information is valid
- _, err = NewDefinitionClient().Get(rbName, rbVersion)
+ rbDef, err := NewDefinitionClient().Get(rbName, rbVersion)
if err != nil {
return pkgerrors.Errorf("Invalid Resource Bundle ID provided: %s", err.Error())
}
@@ -115,11 +121,15 @@ func (v *ConfigTemplateClient) CreateOrUpdate(rbName, rbVersion string, p Config
}
if update {
+ p.ChartName = prev.ChartName
+ p.HasContent = prev.HasContent
err = db.DBconn.Update(v.storeName, key, v.tagMeta, p)
if err != nil {
return pkgerrors.Wrap(err, "Updating ConfigTemplate DB Entry")
}
} else {
+ p.ChartName = rbDef.ChartName
+ p.HasContent = false
err = db.DBconn.Create(v.storeName, key, v.tagMeta, p)
if err != nil {
return pkgerrors.Wrap(err, "Creating ConfigTemplate DB Entry")
@@ -155,19 +165,19 @@ func (v *ConfigTemplateClient) Get(rbName, rbVersion, templateName string) (Conf
}
// List returns the Resource Bundle ConfigTemplate for corresponding ID
-func (v *ConfigTemplateClient) List(rbName, rbVersion string) ([]ConfigTemplate, error) {
+func (v *ConfigTemplateClient) List(rbName, rbVersion string) ([]ConfigTemplateList, error) {
//Get all config templates
dbres, err := db.DBconn.ReadAll(v.storeName, v.tagMeta)
if err != nil || len(dbres) == 0 {
- return []ConfigTemplate{}, pkgerrors.Wrap(err, "No Config Templates Found")
+ return []ConfigTemplateList{}, pkgerrors.Wrap(err, "No Config Templates Found")
}
- var results []ConfigTemplate
+ var results []ConfigTemplateList
for key, value := range dbres {
//value is a byte array
if value != nil {
- tmp := ConfigTemplate{}
+ tmp := ConfigTemplateList{}
err = db.DBconn.Unmarshal(value, &tmp)
if err != nil {
log.Printf("[ConfigTemplate] Error: %s Unmarshaling value for: %s", err.Error(), key)
@@ -267,6 +277,11 @@ func (v *ConfigTemplateClient) Upload(rbName, rbVersion, templateName string, in
if err != nil {
return pkgerrors.Errorf("Error uploading data to db %s", err.Error())
}
+ t.HasContent = true
+ err = db.DBconn.Update(v.storeName, key, v.tagMeta, t)
+ if err != nil {
+ return pkgerrors.Wrap(err, "Updating ConfigTemplate DB Entry")
+ }
return nil
}