Skip to content

Conversation

rohitkumar1369
Copy link

@rohitkumar1369 rohitkumar1369 commented Jun 16, 2025

Fix kubectl command execution and argument handling

Issue:
The kubectl command execution was failing due to incorrect argument ordering and handling:

  1. Global kubectl flags (--cache-dir, --kubeconfig) were being passed to the wrong command
  2. Namespace flag (-n) handling was position-dependent and could fail if not in the expected position
  3. Command structure was causing kubectl to fail with "exit status 2" errors

What does this PR change?

  1. Fixed command argument ordering to ensure kubectl flags are passed correctly

    • Global kubectl flags (--cache-dir, --kubeconfig) are now passed first
    • Namespace flag (-n) is handled specially and placed after global flags
    • Command-specific arguments follow after the flags
  2. Improved namespace flag handling

    • Added support for -n flag in any position in the command
    • Namespace flag is automatically moved to the correct position after global flags
    • Example: kubectl exec -n default -it pod and kubectl -n default exec -it pod now work identically
  3. Code cleanup

    • Removed unused fmt import
    • Simplified logging statements
    • Improved code organization for better readability
  4. Testing
    The changes have been tested with various kubectl command formats:

    • Commands with namespace flag in different positions
    • Interactive commands (exec, logs, edit)
    • Non-interactive commands
    • Commands with global kubectl flags
  5. Impact
    These changes ensure that kubectl commands are executed correctly regardless of the order of flags and arguments, improving the reliability of the command execution system.

Does the PR depend on any other PRs or Issues? If yes, please list them.

No

Checklist

I confirm, that I have...

  • Read and followed the contributing guide in CONTRIBUTING.md
  • Added tests for this PR
  • Formatted the code using go fmt (if applicable)
  • Updated documentation on the Paralus docs site (if applicable)
  • Updated CHANGELOG.md

…to kubectl , but get passed to command in exec
@rohitkumar1369 rohitkumar1369 changed the title handles -n flagin any position and fixes args that need to be passed … Fix kubectl command execution and argument handling Jun 16, 2025
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.

1 participant