Skip to content

Commit

Permalink
e2e test for Gateway with EnvoyProxy (envoyproxy#4548)
Browse files Browse the repository at this point in the history
* e2e test for Gateway with EnvoyProxy

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>

* remove unnecessary comments

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>

---------

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
(cherry picked from commit 217c6a5)
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
  • Loading branch information
zhaohuabing committed Nov 6, 2024
1 parent 562efa9 commit 5514167
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ func (r *gatewayAPIReconciler) processSecretRef(
}
}
}
resourceMap.allAssociatedNamespaces.Insert(secretNS) // TODO Zhaohuabing do we need this line?
resourceMap.allAssociatedNamespaces.Insert(secretNS)
key := utils.NamespacedName(secret).String()
if !resourceMap.allAssociatedSecrets.Has(key) {
resourceMap.allAssociatedSecrets.Insert(key)
Expand Down Expand Up @@ -740,7 +740,7 @@ func (r *gatewayAPIReconciler) processConfigMapRef(
}
}
}
resourceMap.allAssociatedNamespaces.Insert(configMapNS) // TODO Zhaohuabing do we need this line?
resourceMap.allAssociatedNamespaces.Insert(configMapNS)
if !resourceMap.allAssociatedConfigMaps.Has(utils.NamespacedName(configMap).String()) {
resourceMap.allAssociatedConfigMaps.Insert(utils.NamespacedName(configMap).String())
resourceTree.ConfigMaps = append(resourceTree.ConfigMaps, configMap)
Expand Down
49 changes: 49 additions & 0 deletions test/e2e/testdata/gateway-with-envoyproxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway-with-envoyproxy
namespace: gateway-conformance-infra
spec:
gatewayClassName: "{GATEWAY_CLASS_NAME}"
infrastructure:
parametersRef:
group: gateway.envoyproxy.io
kind: EnvoyProxy
name: test
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
namespace: gateway-conformance-infra
name: test
spec:
routingType: Service
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: http-route
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: gateway-with-envoyproxy
rules:
- matches:
- path:
value: /
backendRefs:
- name: infra-backend-v1
port: 8080
filters:
- type: ResponseHeaderModifier
responseHeaderModifier:
add:
- name: upstream-host
value: '%UPSTREAM_HOST%'
59 changes: 59 additions & 0 deletions test/e2e/tests/gatewayt-with-envoyproxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

//go:build e2e

package tests

import (
"context"
"testing"

"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, GatewayWithEnvoyProxy)
}

var GatewayWithEnvoyProxy = suite.ConformanceTest{
ShortName: "Gateway with EnvoyProxy",
Description: "Attach an EnvoyProxy to a Gateway",
Manifests: []string{"testdata/gateway-with-envoyproxy.yaml"},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
t.Run("Attach an EnvoyProxy to a Gateway and set RoutingType to Service", func(t *testing.T) {
ns := "gateway-conformance-infra"
routeNN := types.NamespacedName{Name: "http-route", Namespace: ns}
gwNN := types.NamespacedName{Name: "gateway-with-envoyproxy", Namespace: ns}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

backendNN := types.NamespacedName{Name: "infra-backend-v1", Namespace: ns}
svc := corev1.Service{}
require.NoError(t, suite.Client.Get(context.Background(), backendNN, &svc))

expectedResponse := http.ExpectedResponse{
Request: http.Request{
Path: "/basic-auth-1",
},
Response: http.Response{
StatusCode: 200,

// Verify that the RouteType is set to Service by the attached EnvoyProxy
Headers: map[string]string{
"upstream-host": svc.Spec.ClusterIP + ":8080",
},
},
Namespace: ns,
}

http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
})
},
}

0 comments on commit 5514167

Please sign in to comment.