mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #57930 from zhangxiaoyu-zidif/refactor-service-with-sets
Automatic merge from submit-queue (batch tested with PRs 57926, 57930). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. use sets.String to replace slice when sort []string **What this PR does / why we need it**: use sets.String to replace slice when sort []string No need to maintain a slice comparison function. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
009701f181
@ -23,6 +23,7 @@ go_library(
|
|||||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||||
|
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||||
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
||||||
"//vendor/k8s.io/client-go/informers/core/v1:go_default_library",
|
"//vendor/k8s.io/client-go/informers/core/v1:go_default_library",
|
||||||
|
@ -18,7 +18,6 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -28,6 +27,7 @@ import (
|
|||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/util/runtime"
|
"k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
coreinformers "k8s.io/client-go/informers/core/v1"
|
coreinformers "k8s.io/client-go/informers/core/v1"
|
||||||
@ -567,10 +567,10 @@ func portEqualForLB(x, y *v1.ServicePort) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func nodeNames(nodes []*v1.Node) []string {
|
func nodeNames(nodes []*v1.Node) sets.String {
|
||||||
ret := make([]string, len(nodes))
|
ret := sets.NewString()
|
||||||
for i, node := range nodes {
|
for _, node := range nodes {
|
||||||
ret[i] = node.Name
|
ret.Insert(node.Name)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@ -579,25 +579,7 @@ func nodeSlicesEqualForLB(x, y []*v1.Node) bool {
|
|||||||
if len(x) != len(y) {
|
if len(x) != len(y) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return stringSlicesEqual(nodeNames(x), nodeNames(y))
|
return nodeNames(x).Equal(nodeNames(x))
|
||||||
}
|
|
||||||
|
|
||||||
func stringSlicesEqual(x, y []string) bool {
|
|
||||||
if len(x) != len(y) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if !sort.StringsAreSorted(x) {
|
|
||||||
sort.Strings(x)
|
|
||||||
}
|
|
||||||
if !sort.StringsAreSorted(y) {
|
|
||||||
sort.Strings(y)
|
|
||||||
}
|
|
||||||
for i := range x {
|
|
||||||
if x[i] != y[i] {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNodeConditionPredicate() corelisters.NodeConditionPredicate {
|
func getNodeConditionPredicate() corelisters.NodeConditionPredicate {
|
||||||
|
Loading…
Reference in New Issue
Block a user