-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
What happened (please include outputs or screenshots):
I have tried your recommendation @roycaihw mentioned in #1775 (comment) but I have noticed a strange thing: debug mode "switches back to off" automatically after receiving the response back from the server. Here is the call stack at that moment:
setLevel, __init__.py:1421
debug, configuration.py:271
__init__, configuration.py:126
__init__, v1_managed_fields_entry.py:58
__deserialize_model, api_client.py:641
__deserialize, api_client.py:303
<listcomp>, api_client.py:280
__deserialize, api_client.py:280
__deserialize_model, api_client.py:639
__deserialize, api_client.py:303
__deserialize_model, api_client.py:639
__deserialize, api_client.py:303
deserialize, api_client.py:264
__call_api, api_client.py:192
call_api, api_client.py:348
read_namespaced_config_map_with_http_info, core_v1_api.py:22802
read_namespaced_config_map, core_v1_api.py:22715
... application code
I even tried changing the default one, here is the full repro code:
import kubernetes
kubernetes.config.load_kube_config(context='minikube')
client_config = kubernetes.client.Configuration.get_default_copy()
client_config.debug = True
kubernetes.client.Configuration.set_default(client_config)
core_api_client = kubernetes.client.CoreV1Api()
response_with_debug_logging = core_api_client.read_namespaced_config_map(
name='my-state', namespace='my-namespace'
)
response_without_debug_logging = core_api_client.read_namespaced_config_map(
name='my-state', namespace='my-namespace'
)but the call setLevel mutates global logging configuration and can't be reset back. Actually, based on this code, I got debug working again by manually setting again the debug, but that seems like a very wrong thing to do.
What you expected to happen:
I would prefer if, after creating an API client and choosing to activate debug mode, that it stays active throughout the lifetime of the request.
How to reproduce it (as minimally and precisely as possible):
- Follow the unofficial debug activation process as outlined in here and referenced here.
- Execute more than 1 API call and you will see that the code flips back to non-debug and no request body is logged
Anything else we need to know?:
I found 2 ways of avoiding this problem:
- creating new API client for each interaction, because that one then takes the default config and maintains debug property
- calling the set debug property after each response comes back
Is there a recommendation to always use 1) perhaps? I wouldn't expect that we shouldn't reuse API client object and we should perhaps throw it away each time, but perhaps I am wrong since I'd expect that is wasteful?
Environment:
-
Kubernetes version (
kubectl version):Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.6", GitCommit:"f59f5c2fda36e4036b49ec027e556a15456108f0", GitTreeState:"archive", BuildDate:"1980-01-01T00:00:00Z", GoVersion:"go1.16.13", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.1", GitCommit:"86ec240af8cbd1b60bcc4c03c20da9b98005b92e", GitTreeState:"clean", BuildDate:"2021-12-16T11:34:54Z", GoVersion:"go1.17.5", Compiler:"gc", Platform:"linux/amd64"} -
OS (e.g., MacOS 10.13.6): MacOs 12.3.1
-
Python version (
python --version): 3.9.9 -
Python client version (
pip list | grep kubernetes): 23.3.0