Skip to content

Commit 2626c40

Browse files
committed
ci: minimal CI changes for faster tests
Signed-off-by: John Howard <[email protected]>
1 parent a7aaaa0 commit 2626c40

File tree

12 files changed

+89
-36
lines changed

12 files changed

+89
-36
lines changed

.github/actions/kubernetes-e2e-tests/action.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ runs:
3030
CLUSTER_NAME: ${{ inputs.cluster-name }}
3131
ISTIO_VERSION: ${{ inputs.istio-version }}
3232
TEST_PKG: ./test/e2e/tests
33+
# Doesn't really matter, but using the same as `go build` means we can re-use the same Go cache.
34+
CGO_ENABLED: 0
3335
shell: bash
3436
run: make e2e-test
3537
- name: Archive bug report directory on failure

.github/actions/prep-go-runner/action.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ runs:
2323
docker system df -v
2424
2525
# https://github.com/actions/runner-images/discussions/3242 github runners are bad at cleanup
26-
echo "Removing large packages"
27-
time sudo apt-get remove -y '^dotnet-.*' '^llvm-.*' 'php.*' '^mongodb-.*' '^mysql-.*' azure-cli google-chrome-stable \
28-
firefox powershell mono-devel libgl1-mesa-dri || true
29-
time sudo apt-get autoremove -y || true
30-
time sudo apt-get clean -y || true
31-
echo "Done removing large packages"
32-
df -h
3326
3427
# Clean up pre-installed tools
3528
# For some reason, GHA often takes minutes (up to 20min observed) to clean up somehow.
@@ -85,4 +78,4 @@ runs:
8578
- name: Install Dependencies
8679
if: steps.cache.outputs.cache-hit != 'true'
8780
shell: bash
88-
run: make mod-download
81+
run: time make mod-download

.github/actions/setup-kind-cluster/action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ inputs:
2727
required: false
2828
default: "false"
2929
description: Whether to install localstack
30+
agentgateway:
31+
required: false
32+
default: "false"
33+
description: Whether this test only needs agentgateway
3034

3135
runs:
3236
using: "composite"
@@ -44,6 +48,7 @@ runs:
4448
CONFORMANCE_VERSION: ${{ inputs.gateway-api-version }}
4549
CONFORMANCE_CHANNEL: ${{ inputs.gateway-api-channel }}
4650
LOCALSTACK: ${{ inputs.localstack }}
51+
AGENTGATEWAY: ${{ inputs.agentgateway }}
4752
CONFORMANCE: true
4853
run: |
4954
./hack/kind/setup-kind.sh

.github/workflows/e2e.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ jobs:
7575
- cluster-name: 'agent-gateway-cluster'
7676
go-test-args: '-timeout=25m'
7777
go-test-run-regex: '^TestAgentgatewayIntegration'
78+
agentgateway: 'true'
7879
# August 29, 2025: ~3 minutes
7980
- cluster-name: 'api-validation'
8081
go-test-args: '-timeout=10m'

Makefile

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,10 @@ test: ## Run all tests with ginkgo, or only run the test package at {TEST_PKG} i
180180
# will still have e2e tests run by Github Actions once they publish a pull
181181
# request.
182182
.PHONY: e2e-test
183+
e2e-test: go-test
184+
e2e-test: TEST_TAG = e2e
185+
e2e-test: GO_TEST_ARGS = $(E2E_GO_TEST_ARGS)
183186
e2e-test: dummy-idp-docker dummy-auth0-docker kind-load-dummy-idp kind-load-dummy-auth0
184-
e2e-test: ## Run only e2e tests, and only run the test package at {TEST_PKG} if it is specified
185-
@$(MAKE) --no-print-directory go-test TEST_TAG=e2e TEST_PKG=$(TEST_PKG)
186187

187188

188189
# https://go.dev/blog/cover#heat-maps
@@ -217,10 +218,13 @@ ifeq ($(GOARCH), arm64)
217218
endif
218219
endif
219220

