Skip to content

Commit a7008b0

Browse files
committed
Reset to openapi-generator artifacts
We will subsequently overlay our own commits on this. We also stop setting OPENAPI_GENERATOR_COMMIT: this is already being set by the 'openapi/python.sh' from 'kubernetes-client/gen' so setting it here is very misleading. With this change, any user should now be able to run e.g.: USERNAME=kubernetes CLIENT_ROOT=../kubernetes ./scripts/update-client.sh and see zero changes (assuming kubernetes/kubernetes is in fact cloned to the parent directory). Signed-off-by: Stephen Finucane <[email protected]>
1 parent 59885b6 commit a7008b0

File tree

2 files changed

+196
-5
lines changed

2 files changed

+196
-5
lines changed

scripts/hotfixes.diff

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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) )

scripts/update-client.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ set -o errexit
2121
set -o nounset
2222
set -o pipefail
2323

24-
# The openapi-generator version used by this client
25-
export OPENAPI_GENERATOR_COMMIT="v4.3.0"
26-
2724
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
2825
CLIENT_ROOT="${SCRIPT_ROOT}/../kubernetes"
2926
CLIENT_VERSION=$(python "${SCRIPT_ROOT}/constants.py" CLIENT_VERSION)
@@ -61,7 +58,12 @@ echo ">>> Running python generator from the gen repo"
6158
"${GEN_ROOT}/openapi/python.sh" "${CLIENT_ROOT}" "${SETTING_FILE}"
6259
mv "${CLIENT_ROOT}/swagger.json" "${SCRIPT_ROOT}/swagger.json"
6360

64-
echo ">>> updating version information..."
61+
# This is a hack: openapi-generator shouldn't be producing syntactically
62+
# incorrect tests
63+
echo ">>> Removing broken tests"
64+
git clean -fd -- kubernetes/test/
65+
66+
echo ">>> Updating version information..."
6567
sed -i'' "s/^CLIENT_VERSION = .*/CLIENT_VERSION = \\\"${CLIENT_VERSION}\\\"/" "${SCRIPT_ROOT}/../setup.py"
6668
sed -i'' "s/^__version__ = .*/__version__ = \\\"${CLIENT_VERSION}\\\"/" "${CLIENT_ROOT}/__init__.py"
6769
sed -i'' "s/^PACKAGE_NAME = .*/PACKAGE_NAME = \\\"${PACKAGE_NAME}\\\"/" "${SCRIPT_ROOT}/../setup.py"
@@ -70,7 +72,8 @@ sed -i'' "s,^DEVELOPMENT_STATUS = .*,DEVELOPMENT_STATUS = \\\"${DEVELOPMENT_STAT
7072
# This is a terrible hack:
7173
# first, this must be in gen repo not here
7274
# second, this should be ported to swagger-codegen
73-
echo ">>> patching client..."
75+
echo ">>> Patching client..."
76+
git apply "${SCRIPT_ROOT}/hotfixes.diff"
7477
git apply "${SCRIPT_ROOT}/rest_client_patch.diff"
7578
# The fix this patch is trying to make is already in the upstream swagger-codegen
7679
# repo but it's not in the version we're using. We can remove this patch

0 commit comments

Comments
 (0)