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

Added load_config function #331

Merged
merged 5 commits into from
Aug 17, 2024
Merged

Conversation

james-mchugh
Copy link
Contributor

@james-mchugh james-mchugh commented Aug 11, 2024

Added load config function from https://github.com/kubernetes-client/python/blob/master/kubernetes/base/config/__init__.py#L24. It was pretty much a drop-in copy and paste, aside from having to update the load_kube_config call to be awaited. I would have copied over any tests as well, but I did not find any. Please let me know if you would like to build some up out or if you'd like me to make any other updates!

Fixes #249

Copy link

codecov bot commented Aug 12, 2024

Codecov Report

Attention: Patch coverage is 90.69767% with 4 lines in your changes missing coverage. Please review.

Project coverage is 28.19%. Comparing base (eda8715) to head (90e7184).
Report is 1 commits behind head on master.

Files Patch % Lines
kubernetes_asyncio/config/__init__.py 75.00% 3 Missing ⚠️
kubernetes_asyncio/config/kube_config_test.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #331      +/-   ##
==========================================
+ Coverage   28.16%   28.19%   +0.02%     
==========================================
  Files         779      779              
  Lines       92200    92239      +39     
==========================================
+ Hits        25965    26003      +38     
- Misses      66235    66236       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@tomplus tomplus left a comment

Choose a reason for hiding this comment

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

Thanks for you porting this code. It's definitely helpful in some use cases.

Could you add a simple test to be sure that the function is in place?
You can add something like this: https://github.com/tomplus/kubernetes_asyncio/blob/master/kubernetes_asyncio/config/kube_config_test.py#L950 but using the new function. Thanks.

@james-mchugh
Copy link
Contributor Author

Thanks for you porting this code. It's definitely helpful in some use cases.

Could you add a simple test to be sure that the function is in place? You can add something like this: https://github.com/tomplus/kubernetes_asyncio/blob/master/kubernetes_asyncio/config/kube_config_test.py#L950 but using the new function. Thanks.

Can do

Unfortunately, the `load_incluster_config` function was difficult to test directly as it was as a few constants would have had to be monkeypatched. To make the function more testable, I made those constants configurable via kwargs.
@james-mchugh
Copy link
Contributor Author

Okay, after a bit of a slow down trying to write unit tests using unittest again (I've been using Pytest for the past 5ish years), I've added two unit tests. One test is for loading the kube config and the other is for loading the incluster config. I had considered adding a dedicated test file, but ultimately decided to add them to the existing files to make better use of the existing helpers they contained (I miss fixtures).

The kube config test was fairly simple, but the incluster config test was a bit more challenging. The load_incluster_config function isn't super testable as is (it relied on hardcoded file paths that were difficult to monkeypatch). I updated the function to make it a bit more configurable and testable.

I also noticed that the version of load_config I copied from Kubernetes was a bit outdated. I'm assuming I had an old version of thekubernetes Python package locally that I copied the config from, so I've updated that to use the newer code as well.

Copy link
Owner

@tomplus tomplus left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me 👍

Pipelines reported an error, could you take a look?

@james-mchugh
Copy link
Contributor Author

Pipelines reported an error, could you take a look?

Awh my bad, I was testing using Python 3.11 and the parentheses in with statements wasn't added until 3.10. It should be good now 👍.

It may be worth adding a tox.ini file in the future to make it easier to run tests across different Python versions. Let me know if that sounds like something you'd be interested in and I could perhaps put in a PR for it

@tomplus
Copy link
Owner

tomplus commented Aug 17, 2024

I removed tox.ini (#105), but now I agree it could be helpful.
So yes, If you want to add it again please do it - many thanks for your contribution!

@tomplus tomplus merged commit 27c76b6 into tomplus:master Aug 17, 2024
8 checks passed
@james-mchugh james-mchugh deleted the load_config branch August 18, 2024 22:31
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.

add config.load_config() support
2 participants