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



##########
File path: pkg/kube/translation/util.go
##########
@@ -110,6 +110,14 @@ loop:
        return svc.Spec.ClusterIP, svcPort, nil
 }
 
+// translateUpstreamNotStrictly is not strictly translation, only generate ID 
and Name for delete Event.

Review comment:
       ```suggestion
   // translateUpstreamNotStrictly translates Upstream nodes with a loose way, 
only generate ID and Name for delete Event.
   ```

##########
File path: pkg/kube/translation/apisix_route.go
##########
@@ -304,6 +346,24 @@ func (t *translator) translateRouteMatchExprs(nginxVars 
[]configv2alpha1.ApisixR
        return vars, nil
 }
 
+// translateTCPRouteNotStrictly is not strictly translation, only generate ID 
and Name for delete Event.
+func (t *translator) translateTCPRouteNotStrictly(ctx *TranslateContext, ar 
*configv2alpha1.ApisixRoute) error {
+       for _, part := range ar.Spec.TCP {
+               backend := &part.Backend
+               sr := apisixv1.NewDefaultStreamRoute()
+               name := apisixv1.ComposeStreamRouteName(ar.Namespace, ar.Name, 
part.Name)
+               sr.ID = id.GenID(name)
+               sr.ServerPort = part.Match.IngressPort
+               ups, err := t.translateUpstreamNotStrictly(ar.Namespace, 
backend.ServiceName, backend.Subset, backend.ServicePort.IntVal)
+               if err != nil {
+                       return err
+               }
+               sr.Upstream = ups
+               ctx.addStreamRoute(sr)

Review comment:
       Should also add the `ups` to `ctx`.

##########
File path: pkg/ingress/apisix_route.go
##########
@@ -139,7 +139,11 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
                        return err
                }
        } else {
-               tctx, err = 
c.controller.translator.TranslateRouteV2alpha1(ar.V2alpha1())
+               if ev.Type != types.EventDelete {

Review comment:
       We may description the reason here.

##########
File path: pkg/kube/translation/apisix_route.go
##########
@@ -304,6 +346,24 @@ func (t *translator) translateRouteMatchExprs(nginxVars 
[]configv2alpha1.ApisixR
        return vars, nil
 }
 
+// translateTCPRouteNotStrictly is not strictly translation, only generate ID 
and Name for delete Event.
+func (t *translator) translateTCPRouteNotStrictly(ctx *TranslateContext, ar 
*configv2alpha1.ApisixRoute) error {
+       for _, part := range ar.Spec.TCP {
+               backend := &part.Backend
+               sr := apisixv1.NewDefaultStreamRoute()
+               name := apisixv1.ComposeStreamRouteName(ar.Namespace, ar.Name, 
part.Name)
+               sr.ID = id.GenID(name)
+               sr.ServerPort = part.Match.IngressPort
+               ups, err := t.translateUpstreamNotStrictly(ar.Namespace, 
backend.ServiceName, backend.Subset, backend.ServicePort.IntVal)
+               if err != nil {
+                       return err
+               }
+               sr.Upstream = ups
+               ctx.addStreamRoute(sr)

Review comment:
       We should.
   
   By the way, the code in your link should also be changed as now stream_route 
can use upstream_id.

##########
File path: pkg/kube/translation/apisix_route.go
##########
@@ -329,8 +389,9 @@ func (t *translator) translateTCPRoute(ctx 
*TranslateContext, ar *configv2alpha1
                if err != nil {
                        return err
                }
-               sr.Upstream = ups
+               sr.UpstreamId = ups.ID
                ctx.addStreamRoute(sr)
+               ctx.addUpstream(ups)

Review comment:
       Should check whether it existed already.

##########
File path: test/e2e/scaffold/k8s.go
##########
@@ -29,11 +28,12 @@ import (
        "github.com/stretchr/testify/assert"
        corev1 "k8s.io/api/core/v1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+       "k8s.io/apimachinery/pkg/util/intstr"
        "k8s.io/apimachinery/pkg/util/wait"
 )
 
 type counter struct {
-       Count string `json:"count"`
+       Count intstr.IntOrString `json:"count"`

Review comment:
       Are you sure the marshaling and unmarshaling can be done?
   
   type IntOrString struct {
        Type   Type   `protobuf:"varint,1,opt,name=type,casttype=Type"`
        IntVal int32  `protobuf:"varint,2,opt,name=intVal"`
        StrVal string `protobuf:"bytes,3,opt,name=strVal"`
   }




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