|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package gatewayapi |
| 19 | + |
| 20 | +import ( |
| 21 | + "fmt" |
| 22 | + "time" |
| 23 | + |
| 24 | + "github.com/apache/apisix-ingress-controller/test/e2e/framework" |
| 25 | + "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" |
| 26 | + . "github.com/onsi/ginkgo/v2" |
| 27 | + . "github.com/onsi/gomega" |
| 28 | +) |
| 29 | + |
| 30 | +var _ = Describe("TCPRoute E2E Test", func() { |
| 31 | + s := scaffold.NewDefaultScaffold() |
| 32 | + |
| 33 | + var gatewayProxyYaml = ` |
| 34 | +apiVersion: apisix.apache.org/v1alpha1 |
| 35 | +kind: GatewayProxy |
| 36 | +metadata: |
| 37 | + name: %s |
| 38 | +spec: |
| 39 | + provider: |
| 40 | + type: ControlPlane |
| 41 | + controlPlane: |
| 42 | + service: |
| 43 | + name: %s |
| 44 | + port: 9180 |
| 45 | + auth: |
| 46 | + type: AdminKey |
| 47 | + adminKey: |
| 48 | + value: "%s" |
| 49 | +` |
| 50 | + getGatewayProxySpec := func() string { |
| 51 | + return fmt.Sprintf(gatewayProxyYaml, s.Namespace(), framework.ProviderType, s.AdminKey()) |
| 52 | + } |
| 53 | + |
| 54 | + var gatewayClassYaml = ` |
| 55 | +apiVersion: gateway.networking.k8s.io/v1 |
| 56 | +kind: GatewayClass |
| 57 | +metadata: |
| 58 | + name: %s |
| 59 | +spec: |
| 60 | + controllerName: %s |
| 61 | +` |
| 62 | + Context("TCPRoute Base", func() { |
| 63 | + var tcpGateway = ` |
| 64 | +apiVersion: gateway.networking.k8s.io/v1 |
| 65 | +kind: Gateway |
| 66 | +metadata: |
| 67 | + name: %s |
| 68 | +spec: |
| 69 | + gatewayClassName: %s |
| 70 | + listeners: |
| 71 | + - name: tcp |
| 72 | + protocol: TCP |
| 73 | + port: 80 |
| 74 | + allowedRoutes: |
| 75 | + kinds: |
| 76 | + - kind: TCPRoute |
| 77 | + infrastructure: |
| 78 | + parametersRef: |
| 79 | + group: apisix.apache.org |
| 80 | + kind: GatewayProxy |
| 81 | + name: %s |
| 82 | +` |
| 83 | + |
| 84 | + var tcpRoute = ` |
| 85 | +apiVersion: gateway.networking.k8s.io/v1alpha2 |
| 86 | +kind: TCPRoute |
| 87 | +metadata: |
| 88 | + name: tcp-app-1 |
| 89 | +spec: |
| 90 | + parentRefs: |
| 91 | + - name: %s |
| 92 | + sectionName: tcp |
| 93 | + rules: |
| 94 | + - backendRefs: |
| 95 | + - name: httpbin-service-e2e-test |
| 96 | + port: 80 |
| 97 | +` |
| 98 | + |
| 99 | + BeforeEach(func() { |
| 100 | + // Create GatewayProxy |
| 101 | + Expect(s.CreateResourceFromStringWithNamespace(getGatewayProxySpec(), s.Namespace())). |
| 102 | + NotTo(HaveOccurred(), "creating GatewayProxy") |
| 103 | + |
| 104 | + // Create GatewayClass |
| 105 | + gatewayClassName := s.Namespace() |
| 106 | + Expect(s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayClassYaml, gatewayClassName, s.GetControllerName()), "")). |
| 107 | + NotTo(HaveOccurred(), "creating GatewayClass") |
| 108 | + |
| 109 | + s.RetryAssertion(func() string { |
| 110 | + gcyaml, _ := s.GetResourceYaml("GatewayClass", gatewayClassName) |
| 111 | + return gcyaml |
| 112 | + }).Should( |
| 113 | + And( |
| 114 | + ContainSubstring(`status: "True"`), |
| 115 | + ContainSubstring("message: the gatewayclass has been accepted by the apisix-ingress-controller"), |
| 116 | + ), |
| 117 | + "check GatewayClass condition", |
| 118 | + ) |
| 119 | + |
| 120 | + // Create Gateway with TCP listener |
| 121 | + gatewayName := s.Namespace() |
| 122 | + Expect(s.CreateResourceFromStringWithNamespace(fmt.Sprintf(tcpGateway, gatewayName, gatewayClassName, s.Namespace()), s.Namespace())). |
| 123 | + NotTo(HaveOccurred(), "creating Gateway") |
| 124 | + |
| 125 | + s.RetryAssertion(func() string { |
| 126 | + gwyaml, _ := s.GetResourceYaml("Gateway", gatewayName) |
| 127 | + return gwyaml |
| 128 | + }).Should( |
| 129 | + And( |
| 130 | + ContainSubstring(`status: "True"`), |
| 131 | + ContainSubstring("message: the gateway has been accepted by the apisix-ingress-controlle"), |
| 132 | + ), |
| 133 | + "check Gateway condition status", |
| 134 | + ) |
| 135 | + }) |
| 136 | + |
| 137 | + FIt("should route TCP traffic to backend service", func() { |
| 138 | + gatewayName := s.Namespace() |
| 139 | + By("creating TCPRoute") |
| 140 | + Expect(s.CreateResourceFromString(fmt.Sprintf(tcpRoute, gatewayName))). |
| 141 | + NotTo(HaveOccurred(), "creating TCPRoute") |
| 142 | + |
| 143 | + // Verify TCPRoute status becomes programmed |
| 144 | + s.RetryAssertion(func() string { |
| 145 | + routeYaml, _ := s.GetResourceYaml("TCPRoute", "tcp-app-1") |
| 146 | + return routeYaml |
| 147 | + }).Should( |
| 148 | + ContainSubstring(`status: "True"`), |
| 149 | + "check TCPRoute status", |
| 150 | + ) |
| 151 | + |
| 152 | + By("verifying TCPRoute is functional") |
| 153 | + s.HTTPOverTCPConnectAssert(true, time.Second*10) // should be able to connect |
| 154 | + By("sending TCP traffic to verify routing") |
| 155 | + s.RequestAssert(&scaffold.RequestAssert{ |
| 156 | + Client: s.NewAPISIXClientOnTCPPort(), |
| 157 | + Method: "GET", |
| 158 | + Path: "/get", |
| 159 | + Check: scaffold.WithExpectedStatus(200), |
| 160 | + Timeout: time.Minute * 30, |
| 161 | + Interval: time.Second * 2, |
| 162 | + }) |
| 163 | + |
| 164 | + By("deleting TCPRoute") |
| 165 | + Expect(s.DeleteResource("TCPRoute", "tcp-app-1")). |
| 166 | + NotTo(HaveOccurred(), "deleting TCPRoute") |
| 167 | + |
| 168 | + s.HTTPOverTCPConnectAssert(false, time.Second*10) |
| 169 | + }) |
| 170 | + }) |
| 171 | +}) |
0 commit comments