Skip to content

Migrate kind e2e tests from bash_unit to Ginkgo - #2513

Merged
thomasferrandiz merged 10 commits into
masterfrom
thomasferrandiz-ginkgo-e2e-migration
Aug 11, 2026
Merged

thomasferrandiz merged 10 commits into
masterfrom
thomasferrandiz-ginkgo-e2e-migration

Conversation

@thomasferrandiz

Copy link
Copy Markdown
Contributor

Description

This is a test-infrastructure change (no product code). It replaces the bash_unit-driven kind e2e suite (e2e/run-e2e-tests.sh and its helpers) with a native Ginkgo v2 + Gomega suite written in Go.

Why: the previous suite was a large, hard-to-maintain bash script that shelled out to kubectl, kind, yq and jq, with ad hoc polling and string assertions. Moving it to Go lets us drive the cluster and Kubernetes through first-class libraries, reuse the module toolchain, and get structured, readable specs and failure output.

Approach:

  • New e2e/ Go package gated behind the e2e build tag, so it never runs during make unit-test.
  • Cluster lifecycle uses the sigs.k8s.io/kind library (create, load images via docker save -> node import, delete, and node exec for rule inspection). kind is now a library dependency rather than a CLI tool.
  • Kubernetes operations use client-go (pod create, IPs, podCIDR, remotecommand exec, logs) and all readiness waits (DaemonSet rollout, nodes, coredns, pods, ping reachability, and /run/flannel/subnet.env on each node).
  • The flannel manifest is rendered from Documentation/kube-flannel.yml as a template (image, net-conf.json, udp privileged flag) and applied/deleted via the dynamic client, replacing the yq + kubectl flow.
  • Ports the full prior coverage: per-backend connectivity ping tests, iperf3 perf tests, iptables/nftables golden-rule assertions, and the on-failure debug dump.

Scope note: only the kind suite is migrated. The etcd/docker dist/functional-test*.sh suites intentionally stay on bash_unit.

Components affected: e2e test suite, make kind-e2e-test, and the kind-e2eTests GitHub Actions workflow (drops the kind CLI install since the library handles clusters now). Removes 5 obsolete bash scripts and keeps e2e/kind-config.yaml.

Testing: go vet -tags e2e ./e2e/ is clean, the test binary compiles, gofmt is clean, and go mod tidy is stable. A --ginkgo.dry-run enumerates 11 specs (6 connectivity + 5 perf), matching the original coverage (udp and its perf variant remain amd64-only). The full run exercises real kind clusters and is covered by the kind-e2eTests workflow on CI.

Todos

  • Tests
  • Documentation
  • Release note

Release Note

None required

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the kind-based end-to-end test suite from a bash_unit + kubectl/kind CLI flow to a native Go test suite using Ginkgo v2 + Gomega, client-go, and the sigs.k8s.io/kind library. This modernizes the kind e2e infrastructure while keeping the etcd/docker bash_unit suites unchanged.

Changes:

  • Replaces e2e/run-e2e-tests.sh and helper scripts with a Go e2e/ package gated behind the e2e build tag.
  • Updates make kind-e2e-test to run go test -tags e2e ./... and adjusts CI workflow setup accordingly.
  • Adds Go module dependencies for Ginkgo/Gomega and kind.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
