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

raise exception when an empty config file is passed to load_kube_config #223

Merged
merged 3 commits into from
Feb 9, 2021

Conversation

MridulS
Copy link
Contributor

@MridulS MridulS commented Jan 22, 2021

load_kube_config currently fails with a nondescript TypeError: 'NoneType' error if an empty kube_config file is used.

Error log

~/miniconda3/envs/dask/lib/python3.8/site-packages/kubernetes/config/kube_config.py in load_kube_config(config_file, context, client_configuration, persist_config)
    790         config_file = KUBE_CONFIG_DEFAULT_LOCATION
    791
--> 792     loader = _get_kube_config_loader(
    793         filename=config_file, active_context=context,
    794         persist_config=persist_config)

~/miniconda3/envs/dask/lib/python3.8/site-packages/kubernetes/config/kube_config.py in _get_kube_config_loader(filename, config_dict, persist_config, **kwargs)
    744         **kwargs):
    745     if config_dict is None:
--> 746         kcfg = KubeConfigMerger(filename)
    747         if persist_config and 'config_persister' not in kwargs:
    748             kwargs['config_persister'] = kcfg.save_changes

~/miniconda3/envs/dask/lib/python3.8/site-packages/kubernetes/config/kube_config.py in __init__(self, paths)
    671             self._load_config_from_file_like_object(paths)
    672         else:
--> 673             self._load_config_from_file_path(paths)
    674
    675     @property

~/miniconda3/envs/dask/lib/python3.8/site-packages/kubernetes/config/kube_config.py in _load_config_from_file_path(self, string)
    693                 if os.path.exists(path):
    694                     self.paths.append(path)
--> 695                     self.load_config(path)
    696         self.config_saved = copy.deepcopy(self.config_files)
    697

~/miniconda3/envs/dask/lib/python3.8/site-packages/kubernetes/config/kube_config.py in load_config(self, path)
    703             config_merged = copy.deepcopy(config)
    704             for item in ('clusters', 'contexts', 'users'):
--> 705                 config_merged[item] = []
    706             self.config_merged = ConfigNode(path, config_merged, path)
    707         for item in ('clusters', 'contexts', 'users'):

TypeError: 'NoneType' object does not support item assignment

I have added a check to raise a ConfigException error if an empty file is encountered.

@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 Jan 22, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @MridulS!

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/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 22, 2021
@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 Jan 23, 2021
@MridulS
Copy link
Contributor Author

MridulS commented Jan 25, 2021

The travis error on functional tests seems to be because of a minikube error.

W0125 15:54:45.089355    4821 out.go:181] X Exiting due to RSRC_INSUFFICIENT_CORES: Requested cpu count 1 is less than the minimum allowed of 2
493X Exiting due to RSRC_INSUFFICIENT_CORES: Requested cpu count 1 is less than the minimum allowed of 2
494I0125 15:54:45.089376    4821 out.go:119] 
495
496

@yliaog
Copy link
Contributor

yliaog commented Feb 1, 2021

/assign @fabianvf

config/kube_config_test.py Outdated Show resolved Hide resolved
@MridulS MridulS requested a review from fabianvf February 2, 2021 08:55
@MridulS
Copy link
Contributor Author

MridulS commented Feb 2, 2021

/retest

@k8s-ci-robot
Copy link
Contributor

@MridulS: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

@yliaog
Copy link
Contributor

yliaog commented Feb 2, 2021

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Feb 2, 2021
@MridulS
Copy link
Contributor Author

MridulS commented Feb 2, 2021

/retest

@MridulS
Copy link
Contributor Author

MridulS commented Feb 2, 2021

Travis seems to be failing due to an unrelated test. Any ideas what's happening here? Travis is happy now :D

@MridulS
Copy link
Contributor Author

MridulS commented Feb 9, 2021

Just wanted to check in to see if this looks okay :)

@fabianvf
Copy link
Contributor

fabianvf commented Feb 9, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 9, 2021
@MridulS
Copy link
Contributor Author

MridulS commented Feb 9, 2021

/assign @yliaog

@yliaog
Copy link
Contributor

yliaog commented Feb 9, 2021

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabianvf, MridulS, yliaog

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 Feb 9, 2021
@k8s-ci-robot k8s-ci-robot merged commit 04feb9f into kubernetes-client:master Feb 9, 2021
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants