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

add generic sets to utils #243

Merged
merged 4 commits into from
May 5, 2023
Merged

Conversation

logicalhan
Copy link
Member

@logicalhan logicalhan commented Apr 19, 2022

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

We have a sets utils in pkg in k8s/k8s. This refactors that implementation to use generics instead of code-generation and moves the library here.

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 19, 2022
@liggitt
Copy link
Member

liggitt commented Apr 20, 2022

utils now requires golang 1.18

A couple thoughts:

  • as long as we have supported Kubernetes release branches that use k8s.io/utils and aren't on go1.18, I would not expect us to make the minimum version go1.18... can we use go version build tags or something similar to scope these files to go1.18 while making the rest of the module consumable by earlier versions of go?
  • we have strict go API compatibility checks on this repo... is this the best place to start experimenting with go APIs using generics? we'll be stuck with any mistakes we're unhappy with

@apelisse
Copy link
Member

  • as long as we have supported Kubernetes release branches that use k8s.io/utils and aren't on go1.18, I would not expect us to make the minimum version go1.18... can we use go version build tags or something similar to scope these files to go1.18 while making the rest of the module consumable by earlier versions of go?

Agreed, if we can have some form of conditional compilation and isolate the packages that require go1.18, that'd be nice. Otherwise, we could also branch into a requires-1.18 vs no-1.18. In case we have to make a patch to an older version, we could apply it to the no-1.18 and merge that change back into the 1.18 branch, the process is a little more involved. We can also put that process in place lazily when/if we eventually need it. How often have we needed to patch utils in a minor release?

  • we have strict go API compatibility checks on this repo... is this the best place to start experimenting with go APIs using generics? we'll be stuck with any mistakes we're unhappy with

The thing is that yeah, utils are usually the best place to start using generics :-(

@k8s-triage-robot
Copy link

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jul 21, 2022
@k8s-triage-robot
Copy link

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Aug 20, 2022
@k8s-triage-robot
Copy link

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closed this PR.

In response to this:

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

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.

@thockin
Copy link
Member

thockin commented Nov 8, 2022

We let this age-out. When do we bring it back?

@thockin thockin self-assigned this Nov 8, 2022
@logicalhan
Copy link
Member Author

/reopen

We let this age-out. When do we bring it back?

1.27 (so next release)

@k8s-ci-robot k8s-ci-robot reopened this Nov 8, 2022
@k8s-ci-robot
Copy link
Contributor

@logicalhan: Reopened this PR.

In response to this:

/reopen

We let this age-out. When do we bring it back?

1.27 (so next release)

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.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 8, 2022
@logicalhan
Copy link
Member Author

/lifecycle frozen

@k8s-ci-robot
Copy link
Contributor

@logicalhan: The lifecycle/frozen label cannot be applied to Pull Requests.

In response to this:

/lifecycle frozen

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.

@logicalhan
Copy link
Member Author

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Nov 8, 2022
@logicalhan
Copy link
Member Author

/close

@k8s-ci-robot
Copy link
Contributor

@logicalhan: Closed this PR.

In response to this:

/close

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.

sets/set.go Outdated

import "sort"

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.

The apimachinery implementation uses comparable instead (which requires Go 1.20 to work properly).

sets/set.go Outdated Show resolved Hide resolved
sets/set.go Outdated Show resolved Hide resolved
@thockin
Copy link
Member

thockin commented Apr 27, 2023

The doc on comparable is ... tricky to digest.

@skitt
Copy link
Member

skitt commented Apr 27, 2023

The doc on comparable is ... tricky to digest.

That’s putting it mildly! But I think it’s the right approach in this case (assuming a Go 1.20 bump is acceptable).

@thockin
Copy link
Member

thockin commented Apr 27, 2023

I'm trying to digest why it's OK to runtime-panic on any and how to apply the dirty trick at the end of the doc

@thockin
Copy link
Member

thockin commented Apr 27, 2023

Like: https://go.dev/play/p/vBEo5hg2mnu

It seems BETTER in 1.19 than 1.20

sets/set.go Outdated
limitations under the License.
*/

package sets
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 nitpicking, why not set - set.Set[int] or even set.S[int] ?

Or should this be containers.Set[int] or something? stl.Set[int] ? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I renamed the package to set.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 5, 2023
@logicalhan
Copy link
Member Author

So basically my plan is twofold:

(1) introduce sets using ordered type so that we can have set.SortedList
(2) once we can bump utils to golang 1.20, then I will introduce a set[comparable] which has the exact API as set[ordered] without the SortedList method. Then I will create an API compatible version of set[ordered] which delegates all calls underneath to set[comparable] and then implement SortedList on set[ordered].

Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

nits

sets/set.go Outdated Show resolved Hide resolved
sets/set.go Outdated Show resolved Hide resolved
set/ordered.go Outdated Show resolved Hide resolved
set/set.go Outdated Show resolved Hide resolved
set/set.go Outdated Show resolved Hide resolved
set/set_test.go Outdated Show resolved Hide resolved
Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

Thanks!

/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 May 5, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: logicalhan, thockin

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 May 5, 2023
@k8s-ci-robot k8s-ci-robot merged commit 9f67429 into kubernetes:master May 5, 2023
10 checks passed
@pohly
Copy link
Contributor

pohly commented May 15, 2023

once we can bump utils to golang 1.20, then I will introduce a set[comparable] which has the exact API as set[ordered] without the SortedList method. Then I will create an API compatible version of set[ordered] which delegates all calls underneath to set[comparable] and then implement SortedList on set[ordered].

Is there an issue open for tracking that? Do you already have a prototype?

skitt added a commit to skitt/operator-sdk that referenced this pull request Jul 4, 2023
Following kubernetes/utils#243 it's likely
that the k8s.io/utils version will end up being the canonical one.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
skitt added a commit to skitt/operator-sdk that referenced this pull request Jul 11, 2023
Following kubernetes/utils#243 it's likely
that the k8s.io/utils version will end up being the canonical one.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
everettraven pushed a commit to operator-framework/operator-sdk that referenced this pull request Jul 17, 2023
Following kubernetes/utils#243 it's likely
that the k8s.io/utils version will end up being the canonical one.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants