|
| 1 | +diff --git a/kubernetes/client/api/custom_objects_api.py b/kubernetes/client/api/custom_objects_api.py |
| 2 | +index 8b7bce096..23de49810 100644 |
| 3 | +--- a/kubernetes/client/api/custom_objects_api.py |
| 4 | ++++ b/kubernetes/client/api/custom_objects_api.py |
| 5 | +@@ -2760,7 +2760,7 @@ class CustomObjectsApi(object): |
| 6 | + |
| 7 | + # HTTP header `Content-Type` |
| 8 | + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 |
| 9 | +- ['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501 |
| 10 | ++ ['application/merge-patch+json']) # noqa: E501 |
| 11 | + |
| 12 | + # Authentication setting |
| 13 | + auth_settings = ['BearerToken'] # noqa: E501 |
| 14 | +@@ -2934,7 +2934,7 @@ class CustomObjectsApi(object): |
| 15 | + |
| 16 | + # HTTP header `Content-Type` |
| 17 | + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 |
| 18 | +- ['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501 |
| 19 | ++ ['application/merge-patch+json']) # noqa: E501 |
| 20 | + |
| 21 | + # Authentication setting |
| 22 | + auth_settings = ['BearerToken'] # noqa: E501 |
| 23 | +@@ -3108,7 +3108,7 @@ class CustomObjectsApi(object): |
| 24 | + |
| 25 | + # HTTP header `Content-Type` |
| 26 | + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 |
| 27 | +- ['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501 |
| 28 | ++ ['application/merge-patch+json']) # noqa: E501 |
| 29 | + |
| 30 | + # Authentication setting |
| 31 | + auth_settings = ['BearerToken'] # noqa: E501 |
| 32 | +@@ -3291,7 +3291,7 @@ class CustomObjectsApi(object): |
| 33 | + |
| 34 | + # HTTP header `Content-Type` |
| 35 | + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 |
| 36 | +- ['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501 |
| 37 | ++ ['application/merge-patch+json']) # noqa: E501 |
| 38 | + |
| 39 | + # Authentication setting |
| 40 | + auth_settings = ['BearerToken'] # noqa: E501 |
| 41 | +@@ -3474,7 +3474,7 @@ class CustomObjectsApi(object): |
| 42 | + |
| 43 | + # HTTP header `Content-Type` |
| 44 | + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 |
| 45 | +- ['application/json-patch+json', 'application/merge-patch+json', 'application/apply-patch+yaml']) # noqa: E501 |
| 46 | ++ ['application/merge-patch+json']) # noqa: E501 |
| 47 | + |
| 48 | + # Authentication setting |
| 49 | + auth_settings = ['BearerToken'] # noqa: E501 |
| 50 | +@@ -3657,7 +3657,7 @@ class CustomObjectsApi(object): |
| 51 | + |
| 52 | + # HTTP header `Content-Type` |
| 53 | + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 |
| 54 | +- ['application/json-patch+json', 'application/merge-patch+json', 'application/apply-patch+yaml']) # noqa: E501 |
| 55 | ++ ['application/merge-patch+json']) # noqa: E501 |
| 56 | + |
| 57 | + # Authentication setting |
| 58 | + auth_settings = ['BearerToken'] # noqa: E501 |
| 59 | +diff --git a/kubernetes/client/apis/__init__.py b/kubernetes/client/apis/__init__.py |
| 60 | +new file mode 100644 |
| 61 | +index 000000000..ca4b321de |
| 62 | +--- /dev/null |
| 63 | ++++ b/kubernetes/client/apis/__init__.py |
| 64 | +@@ -0,0 +1,13 @@ |
| 65 | ++from __future__ import absolute_import |
| 66 | ++import warnings |
| 67 | ++ |
| 68 | ++# flake8: noqa |
| 69 | ++ |
| 70 | ++# alias kubernetes.client.api package and print deprecation warning |
| 71 | ++from kubernetes.client.api import * |
| 72 | ++ |
| 73 | ++warnings.filterwarnings('default', module='kubernetes.client.apis') |
| 74 | ++warnings.warn( |
| 75 | ++ "The package kubernetes.client.apis is renamed and deprecated, use kubernetes.client.api instead (please note that the trailing s was removed).", |
| 76 | ++ DeprecationWarning |
| 77 | ++) |
| 78 | +diff --git a/kubernetes/client/configuration.py b/kubernetes/client/configuration.py |
| 79 | +index ff0d43b60..02d60486b 100644 |
| 80 | +--- a/kubernetes/client/configuration.py |
| 81 | ++++ b/kubernetes/client/configuration.py |
| 82 | +@@ -20,6 +20,7 @@ import urllib3 |
| 83 | + |
| 84 | + import six |
| 85 | + from six.moves import http_client as httplib |
| 86 | ++import os |
| 87 | + |
| 88 | + |
| 89 | + class Configuration(object): |
| 90 | +@@ -158,8 +159,20 @@ class Configuration(object): |
| 91 | + """ |
| 92 | + |
| 93 | + self.proxy = None |
| 94 | ++# Load proxy from environment variables (if set) |
| 95 | ++ if os.getenv("HTTPS_PROXY"): self.proxy = os.getenv("HTTPS_PROXY") |
| 96 | ++ if os.getenv("https_proxy"): self.proxy = os.getenv("https_proxy") |
| 97 | ++ if os.getenv("HTTP_PROXY"): self.proxy = os.getenv("HTTP_PROXY") |
| 98 | ++ if os.getenv("http_proxy"): self.proxy = os.getenv("http_proxy") |
| 99 | ++ self.no_proxy = None |
| 100 | ++ # Load no_proxy from environment variables (if set) |
| 101 | ++ if os.getenv("NO_PROXY"): self.no_proxy = os.getenv("NO_PROXY") |
| 102 | ++ if os.getenv("no_proxy"): self.no_proxy = os.getenv("no_proxy") |
| 103 | + """Proxy URL |
| 104 | + """ |
| 105 | ++ self.no_proxy = None |
| 106 | ++ """bypass proxy for host in the no_proxy list. |
| 107 | ++ """ |
| 108 | + self.proxy_headers = None |
| 109 | + """Proxy headers |
| 110 | + """ |
| 111 | +diff --git a/kubernetes/client/rest.py b/kubernetes/client/rest.py |
| 112 | +index 201dc43ce..43301efc3 100644 |
| 113 | +--- a/kubernetes/client/rest.py |
| 114 | ++++ b/kubernetes/client/rest.py |
| 115 | +@@ -25,6 +25,7 @@ from six.moves.urllib.parse import urlencode |
| 116 | + import urllib3 |
| 117 | + |
| 118 | + from kubernetes.client.exceptions import ApiException, ApiValueError |
| 119 | ++from requests.utils import should_bypass_proxies |
| 120 | + |
| 121 | + |
| 122 | + logger = logging.getLogger(__name__) |
| 123 | +@@ -86,7 +87,7 @@ class RESTClientObject(object): |
| 124 | + maxsize = 4 |
| 125 | + |
| 126 | + # https pool manager |
| 127 | +- if configuration.proxy: |
| 128 | ++ if configuration.proxy and not should_bypass_proxies(configuration.host, no_proxy=configuration.no_proxy or ''): |
| 129 | + self.pool_manager = urllib3.ProxyManager( |
| 130 | + num_pools=pools_size, |
| 131 | + maxsize=maxsize, |
| 132 | +diff --git a/kubernetes/test/test_api_client.py b/kubernetes/test/test_api_client.py |
| 133 | +new file mode 100644 |
| 134 | +index 000000000..486b4ac5b |
| 135 | +--- /dev/null |
| 136 | ++++ b/kubernetes/test/test_api_client.py |
| 137 | +@@ -0,0 +1,51 @@ |
| 138 | ++# coding: utf-8 |
| 139 | ++ |
| 140 | ++ |
| 141 | ++import atexit |
| 142 | ++import weakref |
| 143 | ++import unittest |
| 144 | ++ |
| 145 | ++import kubernetes |
| 146 | ++from kubernetes.client.configuration import Configuration |
| 147 | ++import urllib3 |
| 148 | ++ |
| 149 | ++class TestApiClient(unittest.TestCase): |
| 150 | ++ |
| 151 | ++ def test_context_manager_closes_threadpool(self): |
| 152 | ++ with kubernetes.client.ApiClient() as client: |
| 153 | ++ self.assertIsNotNone(client.pool) |
| 154 | ++ pool_ref = weakref.ref(client._pool) |
| 155 | ++ self.assertIsNotNone(pool_ref()) |
| 156 | ++ self.assertIsNone(pool_ref()) |
| 157 | ++ |
| 158 | ++ def test_atexit_closes_threadpool(self): |
| 159 | ++ client = kubernetes.client.ApiClient() |
| 160 | ++ self.assertIsNotNone(client.pool) |
| 161 | ++ self.assertIsNotNone(client._pool) |
| 162 | ++ atexit._run_exitfuncs() |
| 163 | ++ self.assertIsNone(client._pool) |
| 164 | ++ |
| 165 | ++ def test_rest_proxycare(self): |
| 166 | ++ |
| 167 | ++ pool = { 'proxy': urllib3.ProxyManager, 'direct': urllib3.PoolManager } |
| 168 | ++ |
| 169 | ++ for dst, proxy, no_proxy, expected_pool in [ |
| 170 | ++ ( 'http://kube.local/', None, None, pool['direct']), |
| 171 | ++ ( 'http://kube.local/', 'http://proxy.local:8080/', None, pool['proxy']), |
| 172 | ++ ( 'http://127.0.0.1:8080/', 'http://proxy.local:8080/', 'localhost,127.0.0.0/8,.local', pool['direct']), |
| 173 | ++ ( 'http://kube.local/', 'http://proxy.local:8080/', 'localhost,127.0.0.0/8,.local', pool['direct']), |
| 174 | ++ ( 'http://kube.others.com:1234/','http://proxy.local:8080/', 'localhost,127.0.0.0/8,.local', pool['proxy']), |
| 175 | ++ ( 'http://kube.others.com:1234/','http://proxy.local:8080/', '*', pool['direct']), |
| 176 | ++ ]: |
| 177 | ++ # setup input |
| 178 | ++ config = Configuration() |
| 179 | ++ setattr(config, 'host', dst) |
| 180 | ++ if proxy is not None: |
| 181 | ++ setattr(config, 'proxy', proxy) |
| 182 | ++ if no_proxy is not None: |
| 183 | ++ setattr(config, 'no_proxy', no_proxy) |
| 184 | ++ # setup done |
| 185 | ++ |
| 186 | ++ # test |
| 187 | ++ client = kubernetes.client.ApiClient(configuration=config) |
| 188 | ++ self.assertEqual( expected_pool, type(client.rest_client.pool_manager) ) |
0 commit comments