summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/db
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@orange.com>2021-10-01 09:35:35 +0200
committerLukasz Rajewski <lukasz.rajewski@orange.com>2021-10-04 12:06:25 +0200
commitbbeac9a596074d0af6e5be60448567517978a388 (patch)
treea3e0203797e00e6db9e31001e316e238a77d775a /src/k8splugin/internal/db
parentdc62323aa7f6782d69c7ac6509eb270e86ef31bd (diff)
Further fixes for config delete operation
The issue was related with insufficient handlijg of different versions of config vs their delete operation handled by the plugin. Issue-ID: MULTICLOUD-1332 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com> Change-Id: I90d896720fa89ebd66cb3290cdd9401272f5e3fd
Diffstat (limited to 'src/k8splugin/internal/db')
-rw-r--r--src/k8splugin/internal/db/etcd.go14
-rw-r--r--src/k8splugin/internal/db/etcd_testing.go9
2 files changed, 23 insertions, 0 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
+}