gxthrj commented on a change in pull request #163:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/163#discussion_r554321363



##########
File path: pkg/apisix/resource.go
##########
@@ -116,6 +116,7 @@ func (i *item) upstream(clusterName string) (*v1.Upstream, 
error) {
        }
 
        var ups upstreamItem
+       log.Info(string(i.Value))

Review comment:
       Removed

##########
File path: pkg/ingress/controller/apisix_upstream.go
##########
@@ -112,30 +112,46 @@ func (c *ApisixUpstreamController) processNextWorkItem() 
bool {
        return true
 }
 
-func (c *ApisixUpstreamController) syncHandler(key string) error {
-       namespace, name, err := cache.SplitMetaNamespaceKey(key)
+func (c *ApisixUpstreamController) syncHandler(sqo *UpstreamQueueObj) error {
+       namespace, name, err := cache.SplitMetaNamespaceKey(sqo.Key)
        if err != nil {
-               log.Errorf("invalid resource key: %s", key)
-               return fmt.Errorf("invalid resource key: %s", key)
+               log.Errorf("invalid resource key: %s", sqo.Key)
+               return fmt.Errorf("invalid resource key: %s", sqo.Key)
        }
-
-       apisixUpstreamYaml, err := 
c.apisixUpstreamList.ApisixUpstreams(namespace).Get(name)
-       if err != nil {
-               if errors.IsNotFound(err) {
-                       log.Infof("apisixUpstream %s is removed", key)
+       apisixUpstreamYaml := sqo.OldObj
+       if sqo.Ope == DELETE {
+               apisixIngressUpstream, _ := 
c.apisixUpstreamList.ApisixUpstreams(namespace).Get(name)
+               if apisixIngressUpstream != nil && 
apisixIngressUpstream.ResourceVersion > sqo.OldObj.ResourceVersion {
+                       log.Warnf("Upstram %s has been covered when retry", 
sqo.Key)
                        return nil
                }
-               runtime.HandleError(fmt.Errorf("failed to list apisixUpstream 
%s/%s", key, err.Error()))
-               return err
+       } else {
+               apisixUpstreamYaml, err = 
c.apisixUpstreamList.ApisixUpstreams(namespace).Get(name)
+               if err != nil {
+                       if errors.IsNotFound(err) {
+                               log.Infof("apisixUpstraem %s is removed", 
sqo.Key)

Review comment:
       Done

##########
File path: pkg/ingress/controller/apisix_upstream.go
##########
@@ -112,30 +112,46 @@ func (c *ApisixUpstreamController) processNextWorkItem() 
bool {
        return true
 }
 
-func (c *ApisixUpstreamController) syncHandler(key string) error {
-       namespace, name, err := cache.SplitMetaNamespaceKey(key)
+func (c *ApisixUpstreamController) syncHandler(sqo *UpstreamQueueObj) error {
+       namespace, name, err := cache.SplitMetaNamespaceKey(sqo.Key)
        if err != nil {
-               log.Errorf("invalid resource key: %s", key)
-               return fmt.Errorf("invalid resource key: %s", key)
+               log.Errorf("invalid resource key: %s", sqo.Key)
+               return fmt.Errorf("invalid resource key: %s", sqo.Key)
        }
-
-       apisixUpstreamYaml, err := 
c.apisixUpstreamList.ApisixUpstreams(namespace).Get(name)
-       if err != nil {
-               if errors.IsNotFound(err) {
-                       log.Infof("apisixUpstream %s is removed", key)
+       apisixUpstreamYaml := sqo.OldObj
+       if sqo.Ope == DELETE {
+               apisixIngressUpstream, _ := 
c.apisixUpstreamList.ApisixUpstreams(namespace).Get(name)
+               if apisixIngressUpstream != nil && 
apisixIngressUpstream.ResourceVersion > sqo.OldObj.ResourceVersion {
+                       log.Warnf("Upstram %s has been covered when retry", 
sqo.Key)
                        return nil
                }
-               runtime.HandleError(fmt.Errorf("failed to list apisixUpstream 
%s/%s", key, err.Error()))
-               return err
+       } else {
+               apisixUpstreamYaml, err = 
c.apisixUpstreamList.ApisixUpstreams(namespace).Get(name)
+               if err != nil {
+                       if errors.IsNotFound(err) {
+                               log.Infof("apisixUpstraem %s is removed", 
sqo.Key)
+                               return nil
+                       }
+                       runtime.HandleError(fmt.Errorf("failed to list 
apisixService %s/%s", sqo.Key, err.Error()))

Review comment:
       Done

##########
File path: pkg/ingress/controller/apisix_upstream.go
##########
@@ -145,25 +161,45 @@ func (c *ApisixUpstreamController) addFunc(obj 
interface{}) {
                runtime.HandleError(err)
                return
        }
-       c.workqueue.AddRateLimited(key)
+       sqo := &UpstreamQueueObj{Key: key, OldObj: nil, Ope: ADD}
+       c.workqueue.AddRateLimited(sqo)
 }
 
 func (c *ApisixUpstreamController) updateFunc(oldObj, newObj interface{}) {
-       oldRoute := oldObj.(*apisixV1.ApisixUpstream)
-       newRoute := newObj.(*apisixV1.ApisixUpstream)
-       if oldRoute.ResourceVersion == newRoute.ResourceVersion {
+       oldUpstream := oldObj.(*apisixV1.ApisixUpstream)
+       newUpstream := newObj.(*apisixV1.ApisixUpstream)
+       if oldUpstream.ResourceVersion >= newUpstream.ResourceVersion {
                return
        }
-       c.addFunc(newObj)
+       var key string

Review comment:
       Done

##########
File path: test/e2e/scaffold/crd.go
##########
@@ -22,14 +22,13 @@ import (
        "strconv"
        "time"
 
+       "github.com/api7/ingress-controller/pkg/apisix"

Review comment:
       In the test mod , `github.com/api7/ingress-controller` is an externally 
imported package.
   I used fmt tool for me to deal with group of imports.

##########
File path: test/e2e/scaffold/ingress.go
##########
@@ -77,7 +77,7 @@ spec:
             tcpSocket:
               port: 8080
             timeoutSeconds: 2
-          image: "apache/apisix-ingress-controller:dev"
+          image: "apisix-ingress-controller:dev"

Review comment:
       Done




----------------------------------------------------------------
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]


Reply via email to