Makefile Runs kind e2e via go test -tags e2e instead of bash_unit scripts
go.mod Adds Ginkgo/Gomega and kind (plus new indirect deps)
go.sum Updates checksums for newly added dependencies
e2e/version.sh Removes legacy bash tag/arch env setup
e2e/run-e2e-tests.sh Removes legacy bash-driven kind e2e runner
e2e/get-kubeconfig.sh Removes kubeconfig export helper (kind library now used)
e2e/e2e-functions.sh Removes bash polling/helpers (replaced by Go waits)
e2e/download-kubectl.sh Removes kubectl installer (no longer needed for suite)
e2e/e2e_suite_test.go Adds Ginkgo suite bootstrap + env configuration + CNI plugin install
e2e/connectivity_test.go Adds backend connectivity + perf specs in Ginkgo
e2e/cluster.go Adds kind cluster lifecycle, image loading, node exec, CNI plugin install
e2e/kube.go Adds client-go helpers (pods, exec, readiness waits, subnet.env check)
e2e/flannel.go Adds manifest rendering/apply/delete via dynamic client
e2e/rules.go Adds iptables/nftables golden-rule assertions + debug dump
CLAUDE.md Updates repo docs describing the new kind e2e approach
.github/workflows/kind-e2eTests.yml Removes kind CLI install step; relies on Go-based suite

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread e2e/flannel.go Resolved
Comment thread e2e/flannel.go Resolved
Comment thread e2e/flannel.go Resolved
Comment thread e2e/cluster.go Resolved
Comment thread e2e/cluster.go Resolved
Comment thread e2e/cluster.go Resolved
Comment thread e2e/rules.go Resolved
@manuelbuil

Copy link
Copy Markdown
Collaborator

Could we do a follow-up to separate framework/helpers from specs for maintainability? Or maybe in this PR itself? The same directory includes helper-functions (e.g. in cluster.go) and the tests themselves. I would prefer having two different subdirectories: one for infrahelpers and one for tests

@thomasferrandiz

Copy link
Copy Markdown
Contributor Author

I agree the separation can help once the suite grows, but in Go the current boundary is already the idiomatic one: helpers live in non-_test.go files and specs in _test.go files within the same package. Moving them into subdirectories here would mean a separate package and a fairly noisy export/refactor of the helper surface, so I would prefer to keep this PR as-is and revisit that as a follow-up if the e2e suite grows enough to justify it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (5)

e2e/kube.go:189

  • waitForNodesReady ignores List errors and keeps polling, which can turn real API failures into opaque timeouts. Propagate the error so the spec fails with the underlying cause.
		nodeList, err := kc.client.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
		if err != nil {
			return false, nil
		}

e2e/kube.go:210

  • waitForCoreDNS collapses list errors into "not ready" and keeps polling, which can mask API failures behind a timeout. Return the error when the List call fails (still treat an empty list as "not ready").
		pods, err := kc.client.CoreV1().Pods("kube-system").List(ctx, metav1.ListOptions{
			LabelSelector: "k8s-app=kube-dns",
		})
		if err != nil || len(pods.Items) == 0 {
			return false, nil
		}

e2e/connectivity_test.go:91

  • Flannel is only deleted at the end of each spec. If any Expect fails before that (e.g., ping/iperf), the suite can proceed with flannel still installed, and later backends may run against the previous net-conf.json because updating the ConfigMap alone doesn’t force a DaemonSet restart. Add a DeferCleanup right after a successful install so flannel is always removed, even on failure.
	By("installing flannel with backend " + backend)
	Expect(kc.installFlannel(ctx, backend, enableNFT)).To(Succeed())

	By("waiting for the flannel DaemonSet to roll out")
	Expect(kc.waitForFlannelRollout(ctx, 5*time.Minute)).To(Succeed())

e2e/kube.go:170

  • waitForPodReady currently swallows all GET errors and keeps polling. If the error is persistent (e.g., auth/connection), the test will just time out with no root cause. Only ignore NotFound; return other errors so failures are actionable.

This issue also appears in the following locations of the same file:

  • line 186
  • line 205
		pod, err := kc.client.CoreV1().Pods(namespace).Get(ctx, name, metav1.GetOptions{})
		if err != nil {
			return false, nil
		}

e2e/cluster.go:175

  • loadImage writes potentially very large image tarballs into the current working directory (".") during tests. Using the system temp directory avoids filling the repo workspace and is more robust in environments where the checkout may be on a small/slow filesystem.
	tmp, err := os.CreateTemp(".", "kind-image-*.tar")

