Skip to content

Conversation

@pjsharath28
Copy link
Contributor

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

The github.com/google/btree library used by k8s and etcd has been archived and is no longer maintained. This raises long-term concerns around security fixes and CVEs.

We discussed multiple options to address this in the issue. Given that we only rely on a single source file from the library, we concluded that copying the code into k8s.io/utils is the simplest option. This avoids introducing or maintaining a separate fork while preserving identical behaviour.

Which issue(s) this PR is related to:

Discussion issue: etcd-io/etcd#20991

Special notes for your reviewer:

Upstream Google attribution is preserved and the file header follows Kubernetes conventions while remaining Apache-2.0 compliant.

Does this PR introduce a user-facing change?

NONE

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


@k8s-ci-robot k8s-ci-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Dec 17, 2025
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 17, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @pjsharath28!

It looks like this is your first PR to kubernetes/utils 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/utils has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 17, 2025
@aojea
Copy link
Member

aojea commented Dec 17, 2025

/assign @dims

side note @dims, it seems the github actions are waiting for manual approval, you can change that option in in the repo settings IIRC so they always run

Comment on lines 19 to 23
// In Go 1.18 and beyond, a BTreeG generic is created, and BTree is a specific
// instantiation of that generic for the Item interface, with a backwards-
// compatible API. Before go1.18, generics are not supported,
// and BTree is just an implementation based around the Item interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn’t relevant and should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Comment on lines 61 to 64
// There are two implementations; those suffixed with 'G' are generics, usable
// for any type, and require a passed-in "less" function to define their ordering.
// Those without this prefix are specific to the 'Item' interface, and use
// its 'Less' function for ordering.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k/k only uses the generic implementation, do we need to keep both in utils?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally not needed, I removed the non-generic implementation

@pjsharath28 pjsharath28 force-pushed the migrate-btree-to-k8s-util branch from d458954 to af10f52 Compare December 22, 2025 07:19
@pjsharath28
Copy link
Contributor Author

/retest

@k8s-ci-robot
Copy link
Contributor

@pjsharath28: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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.

@pjsharath28 pjsharath28 requested a review from skitt December 22, 2025 07:32
btree/btree.go Outdated
// BTree has its own FreeList, but multiple BTrees can share the same
// FreeList, in particular when they're created with Clone.
// Two Btrees using the same freelist are safe for concurrent write access.
type FreeListG[T any] struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we’re only keeping the generic variant, the G suffix isn’t necessary; please remove it throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@pjsharath28 pjsharath28 requested a review from skitt December 23, 2025 09:54
btree/btree.go Outdated
type ItemIterator[T any] func(item T) bool

// Ordered represents the set of types for which the '<' operator work.
type Ordered interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed this previously, sorry — please use cmp.Ordered instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks
I've resolved it as well

@pjsharath28 pjsharath28 requested a review from skitt December 24, 2025 15:41
@pjsharath28
Copy link
Contributor Author

@skitt, @dims, I've addressed all comments.
Please review when you're back. Thanks.

@dims
Copy link
Member

dims commented Dec 29, 2025

@pjsharath28 can you please move the code to third_party/forked so it is pretty clear where we got this from?

see the existing code in there and the additional files that give it context (we have one in there forked from golang)

@skitt
Copy link
Member

skitt commented Jan 5, 2026

/lgtm

Thanks! cmp.Less could be used instead of functions returned by Less but at a slight additional cost (related to NaN handling), but it’s not particularly important IMO and changes the API slightly compared to the original project.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 5, 2026
@dims
Copy link
Member

dims commented Jan 5, 2026

please add LICENSE - https://github.com/google/btree/blob/master/LICENSE

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 5, 2026
@dims
Copy link
Member

dims commented Jan 5, 2026

hmmm 68cb205 is not a license :)

@dims
Copy link
Member

dims commented Jan 5, 2026

@pjsharath28 please squash and we are good to goo

@pjsharath28 pjsharath28 force-pushed the migrate-btree-to-k8s-util branch from 0a3a1ef to aa383d1 Compare January 5, 2026 14:29
@dims
Copy link
Member

dims commented Jan 5, 2026

/approve
/lgtm

/hold

@pohly please remove hold when happy :)

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 5, 2026
@pohly
Copy link
Contributor

pohly commented Jan 5, 2026

please squash and we are good to go

Hmm, now there's only a single commit, but quite a bit was changed:

$ diff -r third_party/forked/golang/btree /tmp/btree | diffstat
 .git                  |only
 .github               |only
 LICENSE               |    2 -
 README.md             |   11 +++--
 btree.go              |  481 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------------------------------------------------------------------------------
 btree_generic.go      |only
 btree_generic_test.go |only
 btree_mem.go          |only
 btree_test.go         |  462 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------
 go.mod                |only
 10 files changed, 508 insertions(+), 448 deletions(-)

I think it would be nicer if the first commit had just a verbatim copy of the upstream code that we want (i.e. removing files that we don't care about is fine) and the second commit contains our changes.

@pjsharath28 pjsharath28 force-pushed the migrate-btree-to-k8s-util branch from aa383d1 to f2dbb5e Compare January 6, 2026 08:12
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 6, 2026
@pohly
Copy link
Contributor

pohly commented Jan 6, 2026

The update has some comment changes, but those seem benign except that we now have "See http://godoc.org/github.com/google/btree for documentation." again. I think that should be removed in the second commit.

The commits now allow reviewing the history of the code: 👍

@pjsharath28 pjsharath28 force-pushed the migrate-btree-to-k8s-util branch from f2dbb5e to d87c826 Compare January 6, 2026 10:29
@pohly
Copy link
Contributor

pohly commented Jan 6, 2026

/lgtm

Based on #336 (comment) and only one minor diff compared to the already approved version.

Not sure whether that's worth fixing?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 6, 2026
@pjsharath28 pjsharath28 force-pushed the migrate-btree-to-k8s-util branch from d87c826 to cec797e Compare January 6, 2026 10:56
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 6, 2026
@pohly
Copy link
Contributor

pohly commented Jan 6, 2026

@pjsharath28: thanks for your patience!

/lgtm
/hold cancel

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jan 6, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dims, pjsharath28, pohly, skitt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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 merged commit 0fe9cd7 into kubernetes:master Jan 6, 2026
2 checks passed
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. 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants