aboutsummaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/infra
diff options
context:
space:
mode:
authorRitu Sood <ritu.sood@intel.com>2020-03-11 18:05:13 -0700
committerRitu Sood <ritu.sood@intel.com>2020-03-11 18:05:13 -0700
commitc505dd3ce0d4d5bf4611d78e11bc1d6162f49147 (patch)
tree387e561b64fe00ec5656db3517aa599a1d437f29 /src/orchestrator/pkg/infra
parent251c38778c0c499cae61383720dd8b053b16b87e (diff)
Add Delete and DeleteAll functionality to etcd
Currently only supports DeleteAll. Issue-ID: MULTICLOUD-871 Signed-off-by: Ritu Sood <ritu.sood@intel.com> Change-Id: I9ee03648462c5a04481c89bf864cdec35cfd4230
Diffstat (limited to 'src/orchestrator/pkg/infra')
-rw-r--r--src/orchestrator/pkg/infra/contextdb/contextdb.go2
-rw-r--r--src/orchestrator/pkg/infra/contextdb/etcd.go15
2 files changed, 16 insertions, 1 deletions
diff --git a/src/orchestrator/pkg/infra/contextdb/contextdb.go b/src/orchestrator/pkg/infra/contextdb/contextdb.go
index d18af227..58832a19 100644
--- a/src/orchestrator/pkg/infra/contextdb/contextdb.go
+++ b/src/orchestrator/pkg/infra/contextdb/contextdb.go
@@ -29,6 +29,8 @@ type ContextDb interface {
Put(key string, value interface{}) error
// Delete k,v
Delete(key string) error
+ // Delete all keys in heirarchy
+ DeleteAll(key string) error
// Gets Json Struct from db
Get(key string, value interface{}) error
// Returns all keys with a prefix
diff --git a/src/orchestrator/pkg/infra/contextdb/etcd.go b/src/orchestrator/pkg/infra/contextdb/etcd.go
index a1922d3b..44f8ab48 100644
--- a/src/orchestrator/pkg/infra/contextdb/etcd.go
+++ b/src/orchestrator/pkg/infra/contextdb/etcd.go
@@ -156,13 +156,26 @@ func (e *EtcdClient) GetAllKeys(key string) ([]string, error) {
return keys, nil
}
+// DeleteAll keys from Etcd DB
+func (e *EtcdClient) DeleteAll(key string) error {
+ cli := getEtcd(e)
+ if cli == nil {
+ return pkgerrors.Errorf("Etcd Client not initialized")
+ }
+ _, err := cli.Delete(context.Background(), key, clientv3.WithPrefix())
+ if err != nil {
+ return pkgerrors.Errorf("Delete failed etcd entry: %s", err.Error())
+ }
+ return nil
+}
+
// Delete values from Etcd DB
func (e *EtcdClient) Delete(key string) error {
cli := getEtcd(e)
if cli == nil {
return pkgerrors.Errorf("Etcd Client not initialized")
}
- _, err := cli.Delete(context.Background(), key, clientv3.WithPrefix())
+ _, err := cli.Delete(context.Background(), key)
if err != nil {
return pkgerrors.Errorf("Delete failed etcd entry: %s", err.Error())
}