221+
# Skip -race on e2e. This requires building the codebase twice, and provides no value as the only code executed is test code.
222+
# Skip -vet; we already run it on the linter step and its very slow.
223+
E2E_GO_TEST_ARGS ?= -vet=off -timeout=25m -outputdir=$(OUTPUT_DIR)
220224
# Testing flags: https://pkg.go.dev/cmd/go#hdr-Testing_flags
221225
# The default timeout for a suite is 10 minutes, but this can be overridden by setting the -timeout flag. Currently set
222226
# to 25 minutes based on the time it takes to run the longest test setup (kgateway_test).
223-
GO_TEST_ARGS ?= -timeout=25m -cpu=4 -race -outputdir=$(OUTPUT_DIR)
227+
GO_TEST_ARGS ?= $(E2E_GO_TEST_ARGS) -race
224228
GO_TEST_COVERAGE_ARGS ?= --cover --covermode=atomic --coverprofile=cover.out
225229
GO_TEST_COVERAGE ?= go tool github.com/vladopajic/go-test-coverage/v2
226230

@@ -429,15 +433,26 @@ kgateway: $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH)
429433
$(CONTROLLER_OUTPUT_DIR)/Dockerfile: cmd/kgateway/Dockerfile
430434
cp $< $@
431435

436+
$(CONTROLLER_OUTPUT_DIR)/Dockerfile.agentgateway: cmd/kgateway/Dockerfile.agentgateway
437+
cp $< $@
438+
432439
$(CONTROLLER_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH): $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH) $(CONTROLLER_OUTPUT_DIR)/Dockerfile
433440
$(BUILDX_BUILD) --load $(PLATFORM) $(CONTROLLER_OUTPUT_DIR) -f $(CONTROLLER_OUTPUT_DIR)/Dockerfile \
434441
--build-arg GOARCH=$(GOARCH) \
435442
--build-arg ENVOY_IMAGE=$(ENVOY_IMAGE) \
436443
-t $(IMAGE_REGISTRY)/$(CONTROLLER_IMAGE_REPO):$(VERSION)
437444
@touch $@
438445

446+
$(CONTROLLER_OUTPUT_DIR)/.docker-stamp-agentgateway-$(VERSION)-$(GOARCH): $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH) $(CONTROLLER_OUTPUT_DIR)/Dockerfile.agentgateway
447+
$(BUILDX_BUILD) --load $(PLATFORM) $(CONTROLLER_OUTPUT_DIR) -f $(CONTROLLER_OUTPUT_DIR)/Dockerfile.agentgateway \
448+
--build-arg GOARCH=$(GOARCH) \
449+
-t $(IMAGE_REGISTRY)/$(CONTROLLER_IMAGE_REPO):$(VERSION)
450+
@touch $@
451+
439452
.PHONY: kgateway-docker
440453
kgateway-docker: $(CONTROLLER_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH)
454+
.PHONY: kgateway-agentgateway-docker
455+
kgateway-agentgateway-docker: $(CONTROLLER_OUTPUT_DIR)/.docker-stamp-agentgateway-$(VERSION)-$(GOARCH)
441456

442457
#----------------------------------------------------------------------------------
443458
# SDS Server - gRPC server for serving Secret Discovery Service config
@@ -716,6 +731,7 @@ kind-load-%:
716731
# Depends on: IMAGE_REGISTRY, VERSION, CLUSTER_NAME
717732
# Envoy image may be specified via ENVOY_IMAGE on the command line or at the top of this file
718733
kind-build-and-load-%: %-docker kind-load-% ; ## Use to build specified image and load it into kind
734+
kind-build-and-load-kgateway-agentgateway: kgateway-agentgateway-docker kind-load-kgateway ; ## Use to build specified image and load it into kind
719735

720736
# Update the docker image used by a deployment
721737
# This works for most of our deployments because the deployment name and container name both match
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM cgr.dev/chainguard/static
2+
3+
ARG GOARCH=amd64
4+
5+
COPY kgateway-linux-$GOARCH /usr/local/bin/kgateway
6+
7+
USER 10101
8+
9+
ENTRYPOINT ["/usr/local/bin/kgateway"]

