-
Notifications
You must be signed in to change notification settings - Fork 185
Support customizing “Accept” header #1428 #236
Support customizing “Accept” header #1428 #236
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Welcome @Yashks1994! |
Codecov Report
@@ Coverage Diff @@
## master #236 +/- ##
=======================================
Coverage 92.73% 92.73%
=======================================
Files 13 13
Lines 1692 1692
=======================================
Hits 1569 1569
Misses 123 123 Continue to review full report at Codecov.
|
dynamic/client.py
Outdated
]) | ||
if params.get('application/vnd.kubernetes.protobuf') is not None: | ||
header_params['Accept'] = self.client.select_header_accept([ | ||
'application/vnd.kubernetes.protobuf', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the Python client doesn't understand protobuf. What we want is g=meta.k8s.io;v=v1,application/json;as=PartialObjectMetadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's right. it's also why it's good to have a test to verify it works as expected
51e9bb8
to
b0aae73
Compare
Hi @roycaihw, @yliaog
I have added test case which is accepting the params as 'PartialObjectMetadata' and it is checking whether the kind is equal to the params or not. |
dynamic/client.py
Outdated
'application/yaml', | ||
]) | ||
if params.get('header_params') is not None: | ||
partial_object = params.get('header_params') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, header_params can be used, instead of partial_object here
dynamic/client.py
Outdated
if params.get('header_params') is not None: | ||
partial_object = params.get('header_params') | ||
if 'PartialObjectMetadata' in partial_object.get('Accept'): | ||
header_params['Accept'] = 'application/json;as=PartialObjectMetadata;v=v1;g=meta.k8s.io' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to just take whatever is passed, instead of overwriting it here, i think. so if header_params['Accept'] is present, then do nothing, otherwise, set the default ['application/json', 'application/yaml']
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to what Yu said. Let's make the dynamic client dynamic. I'm interested to see how this feature will work with things like as=Table
(what kubectl uses)
After this is merged and included in the main repo, we should have an example for this feature. /kind feature |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: roycaihw, Yashks1994 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
dynamic/client.py
Outdated
header_params['Accept'] = self.client.select_header_accept([ | ||
|
||
# User didn't specify the Accept header. Default it to json and yaml. | ||
if not 'Accept' in header_params.keys(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need .keys()
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can remove the .keys() its not much appropriate. I will make the change.
/lgtm |
/hold |
feel free to remove the hold once the case sensitivity is fixed |
dynamic/client.py
Outdated
header_params['Accept'] = self.client.select_header_accept([ | ||
|
||
# User didn't specify the Accept header. Default it to json and yaml. | ||
if not 'Accept' in header_params: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad. Header names are not case sensitive, so it should be:
if not 'Accept' in header_params or not 'accept' in header_params:
[edit] the above is wrong as well. We should allow things like aCCEpt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I run both by passing 'Accept' and 'accept', it ran fine.
{'Accept': 'application/json;as=PartialObjectMetadataList;v=v1;g=meta.k8s.io'}
PartialObjectMetadataList
meta.k8s.io/v1
{'accept': 'application/json;as=PartialObjectMetadataList;v=v1;g=meta.k8s.io'}
PartialObjectMetadataList
meta.k8s.io/v1
Still I will make the necessary change.
I think the next steps are:
|
dynamic/client.py
Outdated
# Checking Accept header if True pass the user header else default it to json and yaml. | ||
new_header_params = dict((key.lower(), value) for key, value in header_params.items()) | ||
if 'accept' in new_header_params: | ||
header_params['Accept'] = new_header_params['accept'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a user passes in an "accept" header, this will result in duplicated "Accept" and "accept" headers. You can simply do
if not 'accept' in new_header_params:
header_params['Accept'] = self.client.select_header_accept([
'application/json',
'application/yaml',
])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/lgtm |
What this PR does / why we need it:
We are adding the new header parameter in the dynamic client which helps in scenarios where the user only cares about object metadata and wants to reduce the client-side deserialisation time.
This changes will accept the header like
'application/json;as=PartialObjectMetadata;v=v1;g=meta.k8s.io'
or'application/json;as=Table;v=v1;g=meta.k8s.io'
.Which issue(s) this PR fixes:
Fixes #1428
Special notes for your reviewer:
Added the metadata field which is currently present in client-go. Now this feature will also be supporting in the python-client.
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: