Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

body=body

Does this mean users can no longer pass JSON as the body? Is this considered a breaking change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a breaking change, though I'm not sure that we intended for this to accept a string in the first place. Could add a little bit of logic to server_side_apply to attempt to yaml load the content in order to preserve that behavior if it's what we want

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that we intended for this to accept a string in the first place

I agree. I'm okay with calling it out as a breaking change in the release notes. We could provide instruction/util to help users switch/keep the behavior, but the default behavior doesn't have to accept a string.

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