Skip to content

Commit 043429a

Browse files
committed
Fallback to merge patch
Add fallback to merge patch if strategic merge patch is unavailable, as is the case for the custom objects API.
1 parent 84e4e28 commit 043429a

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

examples/patch.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ async def main():
9999
SERVICE_NAME,
100100
SERVICE_NS,
101101
patch,
102-
_content_type="application/merge-patch+json", # required to force merge patch
102+
# required to force merge patch when strategic merge patch would otherwise be used
103+
_content_type="application/merge-patch+json",
103104
)
104105

105106

kubernetes_asyncio/client/api_client.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,13 @@ def select_header_content_type(self, content_types, method=None, body=None):
539539
if ('application/json-patch+json' in content_types and
540540
isinstance(body, list)):
541541
return 'application/json-patch+json'
542-
if ('application/strategic-merge-patch+json' in content_types and
543-
(isinstance(body, dict) or hasattr(body, "to_dict"))):
544-
return 'application/strategic-merge-patch+json'
542+
if isinstance(body, dict) or hasattr(body, "to_dict"):
543+
if 'application/strategic-merge-patch+json' in content_types:
544+
return 'application/strategic-merge-patch+json'
545+
elif 'application/merge-patch+json' in content_types:
546+
# Intended for cases where strategic merge patch is not
547+
# supported, like when patching custom objects.
548+
return 'application/merge-patch+json'
545549

546550
if 'application/json' in content_types or '*/*' in content_types:
547551
return 'application/json'
+13-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
--- /tmp/api_client.py 2024-02-25 20:40:28.143350042 +0100
2-
+++ kubernetes_asyncio/client/api_client.py 2024-02-25 20:40:32.954201652 +0100
3-
@@ -535,10 +535,13 @@
4-
1+
--- /tmp/api_client.py 2024-12-18 03:36:59.552742383 +0000
2+
+++ kubernetes_asyncio/client/api_client.py 2024-12-18 03:36:11.062928089 +0000
3+
@@ -535,10 +535,17 @@
4+
55
content_types = [x.lower() for x in content_types]
6-
6+
77
- if (method == 'PATCH' and
88
- 'application/json-patch+json' in content_types and
99
- isinstance(body, list)):
@@ -12,9 +12,13 @@
1212
+ if ('application/json-patch+json' in content_types and
1313
+ isinstance(body, list)):
1414
+ return 'application/json-patch+json'
15-
+ if ('application/strategic-merge-patch+json' in content_types and
16-
+ (isinstance(body, dict) or hasattr(body, "to_dict"))):
17-
+ return 'application/strategic-merge-patch+json'
18-
15+
+ if isinstance(body, dict) or hasattr(body, "to_dict"):
16+
+ if 'application/strategic-merge-patch+json' in content_types:
17+
+ return 'application/strategic-merge-patch+json'
18+
+ elif 'application/merge-patch+json' in content_types:
19+
+ # Intended for cases where strategic merge patch is not
20+
+ # supported, like when patching custom objects.
21+
+ return 'application/merge-patch+json'
22+
1923
if 'application/json' in content_types or '*/*' in content_types:
2024
return 'application/json'

scripts/update-client.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pushd "${CLIENT_ROOT}" > /dev/null
3535
CLIENT_ROOT=`pwd`
3636
popd > /dev/null
3737

38-
TEMP_FOLDER=$(mktemp -d)
38+
TEMP_FOLDER=$(mktemp -d)
3939
trap "rm -rf ${TEMP_FOLDER}" EXIT SIGINT
4040

4141
SETTING_FILE="${TEMP_FOLDER}/settings"

0 commit comments

Comments
 (0)