Skip to content

feat: pass context and token flags to kubectl exec commands #3169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fabianonunes
Copy link

When initializing k9s with --kubeconfig, --context, and --token parameters, only the --kubeconfig flag was being passed to kubectl exec when running a shell in a container. This inconsistency could lead to authentication issues or accessing the wrong cluster when using shell functionality.

This PR ensures that all relevant authentication flags (--kubeconfig, --context, and --token) are consistently passed to kubectl commands when executing a shell in a container.

This PR:

  1. Modifies buildShellArgs function to accept context and token parameters
  2. Updates all callers to pass these parameters from the connection configuration
  3. Adds test cases to verify the new functionality

When executing shell in a container, only the kubeconfig flag was being
passed to kubectl exec commands. This change ensures that context and bearer
token flags are also passed when available, maintaining consistency with the
initial k9s configuration parameters.
Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabianonunes Nice! Please see comment below.

@@ -337,7 +337,8 @@ func sshIn(a *App, fqn, co string) error {
return fmt.Errorf("os detect failed: %w", err)
}

args := buildShellArgs("exec", fqn, co, a.Conn().Config().Flags().KubeConfig)
flags := a.Conn().Config().Flags()
args := buildShellArgs("exec", fqn, co, flags.KubeConfig, flags.Context, flags.BearerToken)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabianonunes I think it will be best to just pass in the k8s flags at the call site and let buildShellArgs figure out what it need to extract out.

@derailed derailed added enhancement New feature or request needs-tlc Pr needs additional updates labels Mar 7, 2025
@derailed derailed mentioned this pull request Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-tlc Pr needs additional updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants