mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Use Go standard library slices package instead of k8s.io/utils/strings/slices
The package was introduced in Go 1.21 and is already in use in the k8s code base.
This commit is contained in:
parent
ab26ad0950
commit
23dcd26048
@ -18,6 +18,7 @@ package labels
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -27,7 +28,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/validation"
|
"k8s.io/apimachinery/pkg/util/validation"
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
stringslices "k8s.io/utils/strings/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -313,7 +313,7 @@ func (r Requirement) Equal(x Requirement) bool {
|
|||||||
if r.operator != x.operator {
|
if r.operator != x.operator {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return stringslices.Equal(r.strValues, x.strValues)
|
return slices.Equal(r.strValues, x.strValues)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty returns true if the internalSelector doesn't restrict selection space
|
// Empty returns true if the internalSelector doesn't restrict selection space
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -60,7 +61,6 @@ import (
|
|||||||
"k8s.io/kubectl/pkg/scheme"
|
"k8s.io/kubectl/pkg/scheme"
|
||||||
"k8s.io/kubectl/pkg/util/openapi"
|
"k8s.io/kubectl/pkg/util/openapi"
|
||||||
"k8s.io/utils/ptr"
|
"k8s.io/utils/ptr"
|
||||||
"k8s.io/utils/strings/slices"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
82
vendor/k8s.io/utils/strings/slices/slices.go
generated
vendored
82
vendor/k8s.io/utils/strings/slices/slices.go
generated
vendored
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2021 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Package slices defines various functions useful with slices of string type.
|
|
||||||
// The goal is to be as close as possible to
|
|
||||||
// https://github.com/golang/go/issues/45955. Ideal would be if we can just
|
|
||||||
// replace "stringslices" if the "slices" package becomes standard.
|
|
||||||
package slices
|
|
||||||
|
|
||||||
// Equal reports whether two slices are equal: the same length and all
|
|
||||||
// elements equal. If the lengths are different, Equal returns false.
|
|
||||||
// Otherwise, the elements are compared in index order, and the
|
|
||||||
// comparison stops at the first unequal pair.
|
|
||||||
func Equal(s1, s2 []string) bool {
|
|
||||||
if len(s1) != len(s2) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for i, n := range s1 {
|
|
||||||
if n != s2[i] {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter appends to d each element e of s for which keep(e) returns true.
|
|
||||||
// It returns the modified d. d may be s[:0], in which case the kept
|
|
||||||
// elements will be stored in the same slice.
|
|
||||||
// if the slices overlap in some other way, the results are unspecified.
|
|
||||||
// To create a new slice with the filtered results, pass nil for d.
|
|
||||||
func Filter(d, s []string, keep func(string) bool) []string {
|
|
||||||
for _, n := range s {
|
|
||||||
if keep(n) {
|
|
||||||
d = append(d, n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// Contains reports whether v is present in s.
|
|
||||||
func Contains(s []string, v string) bool {
|
|
||||||
return Index(s, v) >= 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Index returns the index of the first occurrence of v in s, or -1 if
|
|
||||||
// not present.
|
|
||||||
func Index(s []string, v string) int {
|
|
||||||
// "Contains" may be replaced with "Index(s, v) >= 0":
|
|
||||||
// https://github.com/golang/go/issues/45955#issuecomment-873377947
|
|
||||||
for i, n := range s {
|
|
||||||
if n == v {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions below are not in https://github.com/golang/go/issues/45955
|
|
||||||
|
|
||||||
// Clone returns a new clone of s.
|
|
||||||
func Clone(s []string) []string {
|
|
||||||
// https://github.com/go101/go101/wiki/There-is-not-a-perfect-way-to-clone-slices-in-Go
|
|
||||||
if s == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
c := make([]string, len(s))
|
|
||||||
copy(c, s)
|
|
||||||
return c
|
|
||||||
}
|
|
1
vendor/modules.txt
vendored
1
vendor/modules.txt
vendored
@ -1219,7 +1219,6 @@ k8s.io/utils/path
|
|||||||
k8s.io/utils/pointer
|
k8s.io/utils/pointer
|
||||||
k8s.io/utils/ptr
|
k8s.io/utils/ptr
|
||||||
k8s.io/utils/strings
|
k8s.io/utils/strings
|
||||||
k8s.io/utils/strings/slices
|
|
||||||
k8s.io/utils/trace
|
k8s.io/utils/trace
|
||||||
# sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3
|
# sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3
|
||||||
## explicit; go 1.21
|
## explicit; go 1.21
|
||||||
|
Loading…
Reference in New Issue
Block a user