Skip to content

Commit 02b6daf

Browse files
committed
apply hotfix no_proxy support
1 parent 2832f62 commit 02b6daf

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

kubernetes/client/configuration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ def __init__(self, host=None,
206206
self.proxy = None
207207
"""Proxy URL
208208
"""
209+
self.no_proxy = None
210+
"""bypass proxy for host in the no_proxy list.
211+
"""
209212
self.proxy_headers = None
210213
"""Proxy headers
211214
"""

kubernetes/client/rest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import urllib3
2525

2626
from kubernetes.client.exceptions import ApiException, UnauthorizedException, ForbiddenException, NotFoundException, ServiceException, ApiValueError
27+
from requests.utils import should_bypass_proxies
2728

2829

2930
logger = logging.getLogger(__name__)
@@ -81,7 +82,7 @@ def __init__(self, configuration, pools_size=4, maxsize=None):
8182
maxsize = 4
8283

8384
# https pool manager
84-
if configuration.proxy:
85+
if configuration.proxy and not should_bypass_proxies(configuration.host, no_proxy=configuration.no_proxy or ''):
8586
self.pool_manager = urllib3.ProxyManager(
8687
num_pools=pools_size,
8788
maxsize=maxsize,

kubernetes/test/test_api_client.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,28 @@ def test_atexit_closes_threadpool(self):
2424
self.assertIsNotNone(client._pool)
2525
atexit._run_exitfuncs()
2626
self.assertIsNone(client._pool)
27+
28+
def test_rest_proxycare(self):
29+
30+
pool = { 'proxy': urllib3.ProxyManager, 'direct': urllib3.PoolManager }
31+
32+
for dst, proxy, no_proxy, expected_pool in [
33+
( 'http://kube.local/', None, None, pool['direct']),
34+
( 'http://kube.local/', 'http://proxy.local:8080/', None, pool['proxy']),
35+
( 'http://127.0.0.1:8080/', 'http://proxy.local:8080/', 'localhost,127.0.0.0/8,.local', pool['direct']),
36+
( 'http://kube.local/', 'http://proxy.local:8080/', 'localhost,127.0.0.0/8,.local', pool['direct']),
37+
( 'http://kube.others.com:1234/','http://proxy.local:8080/', 'localhost,127.0.0.0/8,.local', pool['proxy']),
38+
( 'http://kube.others.com:1234/','http://proxy.local:8080/', '*', pool['direct']),
39+
]:
40+
# setup input
41+
config = Configuration()
42+
setattr(config, 'host', dst)
43+
if proxy is not None:
44+
setattr(config, 'proxy', proxy)
45+
if no_proxy is not None:
46+
setattr(config, 'no_proxy', no_proxy)
47+
# setup done
48+
49+
# test
50+
client = kubernetes.client.ApiClient(configuration=config)
51+
self.assertEqual( expected_pool, type(client.rest_client.pool_manager) )

0 commit comments

Comments
 (0)