Skip to content

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

Open

Description

@sebagavilan

Problem

rtk discover shows ~1,300 kubectl commands not being rewritten despite kubectl being a supported proxy. The issue is that rtk rewrite only handles the simplest form (kubectl <subcommand> ...) but misses common real-world patterns.

Patterns not rewritten

Pattern Example Expected
Flags before subcommand kubectl --context msquant-test get pods -n test rtk kubectl --context msquant-test get pods -n test
kubectl exec kubectl exec -n test pod-0 -- psql rtk kubectl exec -n test pod-0 -- psql
Variable assignment wrapper REDIS_POD=$(kubectl get pods -n test -l app=redis -o name) REDIS_POD=$(rtk kubectl get pods ...)
Line continuation \
kubectl --kubeconfig ...
rtk kubectl --kubeconfig ...

Reproduction

$ rtk rewrite 'kubectl get pods -n test'
rtk kubectl get pods -n test          # ✅ works

$ rtk rewrite 'kubectl --context msquant-test get pods -n test'
# exit 1, no output                   # ❌ missed

$ rtk rewrite 'kubectl exec -n test msquant-postgresql-0 -- psql'
# exit 1, no output                   # ❌ missed

$ rtk rewrite 'REDIS_POD=$(kubectl get pods -n test -l app=redis -o name)'
# exit 1, no output                   # ❌ missed

Environment

  • rtk 0.30.1
  • macOS (Darwin 23.5.0)
  • Hook: rtk-rewrite.sh (hook v2)

Impact

~1,300 kubectl commands over 30 days not getting token savings. kubectl output (pod lists, describe, logs) is often very verbose — high savings potential.

Activity

  1. added
    bug
    effort-medium
    filter-quality
    on Apr 4, 2026
  2. pszymkowiak commented on Apr 4, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 87%

    Summary

    kubectl rewrite rule misses flags-before-subcommand, exec, variable assignment, and line-continuation patterns — ~1,300 commands/month going unrewritten; fix requires expanding the kubectl rewrite regex/parser to cover these four common real-world forms.

    📁 Relevant files
    • src/rewrite/kubectl.rs
    • src/rewrite/mod.rs

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

  3. HerrmannHinz commented on Nov 13, 2026

    @HerrmannHinz

    Still reproducible on rtk 1.0.1: kubectl -n obs get svc and kubectl --context c get pods are not rewritten, while kubectl get svc -n obs is. The general $(...) / loop case is tracked in #5110.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibugeffort-mediumfilter-qualityhelp wantedpriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions