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

Empty auth-provider/config key raises ConfigException #328

Closed
pbrumblay opened this issue Aug 23, 2017 · 11 comments
Closed

Empty auth-provider/config key raises ConfigException #328

pbrumblay opened this issue Aug 23, 2017 · 11 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@pbrumblay
Copy link

I'm trying to write a dockerized application to crawl k8s clusters and extract configuration information. I don't wish to install gcloud/kubectl in the application container so I'm following this suggestion on constructing a kube config file: kubernetes/kubernetes#30617 (comment)

With this config file:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: <REDACTED>
    server: https://<REDACTED>
  name: foo-cluster
contexts:
- context:
    cluster: foo-cluster
    user: foo-cluster
  name: foo-cluster
current-context: foo-cluster
kind: Config
preferences: {}
users:
- name: foo-cluster
  user:
    auth-provider:
      config: null
      name: gcp

And this code:

from kubernetes import config, client

config.load_kube_config('myconfig')

I get this error:

<SNIP!>
  File "/Users/peter/python3/py3/lib/python3.6/site-packages/kubernetes/config/kube_config.py", line 196, in _load_gcp_token
    self._refresh_gcp_token()
  File "/Users/peter/python3/py3/lib/python3.6/site-packages/kubernetes/config/kube_config.py", line 204, in _refresh_gcp_token
    provider = self._user['auth-provider']['config']
  File "/Users/peter/python3/py3/lib/python3.6/site-packages/kubernetes/config/kube_config.py", line 290, in __getitem__
    % (key, self.name))
kubernetes.config.config_exception.ConfigException: Invalid kube-config file. Expected key config in kube-config/users[name=foo-cluster]/user/auth-provider

The key is present - what the heck? This threw me for a while until I cracked open the code.

I believe this is because line 203 of https://github.com/kubernetes-client/python-base/blob/ab3fc5446714ac19100c0f97072c53cbd81c3b87/config/kube_config.py sets the value to the empty dict {} and line 287 in __getitem__ only tests for boolean true (and empty dicts are False in python).

My workaround is to add a bogus attribute under config to my yaml file to make the dict non-empty. It appears that the intent is to allow people to have missing/empty/invalid/expired auth-provider/config entries and to then generate the config entry when such a case is detected. I'm new to python but I suppose this is a common problem because of the way that python evaluates empty dicts to False.

I'm not sure what the right fix would be, whether to have __getitem__ allow empty structures or to simply add a bogus value to make the dict non-empty in line 203. Or maybe I should have just known this and tried adding a bogus attribute to config right off the bat...

@mbohlool
Copy link
Contributor

It is a reasonable request to have getitem allow empty dict. I say we should check check for none here: https://github.com/kubernetes-client/python-base/blob/ab3fc5446714ac19100c0f97072c53cbd81c3b87/config/kube_config.py#L287

if v is not None: ...

@pbrumblay
Copy link
Author

Cool. I'm not terribly concerned if there is an incoming fix or not, but hopefully this issue documents an ok (findable!) workaround so others don't stumble as much as I did.

@iamneha
Copy link
Contributor

iamneha commented Oct 28, 2018

/assign @iamneha

@k8s-ci-robot
Copy link
Contributor

@iamneha: GitHub didn't allow me to assign the following users: iamneha.

Note that only kubernetes-client members and repo collaborators can be assigned.
For more information please see the contributor guide

In response to this:

/assign @iamneha

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.

@pvanderlinden
Copy link

@pbrumblay I don't think it's a good to have a work around instead of a fix. The library should be able to read config files which are generated/read by other standard kubernetes tools, and kubectl reads this just fine. This bug doesn't exist in version 8.0.0.

@pbrumblay
Copy link
Author

@pvanderlinden Great! I'm glad it's been fixed. I've moved on from this work and don't have time to verify it. Feel free to close this. As I said above, I mainly opened this to save others pain.

@pbrumblay I don't think it's a good to have a work around instead of a fix. The library should be able to read config files which are generated/read by other standard kubernetes tools, and kubectl reads this just fine. This bug doesn't exist in version 8.0.0.

@pvanderlinden
Copy link

pvanderlinden commented Jan 9, 2019

@pbrumblay It's not actually fixed. That's just an older version which doesn't have the bug.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 28, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 28, 2019
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

6 participants