mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Merge pull request #48304 from mengqiy/kubectl_slice
Automatic merge from submit-queue split util/slice for kubectl Split util/slice to remove the dependency of kubectl on `k8s.io/kubernetes/pkg/util/slice`. ```release-note NONE ``` /assign @apelisse @monopole cc: @pwittrock ref #48209
This commit is contained in:
commit
950a09d982
@ -278,6 +278,7 @@ pkg/util/rand
|
|||||||
pkg/util/runtime
|
pkg/util/runtime
|
||||||
pkg/util/sets
|
pkg/util/sets
|
||||||
pkg/util/sets/types
|
pkg/util/sets/types
|
||||||
|
pkg/util/slice
|
||||||
pkg/util/tail
|
pkg/util/tail
|
||||||
pkg/util/validation
|
pkg/util/validation
|
||||||
pkg/util/validation/field
|
pkg/util/validation/field
|
||||||
|
@ -143,9 +143,9 @@ go_library(
|
|||||||
"//pkg/credentialprovider:go_default_library",
|
"//pkg/credentialprovider:go_default_library",
|
||||||
"//pkg/kubectl/resource:go_default_library",
|
"//pkg/kubectl/resource:go_default_library",
|
||||||
"//pkg/kubectl/util:go_default_library",
|
"//pkg/kubectl/util:go_default_library",
|
||||||
|
"//pkg/kubectl/util/slice:go_default_library",
|
||||||
"//pkg/printers:go_default_library",
|
"//pkg/printers:go_default_library",
|
||||||
"//pkg/printers/internalversion:go_default_library",
|
"//pkg/printers/internalversion:go_default_library",
|
||||||
"//pkg/util/slice:go_default_library",
|
|
||||||
"//vendor/github.com/emicklei/go-restful-swagger12:go_default_library",
|
"//vendor/github.com/emicklei/go-restful-swagger12:go_default_library",
|
||||||
"//vendor/github.com/golang/glog:go_default_library",
|
"//vendor/github.com/golang/glog:go_default_library",
|
||||||
"//vendor/github.com/spf13/cobra:go_default_library",
|
"//vendor/github.com/spf13/cobra:go_default_library",
|
||||||
|
@ -39,8 +39,8 @@ import (
|
|||||||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||||
"k8s.io/kubernetes/pkg/controller"
|
"k8s.io/kubernetes/pkg/controller"
|
||||||
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
|
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
|
||||||
|
sliceutil "k8s.io/kubernetes/pkg/kubectl/util/slice"
|
||||||
printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
|
printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
|
||||||
sliceutil "k8s.io/kubernetes/pkg/util/slice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -39,8 +39,8 @@ import (
|
|||||||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||||
"k8s.io/kubernetes/pkg/controller/daemon"
|
"k8s.io/kubernetes/pkg/controller/daemon"
|
||||||
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
|
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
|
||||||
|
sliceutil "k8s.io/kubernetes/pkg/kubectl/util/slice"
|
||||||
printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
|
printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
|
||||||
sliceutil "k8s.io/kubernetes/pkg/util/slice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -31,6 +31,7 @@ filegroup(
|
|||||||
srcs = [
|
srcs = [
|
||||||
":package-srcs",
|
":package-srcs",
|
||||||
"//pkg/kubectl/util/crlf:all-srcs",
|
"//pkg/kubectl/util/crlf:all-srcs",
|
||||||
|
"//pkg/kubectl/util/slice:all-srcs",
|
||||||
"//pkg/kubectl/util/term:all-srcs",
|
"//pkg/kubectl/util/term:all-srcs",
|
||||||
],
|
],
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
|
35
pkg/kubectl/util/slice/BUILD
Normal file
35
pkg/kubectl/util/slice/BUILD
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@io_bazel_rules_go//go:def.bzl",
|
||||||
|
"go_library",
|
||||||
|
"go_test",
|
||||||
|
)
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = ["slice.go"],
|
||||||
|
tags = ["automanaged"],
|
||||||
|
)
|
||||||
|
|
||||||
|
go_test(
|
||||||
|
name = "go_default_test",
|
||||||
|
srcs = ["slice_test.go"],
|
||||||
|
library = ":go_default_library",
|
||||||
|
tags = ["automanaged"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "package-srcs",
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
tags = ["automanaged"],
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "all-srcs",
|
||||||
|
srcs = [":package-srcs"],
|
||||||
|
tags = ["automanaged"],
|
||||||
|
)
|
32
pkg/kubectl/util/slice/slice.go
Normal file
32
pkg/kubectl/util/slice/slice.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 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 slice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Int64Slice attaches the methods of Interface to []int64,
|
||||||
|
// sorting in increasing order.
|
||||||
|
type Int64Slice []int64
|
||||||
|
|
||||||
|
func (p Int64Slice) Len() int { return len(p) }
|
||||||
|
func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] }
|
||||||
|
func (p Int64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
||||||
|
|
||||||
|
// Sorts []int64 in increasing order
|
||||||
|
func SortInts64(a []int64) { sort.Sort(Int64Slice(a)) }
|
31
pkg/kubectl/util/slice/slice_test.go
Normal file
31
pkg/kubectl/util/slice/slice_test.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 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 slice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSortInts64(t *testing.T) {
|
||||||
|
src := []int64{10, 1, 2, 3, 4, 5, 6}
|
||||||
|
expected := []int64{1, 2, 3, 4, 5, 6, 10}
|
||||||
|
SortInts64(src)
|
||||||
|
if !reflect.DeepEqual(src, expected) {
|
||||||
|
t.Errorf("func Ints64 didnt sort correctly, %v !- %v", src, expected)
|
||||||
|
}
|
||||||
|
}
|
@ -68,14 +68,3 @@ func ContainsString(slice []string, s string, modifier func(s string) string) bo
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Int64Slice attaches the methods of Interface to []int64,
|
|
||||||
// sorting in increasing order.
|
|
||||||
type Int64Slice []int64
|
|
||||||
|
|
||||||
func (p Int64Slice) Len() int { return len(p) }
|
|
||||||
func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] }
|
|
||||||
func (p Int64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
|
||||||
|
|
||||||
// Sorts []int64 in increasing order
|
|
||||||
func SortInts64(a []int64) { sort.Sort(Int64Slice(a)) }
|
|
||||||
|
@ -89,12 +89,3 @@ func TestShuffleStrings(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSortInts64(t *testing.T) {
|
|
||||||
src := []int64{10, 1, 2, 3, 4, 5, 6}
|
|
||||||
expected := []int64{1, 2, 3, 4, 5, 6, 10}
|
|
||||||
SortInts64(src)
|
|
||||||
if !reflect.DeepEqual(src, expected) {
|
|
||||||
t.Errorf("func Ints64 didnt sort correctly, %v !- %v", src, expected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user