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

The dynamic client example, kubernetes.client.ApiClient(...) takes in the result of kubernetes.config.load_kube_config(...), which is empty #2279

Open
tonur opened this issue Sep 10, 2024 · 4 comments · May be fixed by #2283
Labels
kind/documentation Categorizes issue or PR as related to documentation.

Comments

@tonur
Copy link

tonur commented Sep 10, 2024

Link to the issue (please include a link to the specific documentation or example):
Example where client.ApiClient(configuration=config.load_kube_config()) is used:
https://github.com/kubernetes-client/python/blob/master/examples/dynamic-client/configmap.py#L27
Link to where config function load_kube_config() does not return anything:
https://github.com/kubernetes-client/python/blob/master/kubernetes/base/config/kube_config.py#L799

Description of the issue (please include outputs or screenshots if possible):
I would assume that when configuring an ApiClient, I should send the argument of the configuration object. However, since the config.load_kube_config() does not return anything, I feel that this example is wrong.

I would assume I should do the following:

from kubernetes import config, dynamic
from kubernetes.client import api_client
configuration = client.Configuration()
config.load_kube_config()
client = api_client.ApiClient(configuration=configuration)

Since the config.load_kube_config() has this in the description:
"Loads authentication and cluster information from kube-config file and stores them in kubernetes.client.configuration."
So that the client.Configuration() returned value is updated after being instantiated and thus can be passed to the api_client.ApiClient(...) function.

Can anyone please correct me if I am wrong? I am unsure of what the correct way to get an ApiClient.
Thanks in advance!

@tonur tonur added the kind/documentation Categorizes issue or PR as related to documentation. label Sep 10, 2024
@yliaog
Copy link
Contributor

yliaog commented Sep 11, 2024

@fabianvf could you help take a look?

@fabianvf
Copy link
Contributor

@tonur you're correct, the client is being instatiated there oddly. To create the dynamic client, you instantiate an API client and pass it in, so the proper series of calls would be:

from kubernetes import config, dynamic
from kubernetes.client import api_client

configuration = client.Configuration()
config.load_kube_config()

api_client = api_client.ApiClient(configuration=configuration)
dynamic_client = dynamic.DynamicClient(api_client)

@tonur
Copy link
Author

tonur commented Sep 13, 2024

Is it okay that I make a Pull Request to change this in the example? Or is it something you'd rather do?

@fabianvf
Copy link
Contributor

@tonur absolutely! A PR would be appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Categorizes issue or PR as related to documentation.
Projects
None yet
3 participants