Skip to content

Commit ccac7d5

Browse files
committed
ci: minimal CI changes for faster tests (kgateway-dev#13031)
Signed-off-by: John Howard <[email protected]>
1 parent 4714d45 commit ccac7d5

File tree

13 files changed

+86
-36
lines changed

13 files changed

+86
-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: 2 additions & 1 deletion
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'
@@ -105,6 +106,7 @@ jobs:
105106
kubectl-version: ${{ steps.dotenv.outputs.kubectl_version }}
106107
istio-version: ${{ steps.dotenv.outputs.istio_version }}
107108
localstack: ${{ matrix.test.localstack }}
109+
agentgateway: ${{ matrix.test.agentgateway }}
108110
- id: run-tests
109111
uses: ./.github/actions/kubernetes-e2e-tests
110112
with:
@@ -118,4 +120,3 @@ jobs:
118120
run: |
119121
echo "After job disk space:"
120122
df -h
121-
docker system df -v

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ endif
219219
endif
220220

221221
# Skip -race on e2e. This requires building the codebase twice, and provides no value as the only code executed is test code.
222-
E2E_GO_TEST_ARGS ?= -timeout=25m -cpu=4 -outputdir=$(OUTPUT_DIR)
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)
223224
# Testing flags: https://pkg.go.dev/cmd/go#hdr-Testing_flags
224225
# The default timeout for a suite is 10 minutes, but this can be overridden by setting the -timeout flag. Currently set
225226
# to 25 minutes based on the time it takes to run the longest test setup (kgateway_test).
@@ -430,15 +431,26 @@ kgateway: $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH)
430431
$(CONTROLLER_OUTPUT_DIR)/Dockerfile: cmd/kgateway/Dockerfile
431432
cp $< $@
432433

434+
$(CONTROLLER_OUTPUT_DIR)/Dockerfile.agentgateway: cmd/kgateway/Dockerfile.agentgateway
435+
cp $< $@
436+
433437
$(CONTROLLER_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH): $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH) $(CONTROLLER_OUTPUT_DIR)/Dockerfile
434438
$(BUILDX_BUILD) --load $(PLATFORM) $(CONTROLLER_OUTPUT_DIR) -f $(CONTROLLER_OUTPUT_DIR)/Dockerfile \
435439
--build-arg GOARCH=$(GOARCH) \
436440
--build-arg ENVOY_IMAGE=$(ENVOY_IMAGE) \
437441
-t $(IMAGE_REGISTRY)/$(CONTROLLER_IMAGE_REPO):$(VERSION)
438442
@touch $@
439443

444+
$(CONTROLLER_OUTPUT_DIR)/.docker-stamp-agentgateway-$(VERSION)-$(GOARCH): $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH) $(CONTROLLER_OUTPUT_DIR)/Dockerfile.agentgateway
445+
$(BUILDX_BUILD) --load $(PLATFORM) $(CONTROLLER_OUTPUT_DIR) -f $(CONTROLLER_OUTPUT_DIR)/Dockerfile.agentgateway \
446+
--build-arg GOARCH=$(GOARCH) \
447+
-t $(IMAGE_REGISTRY)/$(CONTROLLER_IMAGE_REPO):$(VERSION)
448+
@touch $@
449+
440450
.PHONY: kgateway-docker
441451
kgateway-docker: $(CONTROLLER_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH)
452+
.PHONY: kgateway-agentgateway-docker
453+
kgateway-agentgateway-docker: $(CONTROLLER_OUTPUT_DIR)/.docker-stamp-agentgateway-$(VERSION)-$(GOARCH)
442454

443455
#----------------------------------------------------------------------------------
444456
# SDS Server - gRPC server for serving Secret Discovery Service config
@@ -717,6 +729,7 @@ kind-load-%:
717729
# Depends on: IMAGE_REGISTRY, VERSION, CLUSTER_NAME
718730
# Envoy image may be specified via ENVOY_IMAGE on the command line or at the top of this file
719731
kind-build-and-load-%: %-docker kind-load-% ; ## Use to build specified image and load it into kind
732+
kind-build-and-load-kgateway-agentgateway: kgateway-agentgateway-docker kind-load-kgateway ; ## Use to build specified image and load it into kind
720733

721734
# Update the docker image used by a deployment
722735
# 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+
testutils.Cleanup(t, 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/istio.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func downloadIstio(version string) (string, error) {
198198

199199
func UninstallIstio(istioctlBinary, kubeContext string) error {
200200
// sh -c yes | istioctl uninstall —purge —context <kube-context>
201-
cmd := exec.Command("sh", "-c", fmt.Sprintf("yes | %s uninstall --purge --context %s", istioctlBinary, kubeContext)) //nolint:gosec // G204: controlled istioctl uninstall command in tests
201+
cmd := exec.Command("sh", "-c", fmt.Sprintf("yes | %s uninstall --purge --context '%s'", istioctlBinary, kubeContext)) //nolint:gosec // G204: controlled istioctl uninstall command in tests
202202
cmd.Stdout = os.Stdout
203203
cmd.Stderr = os.Stderr
204204
if err := cmd.Run(); err != nil {

0 commit comments

Comments
 (0)