-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Add direct serializer #26251
Add direct serializer #26251
Conversation
7e10602
to
9b168fe
Compare
@@ -308,3 +310,52 @@ func (f CodecFactory) SerializerForFileExtension(extension string) (runtime.Seri | |||
} | |||
return nil, false | |||
} | |||
|
|||
type DirectCodecFactory struct { |
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.
@smarterclayton these are the important bits of this PR. Others are mostly generated code.
|
||
func (f DirectCodecFactory) EncoderForVersion(serializer runtime.Encoder, gv unversioned.GroupVersion) runtime.Encoder { | ||
return DirectCodec{ | ||
struct { |
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 would not use anonymous structs. Also, there should be a struct for this already in pkg/runtime/codecs.go
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. Called runtime.NewCodec().
A few comments |
9b168fe
to
f919da2
Compare
@smarterclayton comments addressed, PTAL. Thanks. |
I'll fix the go-vet issues after get the lgtm. |
kind.SetGroupVersionKind(gvk) | ||
defer kind.SetGroupVersionKind(oldGVK) |
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 may be better not to defer here to avoid an allocation (this will be in the critical path for some code).
err = c.Serializer.EncodeToStream(obj, stream, overrides...)
kind.SetGroupVersionKind(oldGVK)
return err
I eliminated the defer in another PR for versioning codecs.
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. I wasn't aware of that defer is costly. PTAL. Thanks!
f919da2
to
a190e49
Compare
Changes look good, if you can add some minimal Godoc this is LGTM and you can self apply. |
Oh sure. Thanks. |
a190e49
to
a381bde
Compare
Godocs added. Applying LGTM per comment. |
8aa6166
to
706005d
Compare
Added back the lgtm after trivial rebase. |
1 similar comment
@caesarxuchao - it seems that something doesn't compile now. Can you please fix? |
706005d
to
f32f396
Compare
Rebased. |
Change looks fine. |
Thanks for the confirmation. |
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
GCE e2e build/test passed for commit f32f396. |
Automatic merge from submit-queue |
@caesarxuchao Does this PR require action by the user when upgrading from 1.2.x to 1.3.0? (Think about non-developer users.) If so, please edit your first comment to have a release-note block, like in #28132. If it is just an optional feature, please change the label to just release-note. If it is not a complete feature by itself, then apply "release-note-none" label instead. |
Fix #25589. Implemented a direct codec that doesn't do conversion, but sets the group, version and kind before serialization as Clayton suggested here.
First commit is cherry-picked from #24826.
@kubernetes/sig-api-machinery