Skip to content

Conversation

@camilamacedo86
Copy link
Member

@camilamacedo86 camilamacedo86 commented Jan 3, 2026

E2E tests now support optional context locking via KUBE_CONTEXT environment
variable. When set, tests validate and lock to the specified kubectl context,
preventing context switching during execution.

Features:

  • Display current kubectl context at test startup
  • Validate context matches KUBE_CONTEXT if set
  • Add --context flag to all kubectl commands when locked
  • 100% backward compatible (opt-in feature)

Usage:
KUBE_CONTEXT=kind-test make test-e2e

This addresses feedback from PR #5329 about preventing inadvertent context
switching during test execution, while maintaining ease of use (works without
any env vars by default).

Closes: #5335

Co-Author: @Sijoma

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 3, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 3, 2026
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 3, 2026
@camilamacedo86 camilamacedo86 reopened this Jan 3, 2026
@camilamacedo86 camilamacedo86 force-pushed the add-e2e-context branch 2 times, most recently from e664caa to c8fa24a Compare January 3, 2026 21:09
@camilamacedo86 camilamacedo86 changed the title WIP: Add e2e context ✨ (go/v4): Add optional kubectl context locking for e2e tests Jan 3, 2026
@camilamacedo86 camilamacedo86 marked this pull request as ready for review January 3, 2026 21:10
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 3, 2026
@k8s-ci-robot k8s-ci-robot requested a review from Kavinjsir January 3, 2026 21:11
@camilamacedo86
Copy link
Member Author

@mandarjog could you please give a look on this one?
That is what I see we can do.

E2E tests now support optional context locking via KUBE_CONTEXT environment
variable. When set, tests validate and lock to the specified kubectl context,
preventing context switching during execution.

Features:
- Display current kubectl context at test startup
- Validate context matches KUBE_CONTEXT if set
- Add --context flag to all kubectl commands when locked
- 100% backward compatible (opt-in feature)

Usage:
  KUBE_CONTEXT=kind-test make test-e2e

This addresses feedback from PR kubernetes-sigs#5329 about preventing inadvertent context
switching during test execution, while maintaining ease of use (works without
any env vars by default).

Assisted-by: Cursor
@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-34-0

Copy link
Contributor

@vitorfloriano vitorfloriano left a comment

Choose a reason for hiding this comment

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

Doesn't kubectl validate available contexts based on kubeconfig?

I mean, if we only pass KUBE_CONTEXT to the --context flag in the command without setting this new context first in kubeconfig using kubectl config set-context first, wouldn't that cause an error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

e2e: Require explicit kubeconfig context and default to kind-only for safety

3 participants