Skip to content

Confine kind setup and e2e tests to the kind context#1807

Open
danielorbach wants to merge 3 commits intokagent-dev:mainfrom
danielorbach:fix/pin-kind-tooling-context
Open

Confine kind setup and e2e tests to the kind context#1807
danielorbach wants to merge 3 commits intokagent-dev:mainfrom
danielorbach:fix/pin-kind-tooling-context

Conversation

@danielorbach
Copy link
Copy Markdown

A stray kubectl config current-context was enough to make make create-kind-cluster, make use-kind-cluster, make kagent-addon-install, and make -C go e2e mutate whichever cluster was active. None of those targets read like "may rewrite an arbitrary cluster," yet that is what they did. Resolves #1806.

scripts/kind/setup-{kind,metallb}.sh now pin every kubectl invocation to --context "kind-${KIND_CLUSTER_NAME}". The Makefile targets use-kind-cluster, kagent-cli-port-forward, kagent-ui-port-forward, and the istioctl install line inside kagent-addon-install get the same treatment; use-kind-cluster no longer touches --current and instead sets the namespace on the kind context by name, so any other context the user has is left untouched. go/Makefile's e2e target materializes the kind cluster's kubeconfig to a temp file and runs go test with KUBECONFIG forced to it — both controller-runtime's config.GetConfig() and the bare exec.Command("kubectl", ...) calls inside the test code now have no path to a remote cluster. The target aborts early with a clear message if the kind cluster is missing.

The same --kube-context kind-$(KIND_CLUSTER_NAME) discipline already applied to helm-install*, helm-uninstall, push-test-agent, and the kubectl apply lines inside kagent-addon-install; this brings the rest of the developer tooling to the same baseline.

Verification

bash -n parses both kind scripts. make -n use-kind-cluster, make -n kagent-addon-install, make -n kagent-cli-port-forward, make -n kagent-ui-port-forward, and make -C go -n e2e all expand with --context kind-kagent (or KUBECONFIG=/tmp/kind-config-e2e) on every state-mutating line.

Out of scope

The Go test code itself still calls kubectl and controller-runtime without an explicit context; the safety here is provided by the wrapping make e2e target setting KUBECONFIG. Anyone running go test ./go/core/test/e2e directly is still responsible for setting KUBECONFIG themselves.

setup-kind.sh and setup-metallb.sh used `kubectl apply` (and rollout/wait)
without `--context`, so they targeted whatever the active kubeconfig
context happened to be. Running `make create-kind-cluster` while pointed
at a remote cluster would silently push the local-registry-hosting
ConfigMap and the entire MetalLB stack onto that cluster.

Pin both scripts to `kind-${KIND_CLUSTER_NAME}` so they only ever touch
the kind cluster they are setting up.
Several Make targets ran kubectl/istioctl against the active kubeconfig
context with no `--context` flag:

- `use-kind-cluster` did `kubectl create namespace kagent` and
  `kubectl config set-context --current --namespace kagent`. If invoked
  while another cluster was active, both lines would mutate that
  cluster's state (and the user's kubeconfig) instead of kind.
- `kagent-cli-port-forward` and `kagent-ui-port-forward` would forward
  ports from whichever cluster happened to be current.
- `kagent-addon-install` pinned its `kubectl apply` lines but left
  `istioctl install` unscoped, so Istio could land on the wrong cluster.

Pin every kubectl/istioctl invocation to `kind-$(KIND_CLUSTER_NAME)`.
`use-kind-cluster` now sets the namespace on the kind context by name
rather than `--current`, leaving any other context untouched.
The e2e test code calls controller-runtime's `config.GetConfig()` and
also `exec.Command("kubectl", ...)`, both of which honor the active
kubeconfig context. Running `make -C go e2e` while pointed at a remote
cluster would create Agents, MCPServers and ModelConfigs in that
cluster's `kagent` namespace.

Materialize the kind cluster's kubeconfig to a temp file and run the
test binary with KUBECONFIG pinned to it, so the tests cannot reach any
cluster other than the one they were designed for. Abort early with a
clear message if the kind cluster is missing.
Copilot AI review requested due to automatic review settings May 6, 2026 18:15
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.

[BUG] Leaking kind-only resources onto the active kubectl context

1 participant