From c505dd3ce0d4d5bf4611d78e11bc1d6162f49147 Mon Sep 17 00:00:00 2001 From: Ritu Sood Date: Wed, 11 Mar 2020 18:05:13 -0700 Subject: Add Delete and DeleteAll functionality to etcd Currently only supports DeleteAll. Issue-ID: MULTICLOUD-871 Signed-off-by: Ritu Sood Change-Id: I9ee03648462c5a04481c89bf864cdec35cfd4230 --- src/orchestrator/pkg/infra/contextdb/contextdb.go | 2 ++ src/orchestrator/pkg/infra/contextdb/etcd.go | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/orchestrator') 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()) } -- cgit 1.2.3-korg