tokers commented on a change in pull request #549:
URL:
https://github.com/apache/apisix-ingress-controller/pull/549#discussion_r655188860
##########
File path: pkg/apisix/route.go
##########
@@ -41,16 +41,24 @@ func newRouteClient(c *cluster) Route {
}
// Get returns the Route.
+func (r *routeClient) Get(ctx context.Context, name string) (*v1.Route, error)
{
+ return r.get(ctx, id.GenID(name), name)
+}
+
+// GetByName returns the Route with route name
+func (r *routeClient) GetByID(ctx context.Context, realID string) (*v1.Route,
error) {
+ return r.get(ctx, realID, realID)
+}
+
// FIXME, currently if caller pass a non-existent resource, the Get always
passes
// through cache.
-func (r *routeClient) Get(ctx context.Context, name string) (*v1.Route, error)
{
+func (r *routeClient) get(ctx context.Context, id string, name string)
(*v1.Route, error) {
log.Debugw("try to look up route",
zap.String("name", name),
zap.String("url", r.url),
zap.String("cluster", "default"),
)
- rid := id.GenID(name)
- route, err := r.cluster.cache.GetRoute(rid)
+ route, err := r.cluster.cache.GetRoute(id)
Review comment:
Consumers will be saved into cache.
##########
File path: pkg/apisix/global_rule.go
##########
@@ -40,33 +40,46 @@ func newGlobalRuleClient(c *cluster) GlobalRule {
}
// Get returns the GlobalRule.
+func (r *globalRuleClient) Get(ctx context.Context, name string)
(*v1.GlobalRule, error) {
+ return r.get(ctx, id.GenID(name), name)
+}
+
+// GetByName returns the GlobalRule with global rule id
+func (r *globalRuleClient) GetByID(ctx context.Context, realID string)
(*v1.GlobalRule, error) {
+ return r.get(ctx, realID, realID)
+}
+
// FIXME, currently if caller pass a non-existent resource, the Get always
passes
// through cache.
-func (r *globalRuleClient) Get(ctx context.Context, name string)
(*v1.GlobalRule, error) {
+func (r *globalRuleClient) get(ctx context.Context, id string, name string)
(*v1.GlobalRule, error) {
log.Debugw("try to look up global_rule",
- zap.String("name", name),
+ zap.String("name/id", name),
zap.String("url", r.url),
zap.String("cluster", "default"),
)
- rid := id.GenID(name)
- globalRule, err := r.cluster.cache.GetGlobalRule(rid)
- if err == nil {
- return globalRule, nil
- }
- if err != cache.ErrNotFound {
- log.Errorw("failed to find global_rule in cache, will try to
lookup from APISIX",
- zap.String("name", name),
- zap.Error(err),
- )
- } else {
- log.Debugw("failed to find global_rule in cache, will try to
lookup from APISIX",
- zap.String("name", name),
- zap.Error(err),
- )
+
+ var globalRule *v1.GlobalRule
+ var err error
Review comment:
```suggestion
var (
globalRule *v1.GlobalRule
var err error
)
```
##########
File path: pkg/apisix/route.go
##########
@@ -41,16 +41,24 @@ func newRouteClient(c *cluster) Route {
}
// Get returns the Route.
+func (r *routeClient) Get(ctx context.Context, name string) (*v1.Route, error)
{
+ return r.get(ctx, id.GenID(name), name)
+}
+
+// GetByName returns the Route with route name
+func (r *routeClient) GetByID(ctx context.Context, realID string) (*v1.Route,
error) {
+ return r.get(ctx, realID, realID)
+}
+
// FIXME, currently if caller pass a non-existent resource, the Get always
passes
// through cache.
-func (r *routeClient) Get(ctx context.Context, name string) (*v1.Route, error)
{
+func (r *routeClient) get(ctx context.Context, id string, name string)
(*v1.Route, error) {
log.Debugw("try to look up route",
zap.String("name", name),
zap.String("url", r.url),
zap.String("cluster", "default"),
Review comment:
Here you don't change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]