Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04dc174

Browse files
committed
Apply hotfixes
1 parent 3ef3dd4 commit 04dc174

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

kubernetes/client/api/custom_objects_api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ def patch_cluster_custom_object_with_http_info(self, group, version, plural, nam
17191719

17201720
# HTTP header `Content-Type`
17211721
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
1722-
['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501
1722+
['application/merge-patch+json']) # noqa: E501
17231723

17241724
# Authentication setting
17251725
auth_settings = ['BearerToken'] # noqa: E501
@@ -1851,7 +1851,7 @@ def patch_cluster_custom_object_scale_with_http_info(self, group, version, plura
18511851

18521852
# HTTP header `Content-Type`
18531853
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
1854-
['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501
1854+
['application/merge-patch+json']) # noqa: E501
18551855

18561856
# Authentication setting
18571857
auth_settings = ['BearerToken'] # noqa: E501
@@ -1983,7 +1983,7 @@ def patch_cluster_custom_object_status_with_http_info(self, group, version, plur
19831983

19841984
# HTTP header `Content-Type`
19851985
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
1986-
['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501
1986+
['application/merge-patch+json']) # noqa: E501
19871987

19881988
# Authentication setting
19891989
auth_settings = ['BearerToken'] # noqa: E501
@@ -2123,7 +2123,7 @@ def patch_namespaced_custom_object_with_http_info(self, group, version, namespac
21232123

21242124
# HTTP header `Content-Type`
21252125
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
2126-
['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501
2126+
['application/merge-patch+json']) # noqa: E501
21272127

21282128
# Authentication setting
21292129
auth_settings = ['BearerToken'] # noqa: E501
@@ -2263,7 +2263,7 @@ def patch_namespaced_custom_object_scale_with_http_info(self, group, version, na
22632263

22642264
# HTTP header `Content-Type`
22652265
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
2266-
['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501
2266+
['application/merge-patch+json']) # noqa: E501
22672267

22682268
# Authentication setting
22692269
auth_settings = ['BearerToken'] # noqa: E501
@@ -2403,7 +2403,7 @@ def patch_namespaced_custom_object_status_with_http_info(self, group, version, n
24032403

24042404
# HTTP header `Content-Type`
24052405
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
2406-
['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501
2406+
['application/merge-patch+json']) # noqa: E501
24072407

24082408
# Authentication setting
24092409
auth_settings = ['BearerToken'] # noqa: E501

kubernetes/client/api_client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from __future__ import absolute_import
1212

13+
import atexit
1314
import datetime
1415
import json
1516
import mimetypes
@@ -77,18 +78,27 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
7778
# Set default User-Agent.
7879
self.user_agent = 'OpenAPI-Generator/11.0.0/python'
7980

80-
def __del__(self):
81+
def __enter__(self):
82+
return self
83+
84+
def __exit__(self, exc_type, exc_value, traceback):
85+
self.close()
86+
87+
def close(self):
8188
if self._pool:
8289
self._pool.close()
8390
self._pool.join()
8491
self._pool = None
92+
if hasattr(atexit, 'unregister'):
93+
atexit.unregister(self.close)
8594

8695
@property
8796
def pool(self):
8897
"""Create thread pool on first request
8998
avoids instantiating unused threadpool for blocking clients.
9099
"""
91100
if self._pool is None:
101+
atexit.register(self.close)
92102
self._pool = ThreadPool(self.pool_threads)
93103
return self._pool
94104

kubernetes/client/apis/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from __future__ import absolute_import
2+
import warnings
3+
4+
# flake8: noqa
5+
6+
# alias kubernetes.client.api package and print deprecation warning
7+
from kubernetes.client.api import *
8+
9+
warnings.filterwarnings('default', module='kubernetes.client.apis')
10+
warnings.warn(
11+
"The package kubernetes.client.apis is renamed and deprecated, use kubernetes.client.api instead (please note that the trailing s was removed).",
12+
DeprecationWarning
13+
)

kubernetes/test/test_api_client.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# coding: utf-8
2+
3+
4+
import atexit
5+
import weakref
6+
import unittest
7+
8+
import kubernetes
9+
10+
11+
class TestApiClient(unittest.TestCase):
12+
13+
def test_context_manager_closes_threadpool(self):
14+
with kubernetes.client.ApiClient() as client:
15+
self.assertIsNotNone(client.pool)
16+
pool_ref = weakref.ref(client._pool)
17+
self.assertIsNotNone(pool_ref())
18+
self.assertIsNone(pool_ref())
19+
20+
def test_atexit_closes_threadpool(self):
21+
client = kubernetes.client.ApiClient()
22+
self.assertIsNotNone(client.pool)
23+
self.assertIsNotNone(client._pool)
24+
atexit._run_exitfuncs()
25+
self.assertIsNone(client._pool)

0 commit comments

Comments
 (0)