tokers commented on a change in pull request #576: URL: https://github.com/apache/apisix-ingress-controller/pull/576#discussion_r667284694
########## File path: test/e2e/ingress/stream.go ########## @@ -0,0 +1,108 @@ +// 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" + "fmt" + "time" + + "github.com/onsi/ginkgo" + "github.com/stretchr/testify/assert" + + "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" +) + +var _ = ginkgo.Describe("ApisixRoute stream Testing with v2beta1", func() { + opts := &scaffold.Options{ + Name: "default", + Kubeconfig: scaffold.GetKubeconfig(), + APISIXConfigPath: "testdata/apisix-gw-config.yaml", + IngressAPISIXReplicas: 1, + HTTPBinServicePort: 80, + APISIXRouteVersion: "apisix.apache.org/v2beta1", + } + s := scaffold.NewScaffold(opts) + ginkgo.It("stream tcp proxy", func() { + backendSvc, backendSvcPort := s.DefaultHTTPBackend() + apisixRoute := fmt.Sprintf(` +apiVersion: apisix.apache.org/v2beta1 +kind: ApisixRoute +metadata: + name: httpbin-tcp-route +spec: + stream: + - name: rule1 + protocol: TCP + match: + ingressPort: 9100 + backend: + serviceName: %s + servicePort: %d +`, backendSvc, backendSvcPort[0]) + + assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute)) + time.Sleep(9 * time.Second) + + err := s.EnsureNumApisixStreamRoutesCreated(1) + assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes") + + sr, err := s.ListApisixStreamRoutes() + assert.Nil(ginkgo.GinkgoT(), err) + assert.Len(ginkgo.GinkgoT(), sr, 1) + assert.Equal(ginkgo.GinkgoT(), sr[0].ServerPort, int32(9100)) + + resp := s.NewAPISIXClientWithTCPProxy().GET("/ip").Expect() + resp.Body().Contains("origin") + + resp = s.NewAPISIXClientWithTCPProxy().GET("/get").WithHeader("x-my-header", "x-my-value").Expect() + resp.Body().Contains("x-my-value") + }) + ginkgo.It("stream udp proxy", func() { + apisixRoute := fmt.Sprintf(` +apiVersion: apisix.apache.org/v2beta1 +kind: ApisixRoute +metadata: + name: httpbin-udp-route +spec: + stream: + - name: rule1 + protocol: UDP + match: + ingressPort: 9200 + backend: + serviceName: kube-dns Review comment: Does APISIX Ingress Controller find this service in the same namespace? kube-dns is in `kube-system`. ########## File path: pkg/kube/translation/util.go ########## @@ -110,6 +111,46 @@ loop: return svc.Spec.ClusterIP, svcPort, nil } +// getStreamServiceClusterIPAndPort is for v2beta1 streamRoute +func (t *translator) getStreamServiceClusterIPAndPort(backend configv2beta1.ApisixRouteStreamBackend, ns string) (string, int32, error) { + svc, err := t.ServiceLister.Services(ns).Get(backend.ServiceName) + if err != nil { + return "", 0, err + } + svcPort := int32(-1) +loop: + for _, port := range svc.Spec.Ports { + switch backend.ServicePort.Type { + case intstr.Int: + if backend.ServicePort.IntVal == port.Port { + svcPort = port.Port + break loop + } + case intstr.String: + if backend.ServicePort.StrVal == port.Name { + svcPort = port.Port + break loop + } + } + } + if svcPort == -1 { + log.Errorw("ApisixRoute refers to non-existent Service port", + zap.String("ApisixRoute namespace", ns), + zap.String("port", backend.ServicePort.String()), + ) + return "", 0, err + } + + if backend.ResolveGranularity == "service" && svc.Spec.ClusterIP == "" { Review comment: This check can be put before the for loop? ########## File path: pkg/ingress/pod.go ########## @@ -64,9 +64,9 @@ func (c *podController) onAdd(obj interface{}) { if !c.controller.namespaceWatching(key) { return } - log.Debugw("pod add event arrived", - zap.Any("object", obj), - ) + //log.Debugw("pod add event arrived", Review comment: We may still preserve this logging but don't show the object (just adding the name). ########## File path: test/e2e/ingress/stream.go ########## @@ -25,7 +26,7 @@ import ( "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" ) -var _ = ginkgo.Describe("ApisixRoute stream Testing with v2beta1", func() { +var _ = ginkgo.FDescribe("ApisixRoute stream Testing with v2beta1", func() { Review comment: Please remove the `F` prefix. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
