This is an automated email from the ASF dual-hosted git repository.

ashishtiwari pushed a commit to branch v1.8.0
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git


The following commit(s) were added to refs/heads/v1.8.0 by this push:
     new 454032c6 fix: backport fix of deletion of references (#2214)
454032c6 is described below

commit 454032c64cee6b061eab44318cf597900a826ee1
Author: Ashish Tiwari <[email protected]>
AuthorDate: Tue Apr 16 12:50:52 2024 +0530

    fix: backport fix of deletion of references (#2214)
    
    * fix: deletion of references (#2213)
    
    * chore: add fix commit in release note
    
    Signed-off-by: Ashish Tiwari <[email protected]>
    
    ---------
    
    Signed-off-by: Ashish Tiwari <[email protected]>
---
 CHANGELOG.md                    | 2 ++
 pkg/apisix/cache/cache.go       | 2 ++
 pkg/apisix/cache/memdb.go       | 8 ++++----
 pkg/apisix/cache/noop_db.go     | 8 ++++++++
 pkg/apisix/nonexistentclient.go | 2 ++
 pkg/apisix/pluginconfig.go      | 6 +++++-
 pkg/apisix/upstream.go          | 6 +++++-
 7 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 73d30b16..5de1ab04 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@
 
 # Table of Contents
 
+- [1.8.1](#181)
 - [1.8.0](#180)
 - [1.7.0](#170)
 - [1.6.0](#160)
@@ -43,6 +44,7 @@
 
 ## What's New
 
+- fix: deletion of references @Revolyssup (#2213)
 - chore: remove redundant logs and improve logs for users @Revolyssup (#2206)
 - fix: use force=true to hard delete the apisix resource @Revolyssup (#2210)
 - chore: upgrade etcd-adapter to latest version @Revolyssup (#2205)
diff --git a/pkg/apisix/cache/cache.go b/pkg/apisix/cache/cache.go
index 7fcdc4aa..91e68b22 100644
--- a/pkg/apisix/cache/cache.go
+++ b/pkg/apisix/cache/cache.go
@@ -97,5 +97,7 @@ type Cache interface {
        // DeletePluginConfig deletes the specified plugin_config in cache.
        DeletePluginConfig(*v1.PluginConfig) error
 
+       CheckUpstreamReference(*v1.Upstream) error
+       CheckPluginConfigReference(*v1.PluginConfig) error
        DeleteUpstreamServiceRelation(*v1.UpstreamServiceRelation) error
 }
diff --git a/pkg/apisix/cache/memdb.go b/pkg/apisix/cache/memdb.go
index 4a45a1a9..3dc03935 100644
--- a/pkg/apisix/cache/memdb.go
+++ b/pkg/apisix/cache/memdb.go
@@ -311,7 +311,7 @@ func (c *dbCache) DeleteSSL(ssl *v1.Ssl) error {
 }
 
 func (c *dbCache) DeleteUpstream(u *v1.Upstream) error {
-       if err := c.checkUpstreamReference(u); err != nil {
+       if err := c.CheckUpstreamReference(u); err != nil {
                return err
        }
        return c.delete("upstream", u)
@@ -334,7 +334,7 @@ func (c *dbCache) DeleteSchema(schema *v1.Schema) error {
 }
 
 func (c *dbCache) DeletePluginConfig(pc *v1.PluginConfig) error {
-       if err := c.checkPluginConfigReference(pc); err != nil {
+       if err := c.CheckPluginConfigReference(pc); err != nil {
                return err
        }
        return c.delete("plugin_config", pc)
@@ -357,7 +357,7 @@ func (c *dbCache) delete(table string, obj interface{}) 
error {
        return nil
 }
 
-func (c *dbCache) checkUpstreamReference(u *v1.Upstream) error {
+func (c *dbCache) CheckUpstreamReference(u *v1.Upstream) error {
        // Upstream is referenced by Route.
        txn := c.db.Txn(false)
        defer txn.Abort()
@@ -379,7 +379,7 @@ func (c *dbCache) checkUpstreamReference(u *v1.Upstream) 
error {
        return nil
 }
 
-func (c *dbCache) checkPluginConfigReference(u *v1.PluginConfig) error {
+func (c *dbCache) CheckPluginConfigReference(u *v1.PluginConfig) error {
        // PluginConfig is referenced by Route.
        txn := c.db.Txn(false)
        defer txn.Abort()
diff --git a/pkg/apisix/cache/noop_db.go b/pkg/apisix/cache/noop_db.go
index 6fce1ec6..d3e7b770 100644
--- a/pkg/apisix/cache/noop_db.go
+++ b/pkg/apisix/cache/noop_db.go
@@ -172,3 +172,11 @@ func (c *noopCache) DeletePluginConfig(pc 
*v1.PluginConfig) error {
 func (c *noopCache) DeleteUpstreamServiceRelation(us 
*v1.UpstreamServiceRelation) error {
        return nil
 }
+
+func (c *noopCache) CheckUpstreamReference(u *v1.Upstream) error {
+       return nil
+}
+
+func (c *noopCache) CheckPluginConfigReference(pc *v1.PluginConfig) error {
+       return nil
+}
diff --git a/pkg/apisix/nonexistentclient.go b/pkg/apisix/nonexistentclient.go
index ac7e4986..237cbbc0 100644
--- a/pkg/apisix/nonexistentclient.go
+++ b/pkg/apisix/nonexistentclient.go
@@ -400,3 +400,5 @@ func (c *dummyCache) DeleteConsumer(_ *v1.Consumer) error
 func (c *dummyCache) DeleteSchema(_ *v1.Schema) error                          
         { return nil }
 func (c *dummyCache) DeletePluginConfig(_ *v1.PluginConfig) error              
         { return nil }
 func (c *dummyCache) DeleteUpstreamServiceRelation(_ 
*v1.UpstreamServiceRelation) error { return nil }
+func (c *dummyCache) CheckUpstreamReference(_ *v1.Upstream) error              
         { return nil }
+func (c *dummyCache) CheckPluginConfigReference(_ *v1.PluginConfig) error      
         { return nil }
diff --git a/pkg/apisix/pluginconfig.go b/pkg/apisix/pluginconfig.go
index 0886e450..6a2d4f0f 100644
--- a/pkg/apisix/pluginconfig.go
+++ b/pkg/apisix/pluginconfig.go
@@ -162,7 +162,11 @@ func (pc *pluginConfigClient) Delete(ctx context.Context, 
obj *v1.PluginConfig)
                zap.String("cluster", pc.cluster.name),
                zap.String("url", pc.url),
        )
-
+       err := pc.cluster.cache.CheckPluginConfigReference(obj)
+       if err != nil {
+               log.Warnw("deletion for plugin config: " + obj.Name + " aborted 
as it is still in use.")
+               return err
+       }
        if err := pc.cluster.HasSynced(ctx); err != nil {
                return err
        }
diff --git a/pkg/apisix/upstream.go b/pkg/apisix/upstream.go
index 2a0f394c..6b53b396 100644
--- a/pkg/apisix/upstream.go
+++ b/pkg/apisix/upstream.go
@@ -158,7 +158,11 @@ func (u *upstreamClient) Delete(ctx context.Context, obj 
*v1.Upstream) error {
                zap.String("cluster", u.cluster.name),
                zap.String("url", u.url),
        )
-
+       err := u.cluster.cache.CheckUpstreamReference(obj)
+       if err != nil {
+               log.Warnw("deletion for upstream: " + obj.Name + " aborted as 
it is still in use.")
+               return err
+       }
        if err := u.cluster.HasSynced(ctx); err != nil {
                return err
        }

Reply via email to