New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
⚠️ Use application/vnd.kubernetes.protobuf as content-type if possible #1149
⚠️ Use application/vnd.kubernetes.protobuf as content-type if possible #1149
Conversation
Welcome @FillZpp! |
Hi @FillZpp. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
/assign @alvaroaleman |
pkg/client/apiutil/apimachinery.go
Outdated
@@ -93,5 +102,8 @@ func createRestConfig(gvk schema.GroupVersionKind, baseConfig *rest.Config) *res | |||
if cfg.UserAgent == "" { | |||
cfg.UserAgent = rest.DefaultKubernetesUserAgent() | |||
} | |||
if cfg.ContentType == "" && localScheme.Recognizes(gvk) { |
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.
So you copy the client-go scheme so this is only used for built-in types? Are you sure protobuf works for all built-in types on all kube server versions? Does upstream have any docs on this?
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.
Do you know what happens if we request protobuf for a type that doesn't support it, is there maybe some way to negotiate?
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.
So you copy the client-go scheme so this is only used for built-in types?
Yes, this is only used for built-in resources. For custom resources, CRDs
can not support Protocol Buffers but Aggregated API
can. You can see it in this table.
Are you sure protobuf works for all built-in types on all kube server versions? Does upstream have any docs on this?
All built-in resources are guaranteed to implement Protocal Buffers:
- This design doc for contributors says protobuf schema for each API group and version in k8s.io/api will be generated from the objects in that API group and version.
- hack/update-generated-protobuf.sh in Kubernetes repo will find all packages contains
+k8s:protobuf-gen=package
and generate protobuf schema for them. And all API definition package must contain a doc.go which has these comments:
// +k8s:deepcopy-gen=package
// +k8s:protobuf-gen=packag
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.
missed this comment. I think this should probably be a bit less magic, since this ignores aggregated api servers or any future improvements to CRDs. This is probably fine in the short run, but in the long run I think we want to check discovery or something to make sure that this is actually true.
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.
Understand, but currently there is no way to check if a resource type supports protobuf or not. I have added a TODO
to describe this.
pkg/client/apiutil/apimachinery.go
Outdated
@@ -93,5 +102,8 @@ func createRestConfig(gvk schema.GroupVersionKind, baseConfig *rest.Config) *res | |||
if cfg.UserAgent == "" { | |||
cfg.UserAgent = rest.DefaultKubernetesUserAgent() | |||
} | |||
if cfg.ContentType == "" && localScheme.Recognizes(gvk) { | |||
cfg.ContentType = "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.
Nit: Can you use runtime.ContentTypeProtobuf
here?
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
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.
/approve
/hold
/assign @DirectXMan12
/ok-to-test |
9077fb6
to
a8946c3
Compare
a8946c3
to
5a22a5f
Compare
pkg/client/apiutil/apimachinery.go
Outdated
) | ||
|
||
func init() { | ||
_ = clientgoscheme.AddToScheme(localScheme) |
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.
this should not be using some sort of magic private scheme -- we should be using the user's passed-in scheme. That way, if the user also defines protobuf support for their types (e.g. aggregated api servers, if we get proto support in the future for CRDs, etc) it'll just work.
EDIT: missed the comment above, responding up there.
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
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.
Nit: Can we panic here if this fails?
_, isUnstructuredList := obj.(*unstructured.UnstructuredList) | ||
isUnstructured = isUnstructured || isUnstructuredList | ||
|
||
resourceByType := c.structuredResourceByType |
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.
move this so that it's under the lock
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
9176b46
to
3abb8c6
Compare
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.
Some nits, other than that it looks good. Also this change is breaking due to the signature change of RESTClientForGVK
.
pkg/client/apiutil/apimachinery.go
Outdated
) | ||
|
||
func init() { | ||
_ = clientgoscheme.AddToScheme(localScheme) |
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.
Nit: Can we panic here if this fails?
pkg/client/apiutil/apimachinery.go
Outdated
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/restmapper" | ||
) | ||
|
||
var ( | ||
localScheme = runtime.NewScheme() |
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.
Nit: Can we rename to "protobufScheme"? The current name is a bit too generic IMHO
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.
All done
3abb8c6
to
00b4b34
Compare
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.
/lgtm
leaving hold cancel to @DirectXMan12
and thanks for your work, this is a great change! |
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.
LGTM
/milestone v0.7.x
PTAL @DirectXMan12 when you have time |
Retitling because this PR includes a breaking change in RESTClientForGVK |
Are we ok unholding this change? @alvaroaleman @DirectXMan12 |
pkg/client/apiutil/apimachinery.go
Outdated
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/restmapper" | ||
) | ||
|
||
var ( | ||
protobufScheme = runtime.NewScheme() |
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.
Actually one nit: Can we add a setter for this so projects that have additional apis that do support protobuf (metrics-server, all the openshift apis that are served via its aggregated apiserver) can add themselves here?
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 am also fine doing a quick follow-up for that and merging this PR as-is
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.
Actually one nit: Can we add a setter for this so projects that have additional apis that do support protobuf (metrics-server, all the openshift apis that are served via its aggregated apiserver) can add themselves here?
Sure. How about provide a function in pkg/client/apiutil/apimachinery.go
?
func AdditionalProtobufScheme(builder runtime.SchemeBuilder) error {
return builder.AddToScheme(protobufScheme)
}
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.
Sounds good to me. Could you also add a small godoc comment explaining it?
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.
How about AddToProtobufScheme
to make the experience familiar with the other AddToScheme methods?
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 have add this func and a RWMutex to avoid race modification of protobufScheme.
PTAL @alvaroaleman @vincepri
Signed-off-by: Siyu Wang <FillZpp.pub@gmail.com>
00b4b34
to
7c26bc0
Compare
@FillZpp: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. |
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.
/lgtm
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.
/approve
@alvaroaleman good to unhold?
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, FillZpp, vincepri 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 |
/hold cancel |
Signed-off-by: Siyu Wang FillZpp.pub@gmail.com
Use
application/vnd.kubernetes.protobuf
as content-type if it is possible, currently for those native resources defined in client-go.