python/scripts/rest_client_patch.diff
Mitsuru Kariya 5529dedcb3
Fix DynamicClient.server_side_apply
DynamicClient.server_side_apply is designed to accept a dict or a
ResourceInstance as body.  However, if a dict or a ResourceInstance is
passed actually, an error occurs because RESTClientObject.rest cannot
interpret the Content-Type application/apply-patch+yaml.

So, modify RESTClientObject.rest to treat application/apply-patch+yaml
as other json-based Content-Types.
2022-07-06 01:16:57 +09:00

18 lines
961 B
Diff

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 (re.search('json', headers['Content-Type'], re.IGNORECASE) or
+ headers['Content-Type'] == 'application/apply-patch+yaml'):
+ 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)