Deprecate obsolete slice utility functions

... and update users to use standard library functions.

Signed-off-by: Stephen Kitt <skitt@redhat.com>

Kubernetes-commit: d42d1e3d1f73ac2975b89f9482c2ecfaeeed13f6
This commit is contained in:
Stephen Kitt 2025-07-15 09:02:48 +02:00 committed by Kubernetes Publisher
parent 13dec8331a
commit 2e358d6313
2 changed files with 21 additions and 23 deletions

View file

@ -81,7 +81,6 @@ import (
"k8s.io/kubectl/pkg/util/qos"
"k8s.io/kubectl/pkg/util/rbac"
resourcehelper "k8s.io/kubectl/pkg/util/resource"
"k8s.io/kubectl/pkg/util/slice"
storageutil "k8s.io/kubectl/pkg/util/storage"
)
@ -312,7 +311,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
switch typedValue := value.(type) {
case map[string]interface{}:
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
if slice.Contains[string](skip, skipExpr, nil) {
if slices.Contains(skip, skipExpr) {
continue
}
w.Write(level, "%s:\n", smartLabelFor(field))
@ -320,7 +319,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
case []interface{}:
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
if slice.Contains[string](skip, skipExpr, nil) {
if slices.Contains(skip, skipExpr) {
continue
}
w.Write(level, "%s:\n", smartLabelFor(field))
@ -335,7 +334,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
default:
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
if slice.Contains[string](skip, skipExpr, nil) {
if slices.Contains(skip, skipExpr) {
continue
}
w.Write(level, "%s:\t%v\n", smartLabelFor(field), typedValue)
@ -383,7 +382,7 @@ func smartLabelFor(field string) string {
continue
}
if slice.Contains(commonAcronyms, strings.ToUpper(part), nil) {
if slices.Contains(commonAcronyms, strings.ToUpper(part)) {
part = strings.ToUpper(part)
} else if strings.ToLower(part) == part {
part = cases.Title(language.English).String(part)

View file

@ -18,36 +18,35 @@ package slice
import "slices"
// SortInts64 sorts []int64 in increasing order
// SortInts64 sorts []int64 in increasing order.
//
// Deprecated: Use slices.Sort instead.
//
//go:fix inline
func SortInts64(a []int64) { slices.Sort(a) }
// Contains checks if a given slice of type T contains the provided item.
// If a modifier func is provided, it is called with the slice item before the comparation.
//
// Deprecated: Use slices.Contains or slices.ContainsFunc instead.
func Contains[T comparable](slice []T, s T, modifier func(s T) T) bool {
for _, item := range slice {
if item == s {
return true
}
if modifier != nil && modifier(item) == s {
return true
}
if slices.Contains(slice, s) {
return true
}
if modifier != nil {
return slices.ContainsFunc(slice, func(item T) bool { return modifier(item) == s })
}
return false
}
// ContainsString checks if a given slice of strings contains the provided string.
// If a modifier func is provided, it is called with the slice item before the comparation.
// Deprecated: Use Contains[T] instead
//
// Deprecated: Use slices.Contains or slices.ContainsFunc instead.
//
//go:fix inline
func ContainsString(slice []string, s string, modifier func(s string) string) bool {
for _, item := range slice {
if item == s {
return true
}
if modifier != nil && modifier(item) == s {
return true
}
}
return false
return Contains(slice, s, modifier)
}
// ToSet returns a single slice containing the unique values from one or more slices. The order of the items in the