Skip to content

Commit

Permalink
fix: controller err handler should ignore not found error (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
lingsamuel committed Mar 8, 2022
1 parent f84a083 commit 1159522
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/ingress/apisix_cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ func (c *apisixClusterConfigController) handleSyncErr(obj interface{}, err error
c.controller.MetricsCollector.IncrSyncOperation("clusterConfig", "success")
return
}
event := obj.(*types.Event)
if k8serrors.IsNotFound(err) && event.Type != types.EventDelete {
log.Infow("sync ApisixClusterConfig but not found, ignore",
zap.String("event_type", event.Type.String()),
zap.String("ApisixClusterConfig", event.Object.(string)),
)
c.workqueue.Forget(event)
return
}
log.Warnw("sync ApisixClusterConfig failed, will retry",
zap.Any("object", obj),
zap.Error(err),
Expand Down
9 changes: 9 additions & 0 deletions pkg/ingress/apisix_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ func (c *apisixConsumerController) handleSyncErr(obj interface{}, err error) {
c.controller.MetricsCollector.IncrSyncOperation("consumer", "success")
return
}
event := obj.(*types.Event)
if k8serrors.IsNotFound(err) && event.Type != types.EventDelete {
log.Infow("sync ApisixConsumer but not found, ignore",
zap.String("event_type", event.Type.String()),
zap.String("ApisixConsumer", event.Object.(string)),
)
c.workqueue.Forget(event)
return
}
log.Warnw("sync ApisixConsumer failed, will retry",
zap.Any("object", obj),
zap.Error(err),
Expand Down
8 changes: 8 additions & 0 deletions pkg/ingress/apisix_pluginconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ func (c *apisixPluginConfigController) sync(ctx context.Context, ev *types.Event
func (c *apisixPluginConfigController) handleSyncErr(obj interface{}, errOrigin error) {
ev := obj.(*types.Event)
event := ev.Object.(kube.ApisixPluginConfigEvent)
if k8serrors.IsNotFound(errOrigin) && ev.Type != types.EventDelete {
log.Infow("sync ApisixPluginConfig but not found, ignore",
zap.String("event_type", ev.Type.String()),
zap.String("ApisixPluginConfig", ev.Object.(kube.ApisixPluginConfigEvent).Key),
)
c.workqueue.Forget(event)
return
}
namespace, name, errLocal := cache.SplitMetaNamespaceKey(event.Key)
if errLocal != nil {
log.Errorf("invalid resource key: %s", event.Key)
Expand Down
8 changes: 8 additions & 0 deletions pkg/ingress/apisix_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ func (c *apisixRouteController) checkPluginNameIfNotEmptyV2beta3(ctx context.Con
func (c *apisixRouteController) handleSyncErr(obj interface{}, errOrigin error) {
ev := obj.(*types.Event)
event := ev.Object.(kube.ApisixRouteEvent)
if k8serrors.IsNotFound(errOrigin) && ev.Type != types.EventDelete {
log.Infow("sync ApisixRoute but not found, ignore",
zap.String("event_type", ev.Type.String()),
zap.String("ApisixRoute", ev.Object.(string)),
)
c.workqueue.Forget(event)
return
}
namespace, name, errLocal := cache.SplitMetaNamespaceKey(event.Key)
if errLocal != nil {
log.Errorf("invalid resource key: %s", event.Key)
Expand Down
10 changes: 10 additions & 0 deletions pkg/ingress/apisix_tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ func (c *apisixTlsController) handleSyncErr(obj interface{}, err error) {
c.controller.MetricsCollector.IncrSyncOperation("TLS", "success")
return
}

event := obj.(*types.Event)
if k8serrors.IsNotFound(err) && event.Type != types.EventDelete {
log.Infow("sync ApisixTls but not found, ignore",
zap.String("event_type", event.Type.String()),
zap.String("ApisixTls", event.Object.(string)),
)
c.workqueue.Forget(event)
return
}
log.Warnw("sync ApisixTls failed, will retry",
zap.Any("object", obj),
zap.Error(err),
Expand Down
10 changes: 10 additions & 0 deletions pkg/ingress/apisix_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ func (c *apisixUpstreamController) handleSyncErr(obj interface{}, err error) {
c.controller.MetricsCollector.IncrSyncOperation("upstream", "success")
return
}

event := obj.(*types.Event)
if k8serrors.IsNotFound(err) && event.Type != types.EventDelete {
log.Infow("sync ApisixUpstream but not found, ignore",
zap.String("event_type", event.Type.String()),
zap.String("ApisixUpstream", event.Object.(string)),
)
c.workqueue.Forget(event)
return
}
log.Warnw("sync ApisixUpstream failed, will retry",
zap.Any("object", obj),
zap.Error(err),
Expand Down
9 changes: 9 additions & 0 deletions pkg/ingress/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ func (c *endpointsController) handleSyncErr(obj interface{}, err error) {
c.controller.MetricsCollector.IncrSyncOperation("endpoints", "success")
return
}
event := obj.(*types.Event)
if errors.IsNotFound(err) && event.Type != types.EventDelete {
log.Infow("sync endpoints but not found, ignore",
zap.String("event_type", event.Type.String()),
zap.Any("endpoints", event.Object.(kube.Endpoint)),
)
c.workqueue.Forget(event)
return
}
log.Warnw("sync endpoints failed, will retry",
zap.Any("object", obj),
)
Expand Down
10 changes: 10 additions & 0 deletions pkg/ingress/endpointslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"go.uber.org/zap"
discoveryv1 "k8s.io/api/discovery/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"

Expand Down Expand Up @@ -112,6 +113,15 @@ func (c *endpointSliceController) handleSyncErr(obj interface{}, err error) {
c.controller.MetricsCollector.IncrSyncOperation("endpointSlice", "success")
return
}
event := obj.(*types.Event)
if k8serrors.IsNotFound(err) && event.Type != types.EventDelete {
log.Infow("sync endpointSlice but not found, ignore",
zap.String("event_type", event.Type.String()),
zap.String("endpointSlice", event.Object.(string)),
)
c.workqueue.Forget(event)
return
}
log.Warnw("sync endpointSlice failed, will retry",
zap.Any("object", obj),
)
Expand Down
9 changes: 9 additions & 0 deletions pkg/ingress/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ func (c *gatewayController) handleSyncErr(obj interface{}, err error) {
c.controller.MetricsCollector.IncrSyncOperation("gateway", "success")
return
}
event := obj.(*types.Event)
if k8serrors.IsNotFound(err) && event.Type != types.EventDelete {
log.Infow("sync gateway but not found, ignore",
zap.String("event_type", event.Type.String()),
zap.String("gateway", event.Object.(string)),
)
c.workqueue.Forget(event)
return
}
log.Warnw("sync gateway failed, will retry",
zap.Any("object", obj),
zap.Error(err),
Expand Down
8 changes: 8 additions & 0 deletions pkg/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ func (c *ingressController) sync(ctx context.Context, ev *types.Event) error {
func (c *ingressController) handleSyncErr(obj interface{}, err error) {
ev := obj.(*types.Event)
event := ev.Object.(kube.IngressEvent)
if k8serrors.IsNotFound(err) && ev.Type != types.EventDelete {
log.Infow("sync ingress but not found, ignore",
zap.String("event_type", ev.Type.String()),
zap.String("ingress", event.Key),
)
c.workqueue.Forget(event)
return
}
namespace, name, errLocal := cache.SplitMetaNamespaceKey(event.Key)
if errLocal != nil {
log.Errorw("invalid resource key",
Expand Down
11 changes: 10 additions & 1 deletion pkg/ingress/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,16 @@ func (c *secretController) handleSyncErr(obj interface{}, err error) {
c.controller.MetricsCollector.IncrSyncOperation("secret", "success")
return
}
log.Warnw("sync ApisixTls failed, will retry",
event := obj.(*types.Event)
if k8serrors.IsNotFound(err) && event.Type != types.EventDelete {
log.Infow("sync secret but not found, ignore",
zap.String("event_type", event.Type.String()),
zap.String("secret", event.Object.(string)),
)
c.workqueue.Forget(event)
return
}
log.Warnw("sync secret failed, will retry",
zap.Any("object", obj),
zap.Error(err),
)
Expand Down

0 comments on commit 1159522

Please sign in to comment.