-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 proto only if we have proto types #1638
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: justinsb The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
513e6cc
to
8067a1d
Compare
8067a1d
to
5a35d58
Compare
pkg/client/apiutil/apimachinery.go
Outdated
if gvkType.Kind() == reflect.Struct { | ||
gvkType = reflect.PtrTo(gvkType) | ||
} | ||
return gvkType.Implements(protoMessageType) |
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.
Is this slow enough that we should cache it? I know reflect operations can get pretty cranky sometimes.
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.
It did involve a linear scan, so I added memoization - thanks!
pkg/client/apiutil/apimachinery.go
Outdated
if gvkType.Kind() == reflect.Struct { | ||
gvkType = reflect.PtrTo(gvkType) | ||
} | ||
return gvkType.Implements(protoMessageType) |
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'm afraid the gvk type has proto definition in scheme doesn't mean the API Server could accept its requests via Protobuf. Actually for a gvk type defined by CRD, API Server can only accept JSON requests even if we implement its proto types in project.
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 if there's a way to discover if the apiserver supports proto (for a given kind)? I think we need destination-type-is-proto and apiserver-supports-proto-for-this-kind
, because if someone queries a PodList into an UnstructuredList we still want to not use proto (?).
BTW the reason that I'm looking at this code is that I'd like to eliminate most of the imports of the kubernetes API types, for controllers that generally just use unstructured.Unstructured.
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 can see this PR Use application/vnd.kubernetes.protobuf as content-type if possible I merged before, which brings Protobuf support into controller-runtime.
// Currently only enabled for built-in resources which are guaranteed to implement Protocol Buffers.
// For custom resources, CRDs can not support Protocol Buffers but Aggregated API can.
// See doc: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#advanced-features-and-flexibility
So if you want to extend the no-built-in types to use Protobuf, you have to find out whether they are defined by CRD or Aggregated API, which is hard to check. Since all types created via kubebuilder/operator-sdk are in CRD definition, I think the built-in types are enough for most ppl using controller-runtime.
WDYT @alvaroaleman
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.
Good point, I guess it is possible (and something I would love to try out!) to use proto to define CRDs locally.
I tweaked the logic therefore, there's a list of built-in types, and we have a unit test to make sure that the core kubernetes types are recognized appropriately. This should detect if there's a new built-in library added upstream, and I added a comment so that it's obvious how to add the newly-added built-in group.
This also means that we can continue to support AddToProtobufScheme.
@justinsb what problem does this PR solve? I agree it is currently a bit hard to discover how to register your api for proto usage, however the only case where this could be wanted is an extension api server that supports proto. To my knowledge, there aren't a lot of them, so this is a bit of a niche problem. |
5a35d58
to
0776b2c
Compare
602bb3c
to
0780d4f
Compare
Thanks for the reviews and comment @alvaroaleman and @coderanger . The intention here is actually the other way round; I want to eliminate all dependencies on kubernetes/scheme. Merely importing that package pulls in all the k8s API types, and that adds up to a lot more memory usage than is really needed (>500 entries in the scheme, instead of around a dozen that are really needed in a typical controller). It also causes the binary size to be much larger, though that is a secondary concern for me. This is by no means the last place we need this, but ... it's a journey! |
We should not try to use proto if the scheme does not have the protobuf representation in the go type; we won't be able to deserialize it.
0780d4f
to
9f1aac0
Compare
@justinsb: 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. |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closed this PR. In response to this:
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. |
✨ WIP: Use proto only if we have proto definitions
Even if the apiserver supports proto for a type, if we don't know the
proto schema definition we can't use it.
Therefore, detect if the type implements proto.Message when deciding
whether to use proto encoding.