Skip to content

Commit

Permalink
fix: verify through the cache first, then delete (#1135)
Browse files Browse the repository at this point in the history
  • Loading branch information
tao12345666333 authored Jul 7, 2022
1 parent a642b14 commit 93c10e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
13 changes: 7 additions & 6 deletions pkg/apisix/pluginconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,22 @@ func (pc *pluginConfigClient) Delete(ctx context.Context, obj *v1.PluginConfig)
zap.String("cluster", "default"),
zap.String("url", pc.url),
)

if err := pc.cluster.HasSynced(ctx); err != nil {
return err
}
url := pc.url + "/" + obj.ID
if err := pc.cluster.deleteResource(ctx, url, "pluginConfig"); err != nil {
pc.cluster.metricsCollector.IncrAPISIXRequest("pluginConfig")
return err
}
pc.cluster.metricsCollector.IncrAPISIXRequest("pluginConfig")
if err := pc.cluster.cache.DeletePluginConfig(obj); err != nil {
log.Errorf("failed to reflect pluginConfig delete to cache: %s", err)
if err != cache.ErrNotFound {
return err
}
}
url := pc.url + "/" + obj.ID
if err := pc.cluster.deleteResource(ctx, url, "pluginConfig"); err != nil {
pc.cluster.metricsCollector.IncrAPISIXRequest("pluginConfig")
return err
}
pc.cluster.metricsCollector.IncrAPISIXRequest("pluginConfig")
return nil
}

Expand Down
18 changes: 9 additions & 9 deletions pkg/apisix/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,24 @@ func (u *upstreamClient) Delete(ctx context.Context, obj *v1.Upstream) error {
zap.String("url", u.url),
)

if err := u.cluster.upstreamServiceRelation.Delete(ctx, &v1.UpstreamServiceRelation{UpstreamName: obj.Name}); err != nil {
log.Errorf("failed to delete upstreamService in cache: %s", err)
}
if err := u.cluster.HasSynced(ctx); err != nil {
return err
}
url := u.url + "/" + obj.ID
if err := u.cluster.deleteResource(ctx, url, "upstream"); err != nil {
u.cluster.metricsCollector.IncrAPISIXRequest("upstream")
return err
}
u.cluster.metricsCollector.IncrAPISIXRequest("upstream")
if err := u.cluster.cache.DeleteUpstream(obj); err != nil {
log.Errorf("failed to reflect upstream delete to cache: %s", err.Error())
if err != cache.ErrNotFound {
return err
}
}
if err := u.cluster.upstreamServiceRelation.Delete(ctx, &v1.UpstreamServiceRelation{UpstreamName: obj.Name}); err != nil {
log.Errorf("failed to delete upstreamService in cache: %s", err)
}
url := u.url + "/" + obj.ID
if err := u.cluster.deleteResource(ctx, url, "upstream"); err != nil {
u.cluster.metricsCollector.IncrAPISIXRequest("upstream")
return err
}
u.cluster.metricsCollector.IncrAPISIXRequest("upstream")
return nil
}

Expand Down

0 comments on commit 93c10e6

Please sign in to comment.