Skip to content

Commit 9d5447d

Browse files
committed
Fix (hack) rest client for patch
1 parent ad7dabb commit 9d5447d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

kubernetes/client/rest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ def request(self, method, url, query_params=None, headers=None,
152152
if query_params:
153153
url += '?' + urlencode(query_params)
154154
if re.search('json', headers['Content-Type'], re.IGNORECASE):
155+
if headers['Content-Type'] == 'application/json-patch+json':
156+
if not isinstance(body, list):
157+
headers['Content-Type'] = \
158+
'application/strategic-merge-patch+json'
155159
request_body = None
156160
if body is not None:
157161
request_body = json.dumps(body)

scripts/rest_client_patch.diff

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/kubernetes/client/rest.py b/kubernetes/client/rest.py
2+
index 65fbe95..e174317 100644
3+
--- a/kubernetes/client/rest.py
4+
+++ b/kubernetes/client/rest.py
5+
@@ -152,6 +152,10 @@ class RESTClientObject(object):
6+
if query_params:
7+
url += '?' + urlencode(query_params)
8+
if re.search('json', headers['Content-Type'], re.IGNORECASE):
9+
+ if headers['Content-Type'] == 'application/json-patch+json':
10+
+ if not isinstance(body, list):
11+
+ headers['Content-Type'] = \
12+
+ 'application/strategic-merge-patch+json'
13+
request_body = None
14+
if body is not None:
15+
request_body = json.dumps(body)

scripts/update-client.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,10 @@ sed -i'' "s/^CLIENT_VERSION = .*/CLIENT_VERSION = \\\"${CLIENT_VERSION}\\\"/" "$
6565
sed -i'' "s/^__version__ = .*/__version__ = \\\"${CLIENT_VERSION}\\\"/" "${CLIENT_ROOT}/__init__.py"
6666
sed -i'' "s/^PACKAGE_NAME = .*/PACKAGE_NAME = \\\"${PACKAGE_NAME}\\\"/" "${SCRIPT_ROOT}/../setup.py"
6767
sed -i'' "s,^DEVELOPMENT_STATUS = .*,DEVELOPMENT_STATUS = \\\"${DEVELOPMENT_STATUS}\\\"," "${SCRIPT_ROOT}/../setup.py"
68+
69+
# This is a terrible hack:
70+
# first, this must be in gen repo not here
71+
# second, this should be ported to swagger-codegen
72+
echo ">>> patching client..."
73+
git apply "${SCRIPT_ROOT}/rest_client_patch.diff"
6874
echo ">>> Done."

0 commit comments

Comments
 (0)