mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +00:00
Remove unnecessary sort in kube-proxy ipvs
Sorting of endpoints before adding them to ipvs is not needed, nor wanted. It just takes time
This commit is contained in:
parent
24e6b03780
commit
d78a794be2
@ -1865,7 +1865,7 @@ func (proxier *Proxier) syncEndpoint(svcPortName proxy.ServicePortName, onlyNode
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create new endpoints
|
// Create new endpoints
|
||||||
for _, ep := range sets.List(newEndpoints) {
|
for _, ep := range newEndpoints.UnsortedList() {
|
||||||
ip, port, err := net.SplitHostPort(ep)
|
ip, port, err := net.SplitHostPort(ep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.ErrorS(err, "Failed to parse endpoint", "endpoint", ep)
|
klog.ErrorS(err, "Failed to parse endpoint", "endpoint", ep)
|
||||||
|
@ -19,6 +19,7 @@ package testing
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -53,6 +54,19 @@ func (r *RealServerKey) String() string {
|
|||||||
return net.JoinHostPort(r.Address.String(), strconv.Itoa(int(r.Port)))
|
return net.JoinHostPort(r.Address.String(), strconv.Itoa(int(r.Port)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implement https://pkg.go.dev/sort#Interface
|
||||||
|
type byAddress []*utilipvs.RealServer
|
||||||
|
|
||||||
|
func (a byAddress) Len() int {
|
||||||
|
return len(a)
|
||||||
|
}
|
||||||
|
func (a byAddress) Less(i, j int) bool {
|
||||||
|
return a[i].String() < a[j].String()
|
||||||
|
}
|
||||||
|
func (a byAddress) Swap(i, j int) {
|
||||||
|
a[i], a[j] = a[j], a[i]
|
||||||
|
}
|
||||||
|
|
||||||
// NewFake creates a fake ipvs implementation - a cache store.
|
// NewFake creates a fake ipvs implementation - a cache store.
|
||||||
func NewFake() *FakeIPVS {
|
func NewFake() *FakeIPVS {
|
||||||
return &FakeIPVS{
|
return &FakeIPVS{
|
||||||
@ -155,6 +169,8 @@ func (f *FakeIPVS) AddRealServer(serv *utilipvs.VirtualServer, dest *utilipvs.Re
|
|||||||
f.Destinations[key] = dests
|
f.Destinations[key] = dests
|
||||||
}
|
}
|
||||||
f.Destinations[key] = append(f.Destinations[key], dest)
|
f.Destinations[key] = append(f.Destinations[key], dest)
|
||||||
|
// The tests assumes that the slice is sorted
|
||||||
|
sort.Sort(byAddress(f.Destinations[key]))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user