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 @@ 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 diff --git a/scripts/rest_pool_manager.diff b/scripts/rest_pool_manager.diff new file mode 100644 index 000000000..479bace13 --- /dev/null +++ b/scripts/rest_pool_manager.diff @@ -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 diff --git a/scripts/update-client.sh b/scripts/update-client.sh index 2b0ce7be1..1eece1f05 100755 --- a/scripts/update-client.sh +++ b/scripts/update-client.sh @@ -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