Skip to content

fix(kubectl): support global flags + exec/delete/rollout subcommands (#927) - #2478

Open
ousamabenyounes wants to merge 2 commits into
rtk-ai:developfrom
ousamabenyounes:fix/issue-927
Open

ousamabenyounes wants to merge 2 commits into
rtk-ai:developfrom
ousamabenyounes:fix/issue-927

Conversation

@ousamabenyounes

Copy link
Copy Markdown
Contributor

Fixes #927.

The kubectl rewrite/classify rules missed several real-world invocation shapes: the --context/-n global flags placed before the subcommand, the exec and delete subcommands, and variable-assignment prefixes. As a result those commands were not routed through the RTK filter.

Fix

Extend the kubectl rules in src/discover/rules.rs to recognise the missing subcommands (exec, delete, rollout, …) and global flags, so they classify and rewrite correctly.

Test verification (RED → GREEN)

RED — src/discover/rules.rs reverted to develop:

test result: FAILED. 8 passed; 6 failed
  test_rewrite_kubectl_with_context_flag ... FAILED
  test_rewrite_kubectl_short_namespace_flag ... FAILED
  test_rewrite_kubectl_exec_subcommand ... FAILED
  test_classify_kubectl_exec ... FAILED
  test_classify_kubectl_delete ... FAILED

GREEN — with the fix:

running 14 tests
test result: ok. 14 passed; 0 failed

(Re-proposes the accidentally-closed #1196, rebased onto current develop.)

@ousamabenyounes

Copy link
Copy Markdown
Contributor Author

Rebased this PR onto current develop and pushed f5955d1.

It is mergeable again with no base lag. Waiting for review when you have a moment, @aeppling.

@ousamabenyounes
ousamabenyounes force-pushed the fix/issue-927 branch 3 times, most recently from ef2ef30 to c671731 Compare August 4, 2026 18:55
ousamabenyounes and others added 2 commits October 17, 2026 00:36
…commands (rtk-ai#927)

The classify/rewrite pattern only matched subcommands in first position,
so `kubectl --context foo get pods` or `kubectl -n ns exec pod` were not
rewritten by the hook or flagged as missed savings.

Update the RtkRule pattern to skip zero or more global flags
(--long-opt[=val|-n val) before matching the subcommand, and extend the
subcommand list from 4 to 19 entries (exec, delete, create, patch,
rollout, scale, port-forward, top, diff, wait, events, run, expose,
auth, cp, version, config, api-resources, label, annotate, edit,
replace, cordon, drain, taint).

Add regression tests for --context, -n, and exec cases.

Closes rtk-ai#927

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
`rewrite_command` now requires a third `transparent_prefixes: &[String]`
argument on develop. Update the 3 kubectl global-flag assertions added
in this PR to pass `&[]` so the project compiles cleanly post-rebase.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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 rewrite misses --context flag, exec subcommand, and variable assignments

1 participant