Skip to content
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

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

tkashem
Copy link
Contributor

@tkashem tkashem commented Oct 10, 2024

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Extract the decode and decodeListItem functions of the ectd3 store implementation as is into an interface:

type Decoder interface {
	Decode(codec runtime.Codec, versioner Versioner, value []byte, objPtr runtime.Object, rev int64) error

	DecodeListItem(ctx context.Context, data []byte, rev uint64, codec runtime.Codec, versioner Versioner, newItemFunc func() runtime.Object) (runtime.Object, error)
}

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?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

KEP: kubernetes/enhancements#3927


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 10, 2024
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Oct 10, 2024
@tkashem
Copy link
Contributor Author

tkashem commented Oct 10, 2024

/assign @sttts

@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/etcd Categorizes an issue or PR as relevant to SIG Etcd. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 10, 2024
// 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
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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 🤔

Copy link
Contributor Author

@tkashem tkashem Oct 10, 2024

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.

Copy link
Contributor Author

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

@tkashem tkashem force-pushed the refactor-store-decoder branch from b5e9090 to ab600da Compare October 10, 2024 19:10
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 10, 2024
var _ Decoder = defaultDecoder{}

type defaultDecoder struct{}

Copy link
Contributor Author

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

@tkashem tkashem force-pushed the refactor-store-decoder branch from ab600da to 359c3ab Compare October 10, 2024 19:38
@Jefftree
Copy link
Member

/remove-sig api-machinery

@sttts
Copy link
Contributor

sttts commented Oct 11, 2024

Can you point me to the PR that uses this? Am unclear why we need a custom decoder.

@aojea
Copy link
Member

aojea commented Oct 11, 2024

/assign @serathius
/cc @wojtek-t

@tkashem
Copy link
Contributor Author

tkashem commented Oct 11, 2024

Can you point me to the PR that uses this? Am unclear why we need a custom decoder.

not a custom decoder, but i need to decorate the current/default one in order to wrap error
491c5cf#diff-1fbc86162ac0d13aef102d5145a4705624bed4e51bd1674850f5aaf24e073334R117-R139

I am doing the same for the transformer which is already interfaced
491c5cf#diff-1fbc86162ac0d13aef102d5145a4705624bed4e51bd1674850f5aaf24e073334R142-R154

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

@sttts
Copy link
Contributor

sttts commented Oct 11, 2024

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
Copy link
Member

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) ?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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

@wojtek-t
Copy link
Member

Waiting for @serathius and @wojtek-t to have the chance for feedback.

I have one comment about the interface itself: https://github.com/kubernetes/kubernetes/pull/127982/files#r1799072481

@wojtek-t wojtek-t self-assigned this Oct 14, 2024
@tkashem tkashem force-pushed the refactor-store-decoder branch from 359c3ab to 1d1a656 Compare October 14, 2024 14:05
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Oct 14, 2024
@tkashem
Copy link
Contributor Author

tkashem commented Oct 14, 2024

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Oct 14, 2024
@tkashem tkashem changed the title KEP-4795: refactor: extract etcd3 store decode functions into an interface KEP-3926: refactor: extract etcd3 store decode functions into an interface Oct 14, 2024
@tkashem
Copy link
Contributor Author

tkashem commented Oct 14, 2024

/retest

@wojtek-t
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 15, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: a6ada18819576457982883234dece962e11d936f

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 15, 2024
@k8s-ci-robot k8s-ci-robot merged commit d32e9b0 into kubernetes:master Oct 15, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.32 milestone Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/etcd Categorizes an issue or PR as relevant to SIG Etcd. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants