aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/rb/definition.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/internal/rb/definition.go')
-rw-r--r--src/k8splugin/internal/rb/definition.go25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/k8splugin/internal/rb/definition.go b/src/k8splugin/internal/rb/definition.go
index 73ea44da..aa76afaa 100644
--- a/src/k8splugin/internal/rb/definition.go
+++ b/src/k8splugin/internal/rb/definition.go
@@ -61,6 +61,7 @@ func (dk DefinitionKey) String() string {
// DefinitionManager is an interface exposes the resource bundle definition functionality
type DefinitionManager interface {
Create(def Definition) (Definition, error)
+ Update(def Definition) (Definition, error)
List(name string) ([]Definition, error)
Get(name string, version string) (Definition, error)
Delete(name string, version string) error
@@ -104,13 +105,13 @@ func (v *DefinitionClient) Create(def Definition) (Definition, error) {
// Create a default profile automatically
prc := NewProfileClient()
- pr, err := prc.Create(Profile{
+ pr, err := prc.CreateOrUpdate(Profile{
RBName: def.RBName,
RBVersion: def.RBVersion,
ProfileName: "default",
Namespace: "default",
ReleaseName: "default",
- })
+ }, false)
if err != nil {
logutils.Error("Create Default Profile", logutils.Fields{
@@ -139,6 +140,26 @@ func (v *DefinitionClient) Create(def Definition) (Definition, error) {
return def, nil
}
+// Update an entry for the resource in the database`
+func (v *DefinitionClient) Update(def Definition) (Definition, error) {
+
+ //Construct composite key consisting of name and version
+ key := DefinitionKey{RBName: def.RBName, RBVersion: def.RBVersion}
+
+ //Check if this definition already exists
+ _, err := v.Get(def.RBName, def.RBVersion)
+ if err != nil {
+ return Definition{}, pkgerrors.New("Definition does not exists")
+ }
+
+ err = db.DBconn.Update(v.storeName, key, v.tagMeta, def)
+ if err != nil {
+ return Definition{}, pkgerrors.Wrap(err, "Updating DB Entry")
+ }
+
+ return def, nil
+}
+
// List all resource entry's versions in the database
func (v *DefinitionClient) List(name string) ([]Definition, error) {
res, err := db.DBconn.ReadAll(v.storeName, v.tagMeta)