@thomasferrandiz
thomasferrandiz force-pushed the thomasferrandiz-ginkgo-e2e-migration branch from f50d73a to 8e52808 Compare July 31, 2026 10:29
thomasferrandiz and others added 10 commits August 7, 2026 13:00
Replace the bash_unit-driven kind e2e suite (e2e/run-e2e-tests.sh) with a
native Ginkgo v2 + Gomega suite under e2e/ (build tag `e2e`). The suite drives
cluster lifecycle through the sigs.k8s.io/kind library and Kubernetes through
client-go, exec-ing into kind node containers for iptables/nftables assertions.

- Per-backend kind cluster (Ordered containers) for vxlan, vxlan-nftables,
  wireguard, host-gw, ipip and udp (udp/perf gated to amd64).
- Flannel manifest rendered from Documentation/kube-flannel.yml as a template
  (image, net-conf.json, udp privileged) and applied via the dynamic client.
- Ports connectivity ping tests, iperf3 perf tests, iptables/nftables golden
  rule checks and the failure debug dump.
- Rewrites `make kind-e2e-test` to `go test -tags e2e ./e2e/...` and updates
  the kind-e2eTests workflow (kind is now a library, not a CLI dependency).
- Removes the obsolete bash scripts and updates CLAUDE.md.

The dist/functional-test*.sh (etcd/docker) suites remain on bash_unit.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add required license headers to the new e2e Go files and wait for flannel resources to be fully deleted before reinstalling them between ordered specs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reduce duplication in the Ginkgo e2e suite while keeping the same 11 specs:

- Derive the iptables/nftables rule check from the backend's EnableNFTables
  flag instead of carrying a per-backend closure, removing the checkRules
  struct field and six near-identical closures.
- Extract a dynamicResource helper for namespaced vs cluster-scoped resource
  clients, replacing three copies of the same if/else in install, delete and
  the deletion wait.
- Extract nodeCIDRs so checkIptables and checkNftables share the pod-CIDR
  lookup loop.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…dumpDebugInfo)

- downloadFile: use http.Client with 5-minute timeout instead of http.Get
- loadImage: write docker save output to a temp file instead of buffering
  the entire archive in memory; avoids OOM for large images
- dumpDebugInfo: expand to include all pod status, flannel pod describe,
  previous container logs, crictl images on nodes, and cluster events

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The bash suite created a single cluster (setup/teardown) and ran all
backends sequentially within it. The Ginkgo migration accidentally
created one cluster per backend (6 total), multiplying cluster create
and delete time by 6x.

Restore parity: create the cluster once in BeforeSuite, delete it in
AfterSuite, and share it across all backend Contexts. Add deleteTestPods
called at the start of each prepareTest to clean up pods left over from
the previous backend so the shared cluster starts clean for each spec.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reduce duplication in the Ginkgo e2e suite while keeping the same 11 specs:

- Derive the iptables/nftables rule check from the backend's EnableNFTables
  flag instead of carrying a per-backend closure, removing the checkRules
  struct field and six near-identical closures.
- Extract a dynamicResource helper for namespaced vs cluster-scoped resource
  clients, replacing three copies of the same if/else in install, delete and
  the deletion wait.
- Extract nodeCIDRs so checkIptables and checkNftables share the pod-CIDR
  lookup loop.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The bash suite created a single cluster (setup/teardown) and ran all
backends sequentially within it. The Ginkgo migration accidentally
created one cluster per backend (6 total), multiplying cluster create
and delete time by 6x.

Restore parity: create the cluster once in BeforeSuite, delete it in
AfterSuite, and share it across all backend Contexts. Add deleteTestPods
called at the start of each prepareTest to clean up pods left over from
the previous backend so the shared cluster starts clean for each spec.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@thomasferrandiz
thomasferrandiz force-pushed the thomasferrandiz-ginkgo-e2e-migration branch from 2f92347 to a6bec47 Compare August 7, 2026 11:03
@thomasferrandiz
thomasferrandiz merged commit 793cbe5 into master Aug 11, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants