You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by kv...@apache.org on 2021/03/26 15:28:59 UTC
[apisix-ingress-controller] branch master updated: fix: workqueue
need to retry when failed (#311)
This is an automated email from the ASF dual-hosted git repository.
kvn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new 244b556 fix: workqueue need to retry when failed (#311)
244b556 is described below
commit 244b5566851164e5b0fd9422d69a2615353c1882
Author: kv <gx...@163.com>
AuthorDate: Fri Mar 26 23:28:52 2021 +0800
fix: workqueue need to retry when failed (#311)
* fix: workqueue need to retry when failed
* fix: rm _maxRetries
---
pkg/ingress/controller/apisix_route.go | 23 +++++++++--------------
pkg/ingress/controller/apisix_upstream.go | 17 +++++++----------
pkg/ingress/controller/endpoint.go | 21 ++++++---------------
pkg/ingress/controller/ingress.go | 17 +++++++----------
4 files changed, 29 insertions(+), 49 deletions(-)
diff --git a/pkg/ingress/controller/apisix_route.go b/pkg/ingress/controller/apisix_route.go
index 707cdd9..d8fcb99 100644
--- a/pkg/ingress/controller/apisix_route.go
+++ b/pkg/ingress/controller/apisix_route.go
@@ -16,19 +16,18 @@ package controller
import (
"context"
-
- "github.com/apache/apisix-ingress-controller/pkg/kube"
-
- apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+ "time"
"go.uber.org/zap"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
+ "github.com/apache/apisix-ingress-controller/pkg/kube"
"github.com/apache/apisix-ingress-controller/pkg/log"
"github.com/apache/apisix-ingress-controller/pkg/seven/state"
"github.com/apache/apisix-ingress-controller/pkg/types"
+ apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
)
type apisixRouteController struct {
@@ -40,7 +39,7 @@ type apisixRouteController struct {
func (c *Controller) newApisixRouteController() *apisixRouteController {
ctl := &apisixRouteController{
controller: c,
- workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "ApisixRoute"),
+ workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemFastSlowRateLimiter(1*time.Second, 60*time.Second, 5), "ApisixRoute"),
workers: 1,
}
c.apisixRouteInformer.AddEventHandler(
@@ -189,15 +188,11 @@ func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
c.workqueue.Forget(obj)
return
}
- if c.workqueue.NumRequeues(obj) < _maxRetries {
- log.Infow("sync ApisixRoute failed, will retry",
- zap.Any("object", obj),
- )
- c.workqueue.AddRateLimited(obj)
- } else {
- c.workqueue.Forget(obj)
- log.Warnf("drop ApisixRoute %+v out of the queue", obj)
- }
+ log.Warnw("sync ApisixRoute failed, will retry",
+ zap.Any("object", obj),
+ zap.Error(err),
+ )
+ c.workqueue.AddRateLimited(obj)
}
func (c *apisixRouteController) onAdd(obj interface{}) {
diff --git a/pkg/ingress/controller/apisix_upstream.go b/pkg/ingress/controller/apisix_upstream.go
index c03ed9c..75dd1ba 100644
--- a/pkg/ingress/controller/apisix_upstream.go
+++ b/pkg/ingress/controller/apisix_upstream.go
@@ -16,6 +16,7 @@ package controller
import (
"context"
+ "time"
"go.uber.org/zap"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -38,7 +39,7 @@ type apisixUpstreamController struct {
func (c *Controller) newApisixUpstreamController() *apisixUpstreamController {
ctl := &apisixUpstreamController{
controller: c,
- workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "ApisixUpstream"),
+ workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemFastSlowRateLimiter(1*time.Second, 60*time.Second, 5), "ApisixUpstream"),
workers: 1,
}
@@ -178,15 +179,11 @@ func (c *apisixUpstreamController) handleSyncErr(obj interface{}, err error) {
c.workqueue.Forget(obj)
return
}
- if c.workqueue.NumRequeues(obj) < _maxRetries {
- log.Infow("sync ApisixUpstream failed, will retry",
- zap.Any("object", obj),
- )
- c.workqueue.AddRateLimited(obj)
- } else {
- c.workqueue.Forget(obj)
- log.Warnf("drop ApisixUpstream %+v out of the queue", obj)
- }
+ log.Warnw("sync ApisixUpstream failed, will retry",
+ zap.Any("object", obj),
+ zap.Error(err),
+ )
+ c.workqueue.AddRateLimited(obj)
}
func (c *apisixUpstreamController) onAdd(obj interface{}) {
diff --git a/pkg/ingress/controller/endpoint.go b/pkg/ingress/controller/endpoint.go
index b3bb3a4..62bed20 100644
--- a/pkg/ingress/controller/endpoint.go
+++ b/pkg/ingress/controller/endpoint.go
@@ -16,6 +16,7 @@ package controller
import (
"context"
+ "time"
"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
@@ -31,11 +32,6 @@ import (
apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
)
-const (
- // maxRetries is the number of times an object will be retried before it is dropped out of the queue.
- _maxRetries = 10
-)
-
type endpointsController struct {
controller *Controller
workqueue workqueue.RateLimitingInterface
@@ -45,7 +41,7 @@ type endpointsController struct {
func (c *Controller) newEndpointsController() *endpointsController {
ctl := &endpointsController{
controller: c,
- workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "endpoints"),
+ workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemFastSlowRateLimiter(1*time.Second, 60*time.Second, 5), "endpoints"),
workers: 1,
}
@@ -179,15 +175,10 @@ func (c *endpointsController) handleSyncErr(obj interface{}, err error) {
c.workqueue.Forget(obj)
return
}
- if c.workqueue.NumRequeues(obj) < _maxRetries {
- log.Infow("sync endpoints failed, will retry",
- zap.Any("object", obj),
- )
- c.workqueue.AddRateLimited(obj)
- } else {
- c.workqueue.Forget(obj)
- log.Warnf("drop endpoints %+v out of the queue", obj)
- }
+ log.Warnw("sync endpoints failed, will retry",
+ zap.Any("object", obj),
+ )
+ c.workqueue.AddRateLimited(obj)
}
func (c *endpointsController) onAdd(obj interface{}) {
diff --git a/pkg/ingress/controller/ingress.go b/pkg/ingress/controller/ingress.go
index 30badf1..c3c0e1e 100644
--- a/pkg/ingress/controller/ingress.go
+++ b/pkg/ingress/controller/ingress.go
@@ -16,6 +16,7 @@ package controller
import (
"context"
+ "time"
"go.uber.org/zap"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -43,7 +44,7 @@ type ingressController struct {
func (c *Controller) newIngressController() *ingressController {
ctl := &ingressController{
controller: c,
- workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "ingress"),
+ workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemFastSlowRateLimiter(1*time.Second, 60*time.Second, 5), "ingress"),
workers: 1,
}
@@ -201,15 +202,11 @@ func (c *ingressController) handleSyncErr(obj interface{}, err error) {
c.workqueue.Forget(obj)
return
}
- if c.workqueue.NumRequeues(obj) < _maxRetries {
- log.Infow("sync ingress failed, will retry",
- zap.Any("object", obj),
- )
- c.workqueue.AddRateLimited(obj)
- } else {
- c.workqueue.Forget(obj)
- log.Warnf("drop ingress %+v out of the queue", obj)
- }
+ log.Warnw("sync ingress failed, will retry",
+ zap.Any("object", obj),
+ zap.Error(err),
+ )
+ c.workqueue.AddRateLimited(obj)
}
func (c *ingressController) onAdd(obj interface{}) {