Skip to content

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

Open
@johnson-earls

Description

@johnson-earls

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions