-
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
KEP-3926: refactor: extract etcd3 store decode functions into an interface #127982
KEP-3926: refactor: extract etcd3 store decode functions into an interface #127982
Conversation
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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-sigs/prow repository. |
/assign @sttts |
// Decode decodes value of bytes into object. It will also | ||
// set the object resource version to rev. | ||
// On success, objPtr would be set to the object. | ||
Decode(codec runtime.Codec, versioner Versioner, value []byte, objPtr runtime.Object, rev int64) error |
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 generic is that really with a int64 rv? do we have this convention elsewhere yet on the storage level?
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.
Alternative: make rev a string, and let the etcd3 store do the conversion.
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.
and then this is really the resource version, not an etcd rev.
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.
and then we are not far from moving the while default decoder 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.
it's not generic, it applies to etcd implementation only, I have put the interface definition in the storage
folder for convenience, maybe we can put the interface definition in the storage/etcd3
folder, let me look into 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.
okay now it's etcd3.Decoder
, not storage.Decoder
b5e9090
to
ab600da
Compare
var _ Decoder = defaultDecoder{} | ||
|
||
type defaultDecoder 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.
moved from store.go as is
ab600da
to
359c3ab
Compare
/remove-sig api-machinery |
Can you point me to the PR that uses this? Am unclear why we need a custom decoder. |
/assign @serathius |
not a custom decoder, but i need to decorate the current/default one in order to wrap error I am doing the same for the transformer which is already interfaced Otherwise, i have to find every code site where these functions are invoked and make change inline. So no change in terms of actual decoding |
Sgtm. Waiting for @serathius and @wojtek-t to have the chance for feedback. |
// Decode decodes value of bytes into object. It will also | ||
// set the object resource version to rev. | ||
// On success, objPtr would be set to the object. | ||
Decode(codec runtime.Codec, versioner storage.Versioner, value []byte, objPtr runtime.Object, rev int64) error |
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 fact that we pass codec
as a parameter to Decoder
seems a bit weird to me (same for DecodeListItems below).
Shouldn't codec
be passed on initialization of Decoder (i.e. codec as a field of defaultDecoder 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.
yes, in contrast to the request scoped parameters, both codec
and versioner
are out of band and shared, so they can be promoted to member variables. Do you want me to add versioner
as a field of defaultDecoder
as well?
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.
Yeah - versioner should be there too.
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.
okay, done, please take a look when you have a moment
I have one comment about the interface itself: https://github.com/kubernetes/kubernetes/pull/127982/files#r1799072481 |
359c3ab
to
1d1a656
Compare
/remove-sig api-machinery |
/retest |
/lgtm |
LGTM label has been added. Git tree hash: a6ada18819576457982883234dece962e11d936f
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: tkashem, wojtek-t 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 |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Extract the
decode
anddecodeListItem
functions of the ectd3 store implementation as is into an interface:This is a refactor-only PR, no behavioral change.
Promoting the functions to an interface will allow us to wrap it so we can do proper error chaining without making inline changes to the store implementation code.
See #127513 to see the unsafe deletion flow
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
KEP: kubernetes/enhancements#3927