Skip to content

Read $KUBECONFIG env var in kubectl generator#233

Merged
lucieleblanc merged 4 commits into
mainfrom
app-3478/command-spec-kubectl-kubeconfig
Apr 6, 2026
Merged

Read $KUBECONFIG env var in kubectl generator#233
lucieleblanc merged 4 commits into
mainfrom
app-3478/command-spec-kubectl-kubeconfig

Conversation

@lucieleblanc
Copy link
Copy Markdown
Contributor

Summary

Read $KUBECONFIG environment variable in kubectl_script() and pass it to kubectl commands when --kubeconfig is not explicitly specified in the command tokens. This enables resource completions for users who set KUBECONFIG in their shell environment, which is common for multi-cluster Kubernetes setups.

Fixes: warpdotdev/warp#3930
Linear: APP-3478

Changes

Updated kubectl_script() in command-signatures/src/generators/kubectl.rs to apply three levels of kubeconfig resolution:

  1. --kubeconfig flag from command tokens (existing behavior, highest priority)
  2. KUBECONFIG from inline command environment variables (e.g., KUBECONFIG=/path kubectl get pods)
  3. $KUBECONFIG shell variable fallback for session-level env vars forwarded to the child process

Added a helper function env_var_value() to extract values from the KEY=VALUE formatted env vars list.

Testing

Context generator with --kubeconfig flag

Completions dropdown correctly shows staging-context and test-context from the kubeconfig file:

Context completions with --kubeconfig flag

Unit Tests

Added 5 unit tests covering:

  • --kubeconfig flag from tokens
  • KUBECONFIG from inline env vars
  • Flag takes precedence over env var
  • Shell variable fallback when neither is specified
  • env_var_value() helper function

All tests pass: cargo test -p warp-command-signatures -- kubectl → 5 passed.

script/presubmit passes (22 total tests).


Conversation: https://staging.warp.dev/conversation/53c00fa8-fb8d-4ba9-86c8-249585bbba02
Run: https://oz.staging.warp.dev/runs/019d4b05-7ecc-79df-b704-a3d601a24f4b
This PR was generated with Oz.

Update kubectl_script() to read the KUBECONFIG environment variable and
pass it to kubectl commands when --kubeconfig is not explicitly specified
in the command tokens. This enables resource completions for users who
set KUBECONFIG in their shell environment (common for multi-cluster
setups).

The fix applies three levels of kubeconfig resolution:
1. --kubeconfig flag from command tokens (existing behavior)
2. KUBECONFIG from inline command environment variables
3. $KUBECONFIG shell variable fallback for session-level env vars

Also adds unit tests for the new behavior.

Fixes: warpdotdev/warp#3930

Co-Authored-By: Oz <oz-agent@warp.dev>
@linear
Copy link
Copy Markdown

linear Bot commented Apr 1, 2026

APP-3478 [kubectl] Read $KUBECONFIG env var in generator

The kubectl generator currently only forwards --kubeconfig from tokens but doesn't read the $KUBECONFIG environment variable. Users who set KUBECONFIG in their shell (common for multi-cluster setups) get no resource completion.

Fix: read $KUBECONFIG env var in kubectl_script() in command-signatures/src/generators/kubectl.rs and pass it to kubectl commands.

See GitHub #3930

Copy link
Copy Markdown
Contributor Author

Context generator screenshot (--kubeconfig flag)

Testing kubectl --kubeconfig /tmp/kube-test/config config use-context + Tab:

The completions dropdown shows staging-context and test-context from the kubeconfig file, followed by flag completions.

Copy link
Copy Markdown
Contributor Author

Context generator with --kubeconfig flag

screenshot-context-generator

Copy link
Copy Markdown
Contributor Author

Context completions with session KUBECONFIG env var

screenshot-context-kubeconfig-env

@lucieleblanc
Copy link
Copy Markdown
Contributor Author

lucieleblanc commented Apr 3, 2026

Manually attached screenshots:
flag generator
image
empty generator
image

@lucieleblanc
Copy link
Copy Markdown
Contributor Author

Manually attached screenshots:
image

image

@lucieleblanc lucieleblanc marked this pull request as ready for review April 3, 2026 21:05
@lucieleblanc lucieleblanc merged commit 31f3da5 into main Apr 6, 2026
3 checks passed
@lucieleblanc lucieleblanc deleted the app-3478/command-spec-kubectl-kubeconfig branch April 6, 2026 14:50
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.

kubectl resources completions not work by KUBECONFIG env

3 participants