Skip to content

Commit 739665e

Browse files
committed
Apply hotfixes
1 parent c206745 commit 739665e

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
@@ -1991,7 +1991,7 @@ def patch_cluster_custom_object_with_http_info(self, group, version, plural, nam
19911991

19921992
# HTTP header `Content-Type`
19931993
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
1994-
['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501
1994+
['application/merge-patch+json']) # noqa: E501
19951995

19961996
# Authentication setting
19971997
auth_settings = ['BearerToken'] # noqa: E501
@@ -2123,7 +2123,7 @@ def patch_cluster_custom_object_scale_with_http_info(self, group, version, plura
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
@@ -2255,7 +2255,7 @@ def patch_cluster_custom_object_status_with_http_info(self, group, version, plur
22552255

22562256
# HTTP header `Content-Type`
22572257
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
2258-
['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501
2258+
['application/merge-patch+json']) # noqa: E501
22592259

22602260
# Authentication setting
22612261
auth_settings = ['BearerToken'] # noqa: E501
@@ -2395,7 +2395,7 @@ def patch_namespaced_custom_object_with_http_info(self, group, version, namespac
23952395

23962396
# HTTP header `Content-Type`
23972397
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
2398-
['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501
2398+
['application/merge-patch+json']) # noqa: E501
23992399

24002400
# Authentication setting
24012401
auth_settings = ['BearerToken'] # noqa: E501
@@ -2535,7 +2535,7 @@ def patch_namespaced_custom_object_scale_with_http_info(self, group, version, na
25352535

25362536
# HTTP header `Content-Type`
25372537
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
2538-
['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501
2538+
['application/merge-patch+json']) # noqa: E501
25392539

25402540
# Authentication setting
25412541
auth_settings = ['BearerToken'] # noqa: E501
@@ -2675,7 +2675,7 @@ def patch_namespaced_custom_object_status_with_http_info(self, group, version, n
26752675

26762676
# HTTP header `Content-Type`
26772677
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
2678-
['application/json-patch+json', 'application/merge-patch+json']) # noqa: E501
2678+
['application/merge-patch+json']) # noqa: E501
26792679

26802680
# Authentication setting
26812681
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/12.0.0-snapshot/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)