Skip to content

fix(kubectl): support global flags before subcommand, add exec/delete/rollout and 15 more subcommands - #1196

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

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

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The kubectl classify/rewrite regex only matched subcommands in the first token position, so commands like kubectl --context foo get pods or kubectl -n ns exec pod -- bash were silently skipped — not rewritten by the hook and not flagged as missed savings by rtk discover
  • Updated the RtkRule pattern to allow zero or more global flags (--long-opt[=val], -f val) before the subcommand anchor
  • Extended the subcommand list from 4 (get, logs, describe, apply) 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
  • Added 6 regression tests covering --context, -n, and exec patterns

Test plan

  • cargo fmt --all passes
  • cargo clippy --all-targets — no new errors (only pre-existing warnings)
  • cargo test --all — all 1379 tests pass
  • New tests: test_rewrite_kubectl_with_context_flag, test_rewrite_kubectl_short_namespace_flag, test_rewrite_kubectl_exec_subcommand, test_classify_kubectl_exec, test_classify_kubectl_delete, test_classify_kubectl_rollout

Closes #927

🤖 Generated with Ora Studio


Vibe Coded by Ousama Ben Younes
Developed With Ora Studio (Claude Code)

@pszymkowiak pszymkowiak added bug Something isn't working effort-medium 1-2 jours, quelques fichiers filter-quality Filter produces incorrect/truncated signal labels Apr 10, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes kubectl command classification and rewriting to support global flags (like --context, -n, --kubeconfig) appearing before the subcommand, which were previously causing commands to be silently skipped. Also extends the recognized subcommand list from 4 to 19+ entries and fixes git log output truncation for user-specified formats.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #927


Analyzed automatically by wshm · This is an automated analysis, not a human review.

ousamabenyounes and others added 2 commits May 24, 2026 22:27
…commands (#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 #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]>
@ousamabenyounes

ousamabenyounes commented May 24, 2026 •

Copy link
Copy Markdown
Contributor Author

@aepling — rebased on develop + CI fix landed in b0198d5. All checks green.

RED → GREEN proof (rewrite_command gained a 3rd transparent_prefixes: &[String] arg on develop):

# BEFORE fix (parent commit 6071424)
error[E0061]: this function takes 3 arguments but 2 arguments were supplied
  --> src/discover/registry.rs:2061 / :2069 / :2077
  (×3 occurrences in new kubectl global-flag tests)

# AFTER fix (b0198d5)
$ cargo test --bin rtk test_rewrite_kubectl
    test_rewrite_kubectl_with_context_flag .... ok
    test_rewrite_kubectl_short_namespace_flag . ok
    test_rewrite_kubectl_exec_subcommand ...... ok
test result: ok. 4 passed; 0 failed

$ cargo test --bin rtk test_classify_kubectl
    test_classify_kubectl_exec ............... ok
    test_classify_kubectl_delete ............. ok
    test_classify_kubectl_rollout ............ ok
test result: ok. 5 passed; 0 failed

Ready for re-review 🙏

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

Labels

bug Something isn't working effort-medium 1-2 jours, quelques fichiers filter-quality Filter produces incorrect/truncated signal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kubectl rewrite misses --context flag, exec subcommand, and variable assignments

2 participants