tokers commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r617248945



##########
File path: pkg/ingress/apisix_route.go
##########
@@ -197,15 +208,57 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
        return c.controller.syncManifests(ctx, added, updated, deleted)
 }
 
-func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
-       if err == nil {
+func (c *apisixRouteController) handleSyncErr(obj interface{}, errOrigin 
error) {
+       ev := obj.(*types.Event)
+       event := ev.Object.(kube.ApisixRouteEvent)
+       namespace, name, errLocal := cache.SplitMetaNamespaceKey(event.Key)
+       if errLocal != nil {
+               log.Errorf("invalid resource key: %s", event.Key)

Review comment:
       We can just return here.

##########
File path: pkg/ingress/apisix_route.go
##########
@@ -197,15 +208,57 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
        return c.controller.syncManifests(ctx, added, updated, deleted)
 }
 
-func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
-       if err == nil {
+func (c *apisixRouteController) handleSyncErr(obj interface{}, errOrigin 
error) {
+       ev := obj.(*types.Event)
+       event := ev.Object.(kube.ApisixRouteEvent)
+       namespace, name, errLocal := cache.SplitMetaNamespaceKey(event.Key)
+       if errLocal != nil {
+               log.Errorf("invalid resource key: %s", event.Key)
+       }
+       if errOrigin == nil {
+               if ev.Type != types.EventDelete {
+                       var ar kube.ApisixRoute
+                       if event.GroupVersion == kube.ApisixRouteV1 {
+                               ar, errLocal = 
c.controller.apisixRouteLister.V1(namespace, name)
+                       } else {
+                               ar, errLocal = 
c.controller.apisixRouteLister.V2alpha1(namespace, name)
+                       }
+                       if errLocal == nil {
+                               message := fmt.Sprintf(_messageResourceSynced, 
_component)
+                               if ar.GroupVersion() == kube.ApisixRouteV1 {
+                                       c.recorder.Event(ar.V1(), 
v1.EventTypeNormal, _resourceSynced, message)
+                               } else if ar.GroupVersion() == 
kube.ApisixRouteV2alpha1 {
+                                       c.recorder.Event(ar.V2alpha1(), 
v1.EventTypeNormal, _resourceSynced, message)
+                                       RecordRouteStatus(ar.V2alpha1(), 
_resourceSynced, CommonSuccessMessage, metav1.ConditionTrue)
+                               }
+                       } else {
+                               log.Errorf("invalid resource key: %s", 
event.Key)

Review comment:
       The error message is not accurate.
   
   ```suggestion
                                log.Errorw("failed list ApisixRoute",
                                        zap.Error(errLocal),
                                        zap.String("name", name),
                                        zap.String("namespace", namespace),
                                )
   ```

##########
File path: pkg/ingress/apisix_route.go
##########
@@ -197,15 +208,57 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
        return c.controller.syncManifests(ctx, added, updated, deleted)
 }
 
-func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
-       if err == nil {
+func (c *apisixRouteController) handleSyncErr(obj interface{}, errOrigin 
error) {
+       ev := obj.(*types.Event)
+       event := ev.Object.(kube.ApisixRouteEvent)
+       namespace, name, errLocal := cache.SplitMetaNamespaceKey(event.Key)
+       if errLocal != nil {
+               log.Errorf("invalid resource key: %s", event.Key)
+       }
+       if errOrigin == nil {
+               if ev.Type != types.EventDelete {
+                       var ar kube.ApisixRoute
+                       if event.GroupVersion == kube.ApisixRouteV1 {
+                               ar, errLocal = 
c.controller.apisixRouteLister.V1(namespace, name)
+                       } else {
+                               ar, errLocal = 
c.controller.apisixRouteLister.V2alpha1(namespace, name)
+                       }
+                       if errLocal == nil {
+                               message := fmt.Sprintf(_messageResourceSynced, 
_component)
+                               if ar.GroupVersion() == kube.ApisixRouteV1 {
+                                       c.recorder.Event(ar.V1(), 
v1.EventTypeNormal, _resourceSynced, message)
+                               } else if ar.GroupVersion() == 
kube.ApisixRouteV2alpha1 {
+                                       c.recorder.Event(ar.V2alpha1(), 
v1.EventTypeNormal, _resourceSynced, message)
+                                       RecordRouteStatus(ar.V2alpha1(), 
_resourceSynced, CommonSuccessMessage, metav1.ConditionTrue)
+                               }
+                       } else {
+                               log.Errorf("invalid resource key: %s", 
event.Key)
+                       }
+               }
                c.workqueue.Forget(obj)
                return
        }
        log.Warnw("sync ApisixRoute failed, will retry",
                zap.Any("object", obj),
-               zap.Error(err),
+               zap.Error(errOrigin),
        )
+       var ar kube.ApisixRoute
+       if event.GroupVersion == kube.ApisixRouteV1 {

Review comment:
       Logic to get `ApisixRoute` can be put prepositive, so we only need to 
use the lister one place.

##########
File path: pkg/ingress/endpoint.go
##########
@@ -181,8 +181,8 @@ func (c *endpointsController) onAdd(obj interface{}) {
        if !c.controller.namespaceWatching(key) {
                return
        }
-       log.Debugw("endpoints add event arrived",
-               zap.Any("object", obj))
+       //log.Debugw("endpoints add event arrived",

Review comment:
       error?

##########
File path: pkg/ingress/status.go
##########
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package ingress
+
+import (
+       "context"
+
+       "k8s.io/apimachinery/pkg/api/meta"
+       metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+       v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+       "github.com/apache/apisix-ingress-controller/pkg/kube"
+       configv2alpha1 
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+       
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/client/clientset/versioned/typed/config/v2alpha1"
+)
+
+const (
+       ConditionType        = "ResourcesAvailable"

Review comment:
       Should always set constants unexportable if they are not used by 
external packages.




-- 
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:
us...@infra.apache.org


Reply via email to