hack/kind/setup-kind.sh

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,43 @@ function create_kind_cluster_or_skip() {
5656
fi
5757
}
5858

59+
function create_and_setup() {
60+
create_kind_cluster_or_skip
61+
62+
# 5. Apply the Kubernetes Gateway API CRDs
63+
kubectl apply --server-side -f "https://github.com/kubernetes-sigs/gateway-api/releases/download/$CONFORMANCE_VERSION/$CONFORMANCE_CHANNEL-install.yaml"
64+
65+
# 6. Apply the Kubernetes Gateway API Inference Extension CRDs
66+
kubectl apply --kustomize "https://github.com/kubernetes-sigs/gateway-api-inference-extension/config/crd?ref=$GIE_CRD_VERSION"
67+
68+
. $SCRIPT_DIR/setup-metalllb-on-kind.sh
69+
}
70+
5971
# 1. Create a kind cluster (or skip creation if a cluster with name=CLUSTER_NAME already exists)
6072
# This config is roughly based on: https://kind.sigs.k8s.io/docs/user/ingress/
61-
create_kind_cluster_or_skip
73+
create_and_setup &
74+
KIND_PID=$!
6275

6376
if [[ $SKIP_DOCKER == 'true' ]]; then
6477
# TODO(tim): refactor the Makefile & CI scripts so we're loading local
6578
# charts to real helm repos, and then we can remove this block.
6679
echo "SKIP_DOCKER=true, not building images or chart"
6780
else
6881
# 2. Make all the docker images and load them to the kind cluster
69-
VERSION=$VERSION CLUSTER_NAME=$CLUSTER_NAME make kind-build-and-load
82+
if [[ $AGENTGATEWAY == 'true' ]]; then
83+
# Skip expensive envoy build
84+
VERSION=$VERSION CLUSTER_NAME=$CLUSTER_NAME make kind-build-and-load-kgateway-agentgateway
85+
else
86+
VERSION=$VERSION CLUSTER_NAME=$CLUSTER_NAME make kind-build-and-load
87+
fi
7088

7189
# 3. Build the test helm chart, ensuring we have a chart in the `_test` folder
7290
VERSION=$VERSION make package-kgateway-charts
73-
7491
fi
7592

76-
# 5. Apply the Kubernetes Gateway API CRDs
77-
kubectl apply --server-side -f "https://github.com/kubernetes-sigs/gateway-api/releases/download/$CONFORMANCE_VERSION/$CONFORMANCE_CHANNEL-install.yaml"
78-
79-
# 6. Apply the Kubernetes Gateway API Inference Extension CRDs
80-
kubectl apply --kustomize "https://github.com/kubernetes-sigs/gateway-api-inference-extension/config/crd?ref=$GIE_CRD_VERSION"
81-
82-
# 7. Conformance test setup
83-
if [[ $CONFORMANCE == "true" ]]; then
84-
echo "Running conformance test setup"
85-
. $SCRIPT_DIR/setup-metalllb-on-kind.sh
86-
fi
93+
wait "$KIND_PID"
8794

88-
# 9. Setup localstack
95+
# 7. Setup localstack
8996
if [[ $LOCALSTACK == "true" ]]; then
9097
echo "Setting up localstack"
9198
. $SCRIPT_DIR/setup-localstack.sh

