Fix (hack) rest client for patch

This commit is contained in:
mbohlool 2017-10-05 17:37:49 -07:00
parent 77a504e294
commit 789e37464b
3 changed files with 25 additions and 0 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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."