From 789e37464b8512ee4687ecf03221ff088afde450 Mon Sep 17 00:00:00 2001 From: mbohlool Date: Thu, 5 Oct 2017 17:37:49 -0700 Subject: [PATCH] Fix (hack) rest client for patch --- kubernetes/client/rest.py | 4 ++++ scripts/rest_client_patch.diff | 15 +++++++++++++++ scripts/update-client.sh | 6 ++++++ 3 files changed, 25 insertions(+) create mode 100644 scripts/rest_client_patch.diff diff --git a/kubernetes/client/rest.py b/kubernetes/client/rest.py index 5716565df..9889b1295 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) diff --git a/scripts/rest_client_patch.diff b/scripts/rest_client_patch.diff new file mode 100644 index 000000000..b47e6e0a7 --- /dev/null +++ b/scripts/rest_client_patch.diff @@ -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) diff --git a/scripts/update-client.sh b/scripts/update-client.sh index 6e02f5019..118d95b22 100755 --- a/scripts/update-client.sh +++ b/scripts/update-client.sh @@ -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."