func()

in pkg/providers/apisix/apisix_global_rule.go [180:243]


func (c *apisixGlobalRuleController) handleSyncErr(obj interface{}, errOrigin error) {
	ev := obj.(*types.Event)
	event := ev.Object.(kube.ApisixGlobalRuleEvent)
	if k8serrors.IsNotFound(errOrigin) && ev.Type != types.EventDelete {
		log.Infow("sync ApisixGlobalRule but not found, ignore",
			zap.String("event_type", ev.Type.String()),
			zap.String("ApisixGlobalRule", ev.Object.(kube.ApisixGlobalRuleEvent).Key),
		)
		c.workqueue.Forget(event)
		return
	}
	namespace, name, errLocal := cache.SplitMetaNamespaceKey(event.Key)
	if errLocal != nil {
		log.Errorf("invalid resource key: %s", event.Key)
		c.MetricsCollector.IncrSyncOperation("GlobalRule", "failure")
		return
	}
	var agr kube.ApisixGlobalRule
	switch event.GroupVersion {
	case config.ApisixV2:
		agr, errLocal = c.ApisixGlobalRuleLister.V2(namespace, name)
	default:
		errLocal = fmt.Errorf("unsupported ApisixGlobalRule group version %s", event.GroupVersion)
	}
	if errOrigin == nil {
		if ev.Type != types.EventDelete {
			if errLocal == nil {
				switch agr.GroupVersion() {
				case config.ApisixV2:
					c.RecordEvent(agr.V2(), v1.EventTypeNormal, utils.ResourceSynced, nil)
					c.recordStatus(agr.V2(), utils.ResourceSynced, nil, metav1.ConditionTrue, agr.GetGeneration())
				}
			} else {
				log.Errorw("failed list ApisixGlobalRule",
					zap.Error(errLocal),
					zap.String("name", name),
					zap.String("namespace", namespace),
				)
			}
		}
		c.workqueue.Forget(obj)
		c.MetricsCollector.IncrSyncOperation("GlobalRule", "success")
		return
	}
	log.Warnw("sync ApisixGlobalRule failed, will retry",
		zap.Any("object", obj),
		zap.Error(errOrigin),
	)
	if errLocal == nil {
		switch agr.GroupVersion() {
		case config.ApisixV2:
			c.RecordEvent(agr.V2(), v1.EventTypeWarning, utils.ResourceSyncAborted, errOrigin)
			c.recordStatus(agr.V2(), utils.ResourceSyncAborted, errOrigin, metav1.ConditionFalse, agr.GetGeneration())
		}
	} else {
		log.Errorw("failed list ApisixGlobalRule",
			zap.Error(errLocal),
			zap.String("name", name),
			zap.String("namespace", namespace),
		)
	}
	c.workqueue.AddRateLimited(obj)
	c.MetricsCollector.IncrSyncOperation("GlobalRule", "failure")
}