Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Support file-ish objects in config loading #208

Merged
merged 7 commits into from
Sep 9, 2020
Merged

Support file-ish objects in config loading #208

merged 7 commits into from
Sep 9, 2020

Conversation

ryphon
Copy link
Contributor

@ryphon ryphon commented Aug 19, 2020

Closes #207

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Aug 19, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @ryphon!

It looks like this is your first PR to kubernetes-client/python-base 🎉. 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-base 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 19, 2020
@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 Aug 19, 2020
@ryphon
Copy link
Contributor Author

ryphon commented Aug 19, 2020

working.txt

File attached of a python console loading a config from local file into a StringIO fileish object, and then that string being used as config for the api client.

This should work just fine with actual file objects as well, rather than a path.

@ryphon
Copy link
Contributor Author

ryphon commented Aug 29, 2020

/assign @yliaog

Comment on lines 671 to 680
if hasattr(paths, 'read'):
self.load_config_from_fileish(paths)
else:
for path in paths.split(ENV_KUBECONFIG_PATH_SEPARATOR):
if path:
path = os.path.expanduser(path)
if os.path.exists(path):
self.paths.append(path)
self.load_config(path)
self.config_saved = copy.deepcopy(self.config_files)
Copy link
Member

Choose a reason for hiding this comment

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

How about pushing the code path for paths to a separate internal function (say _load_config_from_file_path) as well? I think readability will increase that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this as well, will get this in shortly as well!


@property
def config(self):
return self.config_merged

def load_config_from_fileish(self, string):
Copy link
Member

Choose a reason for hiding this comment

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

How does renaming the method to _load_config_from_file_like_object sound? (_ since this is not supposed to be used externally)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a great point, will get that in shortly.

@palnabarun
Copy link
Member

/assign

@roycaihw
Copy link
Member

roycaihw commented Sep 9, 2020

There is a test failure https://travis-ci.org/github/kubernetes-client/python-base/builds/722838842:

_______ TestKubeConfigLoader.test_load_kube_config_from_file_like_object _______
self = <config.kube_config_test.TestKubeConfigLoader testMethod=test_load_kube_config_from_file_like_object>
    def test_load_kube_config_from_file_like_object(self):
        expected = FakeConfig(host=TEST_HOST,
                              token=BEARER_TOKEN_FORMAT % TEST_DATA_BASE64)
        config_file_like_object = io.StringIO()
>       config_file_like_object.write(yaml.safe_dump(self.TEST_KUBE_CONFIG))
E       TypeError: unicode argument expected, got 'str'
kubernetes/base/config/kube_config_test.py:1265: TypeError

Please take a look. LGTM otherwise.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: roycaihw, ryphon

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 9, 2020
@ryphon
Copy link
Contributor Author

ryphon commented Sep 9, 2020

Ah silly me, I didn't realize I also had to write for 2.7. I'll get another commit in the next couple days to address.

@ryphon
Copy link
Contributor Author

ryphon commented Sep 9, 2020

Not sure why travis isn't reporting, but the tests now pass. @roycaihw @palnabarun @yliaog

@roycaihw
Copy link
Member

roycaihw commented Sep 9, 2020

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config isn't able to take a string, or StringIO object
5 participants