Skip to content

Change sort to slices package#503

Merged
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
dongjiang1989:change-sort-to-slice
Apr 2, 2026
Merged

Change sort to slices package#503
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
dongjiang1989:change-sort-to-slice

Conversation

@dongjiang1989

Copy link
Copy Markdown
Member

Replace the sort package with the slices package to simplify the code.

Signed-off-by: dongjiang <dongjiang1989@126.com>
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 2, 2026
@netlify

netlify Bot commented Apr 2, 2026

Copy link
Copy Markdown

Deploy Preview for agent-sandbox canceled.

Name Link
🔨 Latest commit 3bb773c
🔍 Latest deploy log https://app.netlify.com/projects/agent-sandbox/deploys/69ce3c72683e4c0008c0af7d
@aditya-shantanu

Copy link
Copy Markdown
Collaborator

/assign @vicentefb

@natasha41575 natasha41575 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

leaving a note why I think this is a positive change; https://pkg.go.dev/sort#Slice specifically states:

Note: in many situations, the newer [slices.SortFunc](https://pkg.go.dev/slices#SortFunc) function is more ergonomic and runs faster.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 2, 2026
@aditya-shantanu

Copy link
Copy Markdown
Collaborator

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Apr 2, 2026
@justinsb

justinsb commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

/assign

sort.Slice(oldStatus.Conditions, func(i, j int) bool {
return oldStatus.Conditions[i].Type < oldStatus.Conditions[j].Type
slices.SortFunc(oldStatus.Conditions, func(a, b metav1.Condition) int {
if a.Type < b.Type {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: can we use cmp.Compare(a.Type, b.Type)? It makes the new logic easier to follow IMO

sort.Slice(claim.Status.Conditions, func(i, j int) bool {
return claim.Status.Conditions[i].Type < claim.Status.Conditions[j].Type
slices.SortFunc(claim.Status.Conditions, func(a, b metav1.Condition) int {
if a.Type < b.Type {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(Again - will cmp.Compare work?)

slices.SortFunc(candidates, func(a, b *v1alpha1.Sandbox) int {
aReady := isSandboxReady(a)
bReady := isSandboxReady(b)
if aReady != bReady {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like this; it's much clearer (with the comments!)

@justinsb

justinsb commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

I had a nit about using cmp.Compare, but it's such a small nit I don't want to hold up the PR

/approve
/lgtm

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dongjiang1989, justinsb

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 2, 2026
@k8s-ci-robot k8s-ci-robot merged commit 62fd150 into kubernetes-sigs:main Apr 2, 2026
10 checks passed
@dongjiang1989 dongjiang1989 deleted the change-sort-to-slice branch April 3, 2026 00:28
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

6 participants