test/e2e/test.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import (
99
"io/fs"
1010
"os"
1111
"path/filepath"
12-
"runtime"
1312
"testing"
1413

14+
corev1 "k8s.io/api/core/v1"
15+
"k8s.io/apimachinery/pkg/labels"
16+
"sigs.k8s.io/controller-runtime/pkg/client"
17+
1518
"github.com/kgateway-dev/kgateway/v2/pkg/utils/helmutils"
1619
"github.com/kgateway-dev/kgateway/v2/test/e2e/testutils/actions"
1720
"github.com/kgateway-dev/kgateway/v2/test/e2e/testutils/assertions"
@@ -78,7 +81,9 @@ func CreateTestInstallationForCluster(
7881
// between TestInstallation outputs per CI run
7982
GeneratedFiles: MustGeneratedFiles(installContext.InstallNamespace, clusterContext.Name),
8083
}
81-
runtime.SetFinalizer(installation, func(i *TestInstallation) { i.finalize() })
84+
t.Cleanup(func() {
85+
installation.finalize()
86+
})
8287
return installation
8388
}
8489

@@ -159,7 +164,7 @@ func (i *TestInstallation) InstallKgatewayCRDsFromLocalChart(ctx context.Context
159164

160165
// Check if we should skip installation if the release already exists (PERSIST_INSTALL or FAIL_FAST_AND_PERSIST mode)
161166
if testutils.ShouldPersistInstall() || testutils.ShouldFailFastAndPersist() {
162-
if i.Actions.Helm().ReleaseExists(ctx, helmutils.CRDChartName, i.Metadata.InstallNamespace) {
167+
if i.releaseExists(ctx, helmutils.CRDChartName, i.Metadata.InstallNamespace) {
163168
return
164169
}
165170
}
@@ -185,7 +190,7 @@ func (i *TestInstallation) InstallKgatewayCoreFromLocalChart(ctx context.Context
185190

186191
// Check if we should skip installation if the release already exists (PERSIST_INSTALL or FAIL_FAST_AND_PERSIST mode)
187192
if testutils.ShouldPersistInstall() || testutils.ShouldFailFastAndPersist() {
188-
if i.Actions.Helm().ReleaseExists(ctx, helmutils.ChartName, i.Metadata.InstallNamespace) {
193+
if i.releaseExists(ctx, helmutils.ChartName, i.Metadata.InstallNamespace) {
189194
return
190195
}
191196
}
@@ -309,3 +314,16 @@ func MustGeneratedFiles(tmpDirId, clusterId string) GeneratedFiles {
309314
FailureDir: failureDir,
310315
}
311316
}
317+
func (i *TestInstallation) releaseExists(ctx context.Context, releaseName, namespace string) bool {
318+
l := &corev1.SecretList{}
319+
if err := i.ClusterContext.Client.List(ctx, l, &client.ListOptions{
320+
Namespace: namespace,
321+
LabelSelector: labels.SelectorFromSet(map[string]string{
322+
"owner": "helm",
323+
"name": releaseName,
324+
}),
325+
}); err != nil {
326+
return false
327+
}
328+
return len(l.Items) > 0
329+
}

test/e2e/tests/base/base_suite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func (s *BaseTestingSuite) ApplyManifests(testCase *TestCase) {
443443
s.TestInstallation.Assertions.EventuallyPodsRunning(s.Ctx, ns, metav1.ListOptions{
444444
LabelSelector: fmt.Sprintf("%s=%s", defaults.WellKnownAppLabel, name),
445445
// Provide a longer timeout as the pod needs to be pulled and pass HCs
446-
}, time.Second*60, time.Second*2)
446+
}, time.Second*60, time.Second)
447447
}
448448
}
449449

test/e2e/testutils/cluster/kind.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package cluster
44

55
import (
6-
"fmt"
76
"os"
87

98
"k8s.io/apimachinery/pkg/runtime"
@@ -31,10 +30,6 @@ func MustKindContextWithScheme(clusterName string, scheme *runtime.Scheme) *Cont
3130
}
3231

3332
kubeCtx := os.Getenv(testutils.KubeCtx)
34-
if len(kubeCtx) == 0 {
35-
kubeCtx = fmt.Sprintf("kind-%s", clusterName)
36-
}
37-
3833
restCfg, err := kubeutils.GetRestConfigWithKubeContext(kubeCtx)
3934
if err != nil {
4035
panic(err)

0 commit comments

Comments
 (0)