Merge pull request #124514 from brianpursley/fix-sort

Change non-quantity strings to sort alphanumerically, instead of using "Natural Sort"

Kubernetes-commit: f281a02d236d1112009c54062b99972ea6e4e731
This commit is contained in:
Kubernetes Publisher 2024-05-07 11:46:30 -07:00
commit 0f357874d3
3 changed files with 3 additions and 8 deletions

1
go.mod
View File

@ -12,7 +12,6 @@ require (
github.com/evanphx/json-patch v4.12.0+incompatible
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d
github.com/fatih/camelcase v1.0.0
github.com/fvbommel/sortorder v1.1.0
github.com/go-openapi/jsonreference v0.20.2
github.com/google/gnostic-models v0.6.8
github.com/google/go-cmp v0.6.0

2
go.sum
View File

@ -34,8 +34,6 @@ github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d h1:105gxyaGwC
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
github.com/fvbommel/sortorder v1.1.0 h1:fUmoe+HLsBTctBDoaBwpQo5N+nrCp8g/BjKb/6ZQmYw=
github.com/fvbommel/sortorder v1.1.0/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=

View File

@ -32,8 +32,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/printers"
"k8s.io/client-go/util/jsonpath"
"github.com/fvbommel/sortorder"
)
// SortingPrinter sorts list types before delegating to another printer.
@ -180,7 +178,7 @@ func isLess(i, j reflect.Value) (bool, error) {
case reflect.Float32, reflect.Float64:
return i.Float() < j.Float(), nil
case reflect.String:
return sortorder.NaturalLess(i.String(), j.String()), nil
return i.String() < j.String(), nil
case reflect.Pointer:
return isLess(i.Elem(), j.Elem())
case reflect.Struct:
@ -274,11 +272,11 @@ func isLess(i, j reflect.Value) (bool, error) {
// check if it's a Quantity
itypeQuantity, err := resource.ParseQuantity(itype)
if err != nil {
return sortorder.NaturalLess(itype, jtype), nil
return itype < jtype, nil
}
jtypeQuantity, err := resource.ParseQuantity(jtype)
if err != nil {
return sortorder.NaturalLess(itype, jtype), nil
return itype < jtype, nil
}
// Both strings are quantity
return itypeQuantity.Cmp(jtypeQuantity) < 0, nil