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

raise ConfigException on invalid named-arguments to load_incluster_config #2204

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

addyess
Copy link

@addyess addyess commented Mar 1, 2024

What type of PR is this?

/kind bug
/kind api-change

What this PR does / why we need it:

Gracefully ignore named-arguments to load_incluster_config which have a value of None

Which issue(s) this PR fixes:

Fixes #2203

Special notes for your reviewer:

I couldn't find any unit tests for calling load_incluster_config directly. Let me know if i should add some.

Does this PR introduce a user-facing change?

No, it should be transparent. The exception changes from a TypeError to ConfigException

Before:

...
  File "/home/runner/work/pytest-operator/pytest-operator/.tox/integration-2.9/lib/python3.10/site-packages/kubernetes/config/__init__.py", line 49, in load_config
    load_incluster_config(**kwargs)
TypeError: load_incluster_config() got an unexpected keyword argument 'context'

to

  File "/home/runner/work/pytest-operator/pytest-operator/.tox/integration-2.9/lib/python3.10/site-packages/kubernetes/config/__init__.py", line 49, in load_config
    load_incluster_config(**kwargs)
ConfigException: Unimplemented named-argument context for incluster config

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 1, 2024
@k8s-ci-robot
Copy link
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Mar 1, 2024
Copy link

linux-foundation-easycla bot commented Mar 1, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added needs-kind Indicates a PR lacks a `kind/foo` label and requires one. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 1, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @addyess!

It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 1, 2024
@addyess
Copy link
Author

addyess commented Mar 1, 2024

/kind bug

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Mar 1, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 1, 2024
@addyess addyess marked this pull request as ready for review March 1, 2024 15:04
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 1, 2024
@addyess
Copy link
Author

addyess commented Mar 1, 2024

@fabianvf and @yliaog
thanks for taking the moment to review this easy fix

@roycaihw
Copy link
Member

/assign @yliaog

kubernetes/base/config/incluster_config.py Outdated Show resolved Hide resolved
"""
Use the service account kubernetes gives to pods to connect to kubernetes
cluster. It's intended for clients that expect to be running inside a pod
running on kubernetes. It will raise an exception if called from a process
not running in a kubernetes environment."""
for val in kds.values():
if val is not None:
raise ConfigException(f"Unimplemented named-argument {val} for incluster config.")
Copy link
Contributor

Choose a reason for hiding this comment

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

how is ConfigException better than TypeError ?

Copy link
Author

Choose a reason for hiding this comment

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

its only slightly better because the client code only has to catch one exception -- ConfigException

Secondarily, this will allow callers to: load_config

to call with a keyword arg like context=None and load_incluster_config won't bark with the TypeError, but if there is a context=<val> that's non-none, we'll get a meaningful exceptions from load_incluster_config

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: addyess
Once this PR has been reviewed and has the lgtm label, please ask for approval from yliaog. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

load_config does not really support "context"
4 participants