Skip to content

Commit

Permalink
Merge pull request kubernetes-client#1850 from kariya-mitsuru/fix-ser…
Browse files Browse the repository at this point in the history
…ver-side-apply

Fix DynamicClient.server_side_apply
  • Loading branch information
k8s-ci-robot authored Jul 6, 2022
2 parents 2677e9c + 5529ded commit e8a10b1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 1 addition & 3 deletions kubernetes/base/dynamic/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import time
import unittest
import uuid
import json

from kubernetes.e2e_test import base
from kubernetes.client import api_client
Expand Down Expand Up @@ -527,9 +526,8 @@ def test_server_side_apply_api(self):
'ports': [{'containerPort': 80,
'protocol': 'TCP'}]}]}}

body = json.dumps(pod_manifest).encode()
resp = api.server_side_apply(
name=name, namespace='default', body=body,
namespace='default', body=pod_manifest,
field_manager='kubernetes-unittests', dry_run="All")
self.assertEqual('kubernetes-unittests', resp.metadata.managedFields[0].manager)

Expand Down
3 changes: 2 additions & 1 deletion kubernetes/client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def request(self, method, url, query_params=None, headers=None,
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
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'] = \
Expand Down
4 changes: 3 additions & 1 deletion scripts/rest_client_patch.diff
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ index 65fbe95..e174317 100644
@@ -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):
+ 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'] = \
Expand Down

0 comments on commit e8a10b1

Please sign in to comment.