diff options
Diffstat (limited to 'src/k8splugin/internal/db')
-rw-r--r-- | src/k8splugin/internal/db/etcd.go | 14 | ||||
-rw-r--r-- | src/k8splugin/internal/db/etcd_testing.go | 9 | ||||
-rw-r--r-- | src/k8splugin/internal/db/mongo.go | 5 |
3 files changed, 26 insertions, 2 deletions
diff --git a/src/k8splugin/internal/db/etcd.go b/src/k8splugin/internal/db/etcd.go index a435b435..e455cc1a 100644 --- a/src/k8splugin/internal/db/etcd.go +++ b/src/k8splugin/internal/db/etcd.go @@ -39,6 +39,7 @@ type EtcdStore interface { GetAll(key string) ([][]byte, error) Put(key, value string) error Delete(key string) error + DeletePrefix(keyPrefix string) error } // EtcdClient for Etcd @@ -151,3 +152,16 @@ func (e EtcdClient) Delete(key string) error { } return nil } + +// Delete values by prefix from Etcd DB +func (e EtcdClient) DeletePrefix(keyPrefix string) error { + + if e.cli == nil { + return pkgerrors.Errorf("Etcd Client not initialized") + } + _, err := e.cli.Delete(context.Background(), keyPrefix, clientv3.WithPrefix()) + if err != nil { + return pkgerrors.Errorf("Delete prefix failed etcd entry:%s", err.Error()) + } + return nil +} diff --git a/src/k8splugin/internal/db/etcd_testing.go b/src/k8splugin/internal/db/etcd_testing.go index 9dfcad82..4b4dfe3e 100644 --- a/src/k8splugin/internal/db/etcd_testing.go +++ b/src/k8splugin/internal/db/etcd_testing.go @@ -55,3 +55,12 @@ func (c *MockEtcdClient) Delete(key string) error { delete(c.Items, key) return c.Err } + +func (c *MockEtcdClient) DeletePrefix(key string) error { + for kvKey := range c.Items { + if strings.HasPrefix(kvKey, key) { + delete(c.Items, key) + } + } + return c.Err +} diff --git a/src/k8splugin/internal/db/mongo.go b/src/k8splugin/internal/db/mongo.go index c15b108b..aa05820a 100644 --- a/src/k8splugin/internal/db/mongo.go +++ b/src/k8splugin/internal/db/mongo.go @@ -17,9 +17,10 @@ package db import ( - "golang.org/x/net/context" "log" + "golang.org/x/net/context" + "github.com/onap/multicloud-k8s/src/k8splugin/internal/config" pkgerrors "github.com/pkg/errors" @@ -374,7 +375,7 @@ func (m *MongoStore) ReadAll(coll, tag string) (map[string][]byte, error) { //Get objectID of tag document tid, ok := d.Lookup(tag).ObjectIDOK() if !ok { - log.Printf("Did not find tag: %s", tag) + //"Did not find tag: %s", tag) continue } |