Skip to content

Commit 412762b

Browse files
committed
fix delete
1 parent 5797240 commit 412762b

File tree

8 files changed

+70
-43
lines changed

8 files changed

+70
-43
lines changed

internal/controlplane/controlplane.go

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -77,43 +77,44 @@ func (d *dashboardClient) Update(ctx context.Context, tctx *translator.Translate
7777

7878
func (d *dashboardClient) Delete(ctx context.Context, obj client.Object) error {
7979
clusters := d.c.ListClusters()
80+
kindLabel := dashboard.ListByKindLabelOptions{
81+
Kind: obj.GetObjectKind().GroupVersionKind().Kind,
82+
Namespace: obj.GetNamespace(),
83+
Name: obj.GetName(),
84+
}
8085
for _, cluster := range clusters {
81-
routes, _ := cluster.Route().List(ctx, dashboard.ListOptions{
82-
From: dashboard.ListFromCache,
83-
Args: []interface{}{
84-
"label",
85-
obj.GetObjectKind().GroupVersionKind().Kind,
86-
obj.GetNamespace(),
87-
obj.GetName(),
88-
},
89-
})
90-
91-
for _, route := range routes {
92-
if err := cluster.Route().Delete(ctx, route); err != nil {
93-
return err
86+
switch obj.(type) {
87+
case *gatewayv1.Gateway:
88+
ssls, _ := cluster.SSL().List(ctx, dashboard.ListOptions{
89+
From: dashboard.ListFromCache,
90+
KindLabel: kindLabel,
91+
})
92+
for _, ssl := range ssls {
93+
if err := cluster.SSL().Delete(ctx, ssl); err != nil {
94+
return err
95+
}
9496
}
95-
}
97+
case *gatewayv1.HTTPRoute:
98+
routes, _ := cluster.Route().List(ctx, dashboard.ListOptions{
99+
From: dashboard.ListFromCache,
100+
KindLabel: kindLabel,
101+
})
96102

97-
services, _ := cluster.Service().List(ctx, dashboard.ListOptions{
98-
From: dashboard.ListFromCache,
99-
Args: []interface{}{
100-
"label",
101-
obj.GetObjectKind().GroupVersionKind().Kind,
102-
obj.GetNamespace(),
103-
obj.GetName(),
104-
},
105-
})
106-
107-
for _, service := range services {
108-
if err := cluster.Service().Delete(ctx, service); err != nil {
109-
return err
103+
for _, route := range routes {
104+
if err := cluster.Route().Delete(ctx, route); err != nil {
105+
return err
106+
}
110107
}
111-
}
112108

113-
ssls, _ := cluster.SSL().List(ctx)
114-
for _, ssl := range ssls {
115-
if err := cluster.SSL().Delete(ctx, ssl); err != nil {
116-
return err
109+
services, _ := cluster.Service().List(ctx, dashboard.ListOptions{
110+
From: dashboard.ListFromCache,
111+
KindLabel: kindLabel,
112+
})
113+
114+
for _, service := range services {
115+
if err := cluster.Service().Delete(ctx, service); err != nil {
116+
return err
117+
}
117118
}
118119
}
119120
}

pkg/dashboard/cache/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type Cache interface {
6161
// ListStreamRoutes lists all stream_route objects in cache.
6262
ListStreamRoutes() ([]*v1.StreamRoute, error)
6363
// ListSSL lists all ssl objects in cache.
64-
ListSSL() ([]*v1.Ssl, error)
64+
ListSSL(...interface{}) ([]*v1.Ssl, error)
6565
// ListUpstreams lists all upstreams in cache.
6666
ListServices(...interface{}) ([]*v1.Service, error)
6767
// ListGlobalRules lists all global_rule objects in cache.

pkg/dashboard/cache/memdb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ func (c *dbCache) ListRoutes(args ...interface{}) ([]*v1.Route, error) {
179179
return routes, nil
180180
}
181181

182-
func (c *dbCache) ListSSL() ([]*v1.Ssl, error) {
183-
raws, err := c.list("ssl")
182+
func (c *dbCache) ListSSL(args ...interface{}) ([]*v1.Ssl, error) {
183+
raws, err := c.list("ssl", args...)
184184
if err != nil {
185185
return nil, err
186186
}

pkg/dashboard/cache/noop_db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (c *noopCache) ListRoutes(...interface{}) ([]*v1.Route, error) {
8080
return nil, nil
8181
}
8282

83-
func (c *noopCache) ListSSL() ([]*v1.Ssl, error) {
83+
func (c *noopCache) ListSSL(...interface{}) ([]*v1.Ssl, error) {
8484
return nil, nil
8585
}
8686

pkg/dashboard/dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type Route interface {
8383
type SSL interface {
8484
// name is namespace_sslname
8585
Get(ctx context.Context, name string) (*v1.Ssl, error)
86-
List(ctx context.Context) ([]*v1.Ssl, error)
86+
List(ctx context.Context, args ...interface{}) ([]*v1.Ssl, error)
8787
Create(ctx context.Context, ssl *v1.Ssl) (*v1.Ssl, error)
8888
Delete(ctx context.Context, ssl *v1.Ssl) error
8989
Update(ctx context.Context, ssl *v1.Ssl) (*v1.Ssl, error)

pkg/dashboard/nonexistentclient.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (f *dummySSL) Get(_ context.Context, _ string) (*v1.Ssl, error) {
8585
return nil, ErrClusterNotExist
8686
}
8787

88-
func (f *dummySSL) List(_ context.Context) ([]*v1.Ssl, error) {
88+
func (f *dummySSL) List(_ context.Context, _ ...interface{}) ([]*v1.Ssl, error) {
8989
return nil, ErrClusterNotExist
9090
}
9191

@@ -356,7 +356,7 @@ func (c *dummyCache) GetPluginConfig(_ string) (*v1.PluginConfig, error) {
356356
}
357357

358358
func (c *dummyCache) ListRoutes(...interface{}) ([]*v1.Route, error) { return nil, nil }
359-
func (c *dummyCache) ListSSL() ([]*v1.Ssl, error) { return nil, nil }
359+
func (c *dummyCache) ListSSL(_ ...interface{}) ([]*v1.Ssl, error) { return nil, nil }
360360
func (c *dummyCache) ListServices(...interface{}) ([]*v1.Service, error) { return nil, nil }
361361
func (c *dummyCache) ListStreamRoutes() ([]*v1.StreamRoute, error) { return nil, nil }
362362
func (c *dummyCache) ListGlobalRules() ([]*v1.GlobalRule, error) { return nil, nil }

pkg/dashboard/service.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ var (
5757
)
5858

5959
type ListOptions struct {
60-
From ListFrom
61-
Args []interface{}
60+
From ListFrom
61+
KindLabel ListByKindLabelOptions
62+
}
63+
64+
type ListByKindLabelOptions struct {
65+
Kind string
66+
Namespace string
67+
Name string
6268
}
6369

6470
// List is only used in cache warming up. So here just pass through
@@ -74,7 +80,10 @@ func (u *serviceClient) List(ctx context.Context, listOptions ...interface{}) ([
7480
zap.String("cluster", u.cluster.name),
7581
zap.String("url", u.url),
7682
)
77-
return u.cluster.cache.ListServices()
83+
return u.cluster.cache.ListServices("label",
84+
options.KindLabel.Kind,
85+
options.KindLabel.Namespace,
86+
options.KindLabel.Name)
7887
}
7988

8089
log.Debugw("try to list upstreams in APISIX",

pkg/dashboard/ssl.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,23 @@ func (s *sslClient) Get(ctx context.Context, name string) (*v1.Ssl, error) {
5353

5454
// List is only used in cache warming up. So here just pass through
5555
// to APISIX.
56-
func (s *sslClient) List(ctx context.Context) ([]*v1.Ssl, error) {
56+
func (s *sslClient) List(ctx context.Context, listOptions ...interface{}) ([]*v1.Ssl, error) {
57+
var options ListOptions
58+
if len(listOptions) > 0 {
59+
options = listOptions[0].(ListOptions)
60+
}
61+
if options.From == ListFromCache {
62+
log.Debugw("try to list ssls in cache",
63+
zap.String("cluster", s.cluster.name),
64+
zap.String("url", s.url),
65+
)
66+
return s.cluster.cache.ListSSL(
67+
"label",
68+
options.KindLabel.Kind,
69+
options.KindLabel.Namespace,
70+
options.KindLabel.Name,
71+
)
72+
}
5773
log.Debugw("try to list ssl in APISIX",
5874
zap.String("url", s.url),
5975
zap.String("cluster", s.cluster.name),
@@ -75,6 +91,7 @@ func (s *sslClient) List(ctx context.Context) ([]*v1.Ssl, error) {
7591
)
7692
return nil, err
7793
}
94+
7895
items = append(items, ssl)
7996
}
8097

0 commit comments

Comments
 (0)