Add Delete and DeleteAll functionality to etcd 42/103542/1
authorRitu Sood <ritu.sood@intel.com>
Thu, 12 Mar 2020 01:05:13 +0000 (18:05 -0700)
committerRitu Sood <ritu.sood@intel.com>
Thu, 12 Mar 2020 01:05:13 +0000 (18:05 -0700)
Currently only supports DeleteAll.

Issue-ID: MULTICLOUD-871
Signed-off-by: Ritu Sood <ritu.sood@intel.com>
Change-Id: I9ee03648462c5a04481c89bf864cdec35cfd4230

src/orchestrator/pkg/infra/contextdb/contextdb.go
src/orchestrator/pkg/infra/contextdb/etcd.go

index d18af22..58832a1 100644 (file)
@@ -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
index a1922d3..44f8ab4 100644 (file)
@@ -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())
        }