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

Allow passing of custom pool manager #2335

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kubernetes/client/api_client.py
Original file line number Diff line number Diff line change
@@ -66,13 +66,13 @@ class ApiClient(object):
_pool = None

def __init__(self, configuration=None, header_name=None, header_value=None,
cookie=None, pool_threads=1):
cookie=None, pool_threads=1, pool_manager=None):
if configuration is None:
configuration = Configuration.get_default_copy()
self.configuration = configuration
self.pool_threads = pool_threads

self.rest_client = rest.RESTClientObject(configuration)
self.rest_client = rest.RESTClientObject(configuration, pool_manager=pool_manager)
self.default_headers = {}
if header_name is not None:
self.default_headers[header_name] = header_value
7 changes: 6 additions & 1 deletion kubernetes/client/rest.py
Original file line number Diff line number Diff line change
@@ -50,13 +50,18 @@ def getheader(self, name, default=None):

class RESTClientObject(object):

def __init__(self, configuration, pools_size=4, maxsize=None):
def __init__(self, configuration, pools_size=4, maxsize=None, pool_manager=None):
# urllib3.PoolManager will pass all kw parameters to connectionpool
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
# maxsize is the number of requests to host that are allowed in parallel # noqa: E501
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501

# Pre-created pool manager provided
if pool_manager is not None:
self.pool_manager = pool_manager
return

# cert_reqs
if configuration.verify_ssl:
cert_reqs = ssl.CERT_REQUIRED
44 changes: 44 additions & 0 deletions scripts/rest_pool_manager.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
diff --git a/kubernetes/client/api_client.py b/kubernetes/client/api_client.py
index 53d94ce40..9db3eafad 100644
--- a/kubernetes/client/api_client.py
+++ b/kubernetes/client/api_client.py
@@ -66,13 +66,13 @@ class ApiClient(object):
_pool = None

def __init__(self, configuration=None, header_name=None, header_value=None,
- cookie=None, pool_threads=1):
+ cookie=None, pool_threads=1, pool_manager=None):
if configuration is None:
configuration = Configuration.get_default_copy()
self.configuration = configuration
self.pool_threads = pool_threads

- self.rest_client = rest.RESTClientObject(configuration)
+ self.rest_client = rest.RESTClientObject(configuration, pool_manager=pool_manager)
self.default_headers = {}
if header_name is not None:
self.default_headers[header_name] = header_value
diff --git a/kubernetes/client/rest.py b/kubernetes/client/rest.py
index 3e3b8b273..a5cee8d64 100644
--- a/kubernetes/client/rest.py
+++ b/kubernetes/client/rest.py
@@ -50,13 +50,18 @@ class RESTResponse(io.IOBase):

class RESTClientObject(object):

- def __init__(self, configuration, pools_size=4, maxsize=None):
+ def __init__(self, configuration, pools_size=4, maxsize=None, pool_manager=None):
# urllib3.PoolManager will pass all kw parameters to connectionpool
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
# maxsize is the number of requests to host that are allowed in parallel # noqa: E501
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501

+ # Pre-created pool manager provided
+ if pool_manager is not None:
+ self.pool_manager = pool_manager
+ return
+
# cert_reqs
if configuration.verify_ssl:
cert_reqs = ssl.CERT_REQUIRED
1 change: 1 addition & 0 deletions scripts/update-client.sh
Original file line number Diff line number Diff line change
@@ -82,6 +82,7 @@ git apply "${SCRIPT_ROOT}/rest_sni_patch.diff"
# AttributeError: 'RESTResponse' object has no attribute 'headers'
# OpenAPI client generator prior to 6.4.0 uses deprecated urllib3 APIs.
# git apply "${SCRIPT_ROOT}/rest_urllib_headers.diff"
git apply "${SCRIPT_ROOT}/rest_pool_manager.diff"

echo ">>> generating docs..."
pushd "${DOC_ROOT}" > /dev/null