Skip to content

Commit 7621168

Browse files
authored
add static backend e2e test (#10736)
1 parent 9628754 commit 7621168

19 files changed

+186
-512
lines changed

.github/workflows/pr-kubernetes-tests.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ jobs:
2828
# Feb 27, 2025: 13 minutes
2929
- cluster-name: 'cluster-one'
3030
go-test-args: '-v -timeout=25m'
31-
go-test-run-regex: '^TestKgateway$$/^BasicRouting$$|^TestKgateway$$/^Deployer$$|^TestKgateway$$/^HTTPRouteServices$$|^TestKgateway$$/^TCPRouteServices$$|^TestKgateway$$/^TLSRouteServices$$'
31+
go-test-run-regex: '^TestKgateway$$/^BasicRouting$$|^TestKgateway$$/^Deployer$$|^TestKgateway$$/^HTTPRouteServices$$|^TestKgateway$$/^TCPRouteServices$$|^TestKgateway$$/^TLSRouteServices$$|^TestKgateway$$/^Backends$$'
3232

3333
# # Dec 4, 2024: 23 minutes
3434
# - cluster-name: 'cluster-two'
3535
# go-test-args: '-v -timeout=25m'
36-
# go-test-run-regex: '^TestKgateway$$/^RouteDelegation$$|^TestKgatewayIstioRevision$$|^TestRevisionIstioRegression$$|^TestKgateway$$/^RouteOptions$$|^TestKgateway$$/^VirtualHostOptions$$|^TestKgateway$$/^Upstreams$$|^TestKgateway$$/^HeadlessSvc$$|^TestKgateway$$/^PortRouting$$|^TestKgatewayMinimalDefaultGatewayParameters$$|^TestKgateway$$/^DirectResponse$$|^TestKgateway$$/^HttpListenerOptions$$|^TestKgateway$$/^ListenerOptions$$|^TestKgateway$$/^GlooAdminServer$$'
36+
# go-test-run-regex: '^TestKgateway$$/^RouteDelegation$$|^TestKgatewayIstioRevision$$|^TestRevisionIstioRegression$$|^TestKgateway$$/^RouteOptions$$|^TestKgateway$$/^VirtualHostOptions$$|^TestKgateway$$/^HeadlessSvc$$|^TestKgateway$$/^PortRouting$$|^TestKgatewayMinimalDefaultGatewayParameters$$|^TestKgateway$$/^DirectResponse$$|^TestKgateway$$/^HttpListenerOptions$$|^TestKgateway$$/^ListenerOptions$$|^TestKgateway$$/^GlooAdminServer$$'
3737

3838
# # Dec 4, 2024: 24 minutes
3939
# - cluster-name: 'cluster-three'

pkg/utils/kubeutils/dns.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ import (
88
// ServiceFQDN returns the FQDN for the Service, assuming it is being accessed from within the Cluster
99
// https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#services
1010
func ServiceFQDN(serviceMeta metav1.ObjectMeta) string {
11+
// TODO: remove dependency on knative just for this function
1112
return network.GetServiceHostname(serviceMeta.Name, serviceMeta.Namespace)
1213
}

test/kubernetes/e2e/debugging.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ There is no setup required for this option, as the test suite will download the
1616

1717
### Using a locally built version
1818
For these tests to run, we require the following conditions:
19-
- Gloo Gateway Helm chart archive is present in the `_test` folder,
20-
- `glooctl` is built in the `_output` folder
21-
- A KinD cluster is set up and loaded with the images to be installed by the helm chart
19+
- kgateway helm chart archive present in the `_test` folder
20+
- running kind cluster loaded with the images (with correct tags) referenced in the helm chart
2221

2322
[hack/kind/setup-kind.sh](/hack/kind/setup-kind.sh) gets run in CI to setup the test environment for the above requirements.
24-
It accepts a number of environment variables, to control the creation of a kind cluster and deployment of Gloo resources to that kind cluster. Please refer to the script itself to see what variables are available.
23+
The default settings should be sufficient for a working local environment.
24+
However, the setup script accepts a number of environment variables to control the creation of a kind cluster and deployment of kgateway resources.
25+
Please refer to the script itself to see what variables are available if you need customization.
2526

26-
Example:
27+
Basic Example:
2728
```bash
28-
CLUSTER_NAME=solo-test-cluster CLUSTER_NODE_VERSION=v1.30.0 VERSION=v1.0.0-solo-test hack/kind/setup-kind.sh
29+
./hack/kind/setup-kind.sh
2930
```
3031

3132
## Step 2: Running Tests
@@ -41,7 +42,7 @@ _should run `kind-<CLUSTER_NAME>`_
4142

4243
Since each feature suite is a subtest of the top level suite, you can run a single feature suite by running the top level suite with the `-run` flag.
4344

44-
For example, to run the `Deployer` feature suite in `TestKgateway`, you can run:
45+
For example, to run the `Deployer` feature suite in the `TestKgateway` test, you can run:
4546
```bash
4647
go test -v -timeout 600s ./test/kubernetes/e2e/tests -run ^TestKgateway$/^Deployer$
4748
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# this is a separate manifest so it can be applied after the Route is created
2+
apiVersion: gateway.kgateway.dev/v1alpha1
3+
kind: Backend
4+
metadata:
5+
name: nginx-static
6+
spec:
7+
type: static
8+
static:
9+
hosts:
10+
- host: nginx.default.svc # static reference to k8s service name
11+
port: 8080
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
kind: Gateway
2+
apiVersion: gateway.networking.k8s.io/v1
3+
metadata:
4+
name: gw
5+
spec:
6+
gatewayClassName: kgateway
7+
listeners:
8+
- protocol: HTTP
9+
port: 8080
10+
name: http
11+
allowedRoutes:
12+
namespaces:
13+
from: Same
14+
---
15+
apiVersion: gateway.networking.k8s.io/v1
16+
kind: HTTPRoute
17+
metadata:
18+
name: example-route
19+
spec:
20+
parentRefs:
21+
- name: gw
22+
hostnames:
23+
- "example.com"
24+
rules:
25+
- backendRefs:
26+
- name: nginx-static
27+
kind: Backend
28+
group: gateway.kgateway.dev
29+
---
30+
# create nginx Pod and Service, we will create a static Backend to refer to the nginx Service directly
31+
apiVersion: v1
32+
kind: Service
33+
metadata:
34+
name: nginx
35+
spec:
36+
selector:
37+
app.kubernetes.io/name: nginx
38+
ports:
39+
- protocol: TCP
40+
port: 8080
41+
targetPort: http-web-svc
42+
---
43+
apiVersion: v1
44+
kind: Pod
45+
metadata:
46+
name: nginx
47+
labels:
48+
app.kubernetes.io/name: nginx
49+
spec:
50+
containers:
51+
- name: nginx
52+
image: nginx:stable
53+
ports:
54+
- containerPort: 80
55+
name: http-web-svc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package backends
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"path/filepath"
7+
8+
"github.com/onsi/gomega"
9+
"github.com/stretchr/testify/suite"
10+
appsv1 "k8s.io/api/apps/v1"
11+
corev1 "k8s.io/api/core/v1"
12+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
14+
"github.com/kgateway-dev/kgateway/v2/api/v1alpha1"
15+
"github.com/kgateway-dev/kgateway/v2/pkg/utils/fsutils"
16+
"github.com/kgateway-dev/kgateway/v2/pkg/utils/kubeutils"
17+
"github.com/kgateway-dev/kgateway/v2/pkg/utils/requestutils/curl"
18+
"github.com/kgateway-dev/kgateway/v2/test/gomega/matchers"
19+
"github.com/kgateway-dev/kgateway/v2/test/kubernetes/e2e"
20+
"github.com/kgateway-dev/kgateway/v2/test/kubernetes/e2e/defaults"
21+
)
22+
23+
var _ e2e.NewSuiteFunc = NewTestingSuite
24+
25+
var (
26+
manifests = []string{
27+
filepath.Join(fsutils.MustGetThisDir(), "inputs/base.yaml"),
28+
// backend in separate manifest to allow creation independently of routing config
29+
filepath.Join(fsutils.MustGetThisDir(), "inputs/backend.yaml"),
30+
defaults.CurlPodManifest,
31+
}
32+
33+
proxyObjMeta = metav1.ObjectMeta{
34+
Name: "gw",
35+
Namespace: "default",
36+
}
37+
proxyDeployment = &appsv1.Deployment{ObjectMeta: proxyObjMeta}
38+
proxyService = &corev1.Service{ObjectMeta: proxyObjMeta}
39+
40+
backendMeta = metav1.ObjectMeta{
41+
Name: "nginx-static",
42+
Namespace: "default",
43+
}
44+
backend = &v1alpha1.Backend{
45+
ObjectMeta: backendMeta,
46+
}
47+
48+
nginxMeta = metav1.ObjectMeta{
49+
Name: "nginx",
50+
Namespace: "default",
51+
}
52+
)
53+
54+
type testingSuite struct {
55+
suite.Suite
56+
ctx context.Context
57+
testInstallation *e2e.TestInstallation
58+
}
59+
60+
func NewTestingSuite(ctx context.Context, testInst *e2e.TestInstallation) suite.TestingSuite {
61+
return &testingSuite{
62+
ctx: ctx,
63+
testInstallation: testInst,
64+
}
65+
}
66+
67+
func (s *testingSuite) TestConfigureBackingDestinationsWithUpstream() {
68+
s.T().Cleanup(func() {
69+
for _, manifest := range manifests {
70+
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, manifest)
71+
s.Require().NoError(err)
72+
}
73+
s.testInstallation.Assertions.EventuallyObjectsNotExist(s.ctx, proxyService, proxyDeployment, backend)
74+
})
75+
76+
for _, manifest := range manifests {
77+
err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, manifest)
78+
s.Require().NoError(err)
79+
}
80+
81+
// assert the expected resources are created and running before attempting to send traffic
82+
s.testInstallation.Assertions.EventuallyObjectsExist(s.ctx, proxyService, proxyDeployment, backend)
83+
// TODO: make this a specific assertion to remove the need for c/p the label selector
84+
// e.g. EventuallyCurlPodRunning(...) etc.
85+
s.testInstallation.Assertions.EventuallyPodsRunning(s.ctx, defaults.CurlPod.GetNamespace(), metav1.ListOptions{
86+
LabelSelector: "app.kubernetes.io/name=curl",
87+
})
88+
s.testInstallation.Assertions.EventuallyPodsRunning(s.ctx, nginxMeta.GetNamespace(), metav1.ListOptions{
89+
LabelSelector: "app.kubernetes.io/name=nginx",
90+
})
91+
s.testInstallation.Assertions.EventuallyPodsRunning(s.ctx, proxyObjMeta.GetNamespace(), metav1.ListOptions{
92+
LabelSelector: "app.kubernetes.io/name=gw",
93+
})
94+
95+
s.testInstallation.Assertions.AssertEventualCurlResponse(
96+
s.ctx,
97+
defaults.CurlPodExecOpt,
98+
[]curl.Option{
99+
curl.WithHost(kubeutils.ServiceFQDN(proxyService.ObjectMeta)),
100+
curl.WithHostHeader("example.com"),
101+
curl.WithPath("/"),
102+
},
103+
&matchers.HttpResponse{
104+
StatusCode: http.StatusOK,
105+
Body: gomega.ContainSubstring(defaults.NginxResponse),
106+
})
107+
}

test/kubernetes/e2e/features/discovery_watchlabels/discovery_watchlabels_suite.go

-163
This file was deleted.

0 commit comments

Comments
 (0)