Skip to content
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

execution provider errors encountered while loading configuration in interactive mode generate secondary exception #2343

Open
johnson-earls opened this issue Feb 3, 2025 · 2 comments
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@johnson-earls
Copy link

What happened (please include outputs or screenshots):

Due to already-reported issues with ExecProvider in 32.0.0, loading my EKS-based kube config failed. i was doing my testing in an interactive shell, however, so what I saw is this:

>>> kubernetes.config.load_config(context='dev-admin')

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help

aws: error: the following arguments are required: command

ERROR:root:'NoneType' object has no attribute 'strip'
>>>

What you expected to happen:

I did not expect the 'NoneType' object has no attribute 'strip' exception.

How to reproduce it (as minimally and precisely as possible):

The following only works with python-kubernetes version 31 or older, due to the bug introduced in ExecProvider in 32.0.0 that causes it to lose the exec arguments, but the bug in question still exists in version 32 from visual inspection of the code.

$ kubectl config set-credentials test-fail --exec-api-version='client.authentication.k8s.io/v1beta1' --exec-command=sh --exec-arg=-c --exec-arg='exit 1'
$ kubectl config set-cluster test-fail
$ kubectl config set-context test-fail --cluster=test-fail --user=test-fail
$ python -c 'import kubernetes; kubernetes.config.load_config(context="test-fail")'
ERROR:root:'NoneType' object has no attribute 'strip'
$ python -c 'import kubernetes; kubernetes.config.load_config(context="test-fail")' | cat
ERROR:root:exec: process returned 1

Anything else we need to know?:

Error is caused when run with stdout pointing to a tty: in ExecProvider.run(), if is_interactive gets set to True, then the subprocess is opened with stderr pointing to sys.stderr rather than subprocess.PIPE. In the later error handling code, there is no check to see if is_interactive is True or if stderr is not None, so the code blindly calls stderr.strip() and raises the secondary exception.

Environment:

  • Kubernetes version (kubectl version):
Client Version: v1.25.4
Kustomize Version: v4.5.7
  • OS (e.g., MacOS 10.13.6):
    MacOS 15.3
  • Python version (python --version)
    Python 3.11.7
  • Python client version (pip list | grep kubernetes)
kubernetes                         31.0.0
@johnson-earls johnson-earls added the kind/bug Categorizes issue or PR as related to a bug. label Feb 3, 2025
@jennifgcrl
Copy link

oh this is fixed by #2338

@roycaihw
Copy link
Member

#2338 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants