Skip to content

Commit

Permalink
Fix (hack) rest client for patch
Browse files Browse the repository at this point in the history
  • Loading branch information
mbohlool committed Oct 10, 2017
1 parent 77a504e commit 789e374
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kubernetes/client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def request(self, method, url, query_params=None, headers=None,
if query_params:
url += '?' + urlencode(query_params)
if re.search('json', headers['Content-Type'], re.IGNORECASE):
if headers['Content-Type'] == 'application/json-patch+json':
if not isinstance(body, list):
headers['Content-Type'] = \
'application/strategic-merge-patch+json'
request_body = None
if body is not None:
request_body = json.dumps(body)
Expand Down
15 changes: 15 additions & 0 deletions scripts/rest_client_patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/kubernetes/client/rest.py b/kubernetes/client/rest.py
index 65fbe95..e174317 100644
--- a/kubernetes/client/rest.py
+++ b/kubernetes/client/rest.py
@@ -152,6 +152,10 @@ class RESTClientObject(object):
if query_params:
url += '?' + urlencode(query_params)
if re.search('json', headers['Content-Type'], re.IGNORECASE):
+ if headers['Content-Type'] == 'application/json-patch+json':
+ if not isinstance(body, list):
+ headers['Content-Type'] = \
+ 'application/strategic-merge-patch+json'
request_body = None
if body is not None:
request_body = json.dumps(body)
6 changes: 6 additions & 0 deletions scripts/update-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ sed -i'' "s/^CLIENT_VERSION = .*/CLIENT_VERSION = \\\"${CLIENT_VERSION}\\\"/" "$
sed -i'' "s/^__version__ = .*/__version__ = \\\"${CLIENT_VERSION}\\\"/" "${CLIENT_ROOT}/__init__.py"
sed -i'' "s/^PACKAGE_NAME = .*/PACKAGE_NAME = \\\"${PACKAGE_NAME}\\\"/" "${SCRIPT_ROOT}/../setup.py"
sed -i'' "s,^DEVELOPMENT_STATUS = .*,DEVELOPMENT_STATUS = \\\"${DEVELOPMENT_STATUS}\\\"," "${SCRIPT_ROOT}/../setup.py"

# This is a terrible hack:
# first, this must be in gen repo not here
# second, this should be ported to swagger-codegen
echo ">>> patching client..."
git apply "${SCRIPT_ROOT}/rest_client_patch.diff"
echo ">>> Done."

0 comments on commit 789e374

Please sign in to comment.