Skip to content

Migrate Helm e2e tests to terratest v2 modules - #1356

Merged
antoninbas merged 1 commit into
antrea-io:mainfrom
antoninbas:terratest-v2-drop-aws-sdk
Aug 15, 2026
Merged

Migrate Helm e2e tests to terratest v2 modules#1356
antoninbas merged 1 commit into
antrea-io:mainfrom
antoninbas:terratest-v2-drop-aws-sdk

Conversation

@antoninbas

Copy link
Copy Markdown
Contributor

Closes #1290, which bumped terratest to v1. This goes further and moves us to the v2 modules instead.

Why

terratest v1 ships as a single Go module, and modules/k8s imported modules/aws for a single EC2 call (resolving EKS node public IPs in GetServiceEndpoint). modules/aws is one flat package covering every AWS service, so importing modules/k8s pulled the whole AWS SDK into our graph:

antrea.io/antrea-ui/test/e2e_helm
github.com/gruntwork-io/terratest/modules/k8s
github.com/gruntwork-io/terratest/modules/aws
github.com/aws/aws-sdk-go-v2/aws

That was 36 aws-sdk-go-v2 entries in go.mod for code we never call.

Upstream fixed this: gruntwork-io/terratest#1877 broke the k8s -> aws edge (node addresses now prefer ExternalIP, so there is no EC2 call and no ec2:DescribeInstances permission needed), and #1881 added CI gating so the edge cannot come back. v2 also splits terratest into 16 per-package modules, so we only pull what we use.

Result

before after
aws-sdk-go-v2 entries in go.mod 36 0
go.sum lines 470 375

Changes

  • Import paths move to the v2 modules: k8s/v2, helm/v2, http-helper -> httphelper/v2 (the package identifier loses its underscore), and random -> core/v2/random.
  • v2 dropped the non-Context function variants, so the helm and k8s calls become their …Context equivalents with an explicit ctx.
  • httphelper collapsed the URL and TLS parameters into an HttpGetOptions struct.
  • random.UniqueId -> random.UniqueID.
  • Pre-existing bug fix: the first two arguments to k8s.NewKubectlOptions were swapped. The signature is NewKubectlOptions(contextName, configPath, namespace), but we passed (kubeconfigPath, kubeconfigContext, ...), so -kubeconfig and -context were wired to the wrong fields. This is not migration fallout — the signature is identical in v1 and v2. It went unnoticed because both flags default to the empty string.

In the t.Cleanup that deletes the OIDC Secret I pass context.Background() rather than t.Context(), because t.Context() is canceled just before Cleanup functions run and the delete would fail. The plain defer blocks inside the subtest still run before the test function returns, so t.Context() is valid there.

Note on the beta

v2.0.0-beta.2 is a pre-release. I think that is acceptable here: terratest is a test-only dependency that never reaches a shipped binary, and the alternative is carrying the AWS SDK until v2 is final. Worth flagging explicitly for review, though — and Renovate will not track these the way it tracked v1.

Testing

go build ./..., go vet ./..., go test -c ./test/e2e_helm/ and golangci-lint all pass locally. The e2e suite itself needs a live cluster, so I have not run it — relying on CI for that.

terratest v1 ships as a single module, and modules/k8s imported
modules/aws for one EC2 call, which pulled the entire AWS SDK into our
dependency graph: 36 aws-sdk-go-v2 entries in go.mod for code we never
call. terratest v2 splits the repo into per-package modules and drops
that edge, so depending on k8s no longer drags in the AWS SDK.

Switch the Helm e2e test to the v2 modules (k8s, helm, httphelper and
core/random) at v2.0.0-beta.2. This is a pre-release, which is
acceptable here because terratest is a test-only dependency that never
reaches a shipped binary.

The v2 API required a few call-site updates: the non-Context function
variants are gone, http-helper takes an options struct, and UniqueId
was renamed to UniqueID. In the Cleanup deleting the OIDC Secret we
pass context.Background(), since t.Context() is canceled just before
Cleanup functions run.

Also fix a pre-existing bug: the first two arguments to
NewKubectlOptions were swapped, so -kubeconfig and -context were wired
to the wrong fields. It went unnoticed because both flags default to
the empty string.

go.sum drops from 470 to 375 lines.

Supersedes antrea-io#1290.

Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
@antoninbas
antoninbas merged commit 254fff8 into antrea-io:main Aug 15, 2026
11 checks passed
@antoninbas
antoninbas deleted the terratest-v2-drop-aws-sdk branch August 15, 2026 05:30
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.

1 participant