Merge pull request #121744 from uablrek/ipvs-remove-sorting
Remove unnecessary sort in kube-proxy ipvs
This commit is contained in:
		@@ -1865,7 +1865,7 @@ func (proxier *Proxier) syncEndpoint(svcPortName proxy.ServicePortName, onlyNode
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Create new endpoints
 | 
			
		||||
	for _, ep := range sets.List(newEndpoints) {
 | 
			
		||||
	for _, ep := range newEndpoints.UnsortedList() {
 | 
			
		||||
		ip, port, err := net.SplitHostPort(ep)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			klog.ErrorS(err, "Failed to parse endpoint", "endpoint", ep)
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,7 @@ package testing
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net"
 | 
			
		||||
	"sort"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
@@ -53,6 +54,19 @@ func (r *RealServerKey) String() string {
 | 
			
		||||
	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.
 | 
			
		||||
func NewFake() *FakeIPVS {
 | 
			
		||||
	return &FakeIPVS{
 | 
			
		||||
@@ -155,6 +169,8 @@ func (f *FakeIPVS) AddRealServer(serv *utilipvs.VirtualServer, dest *utilipvs.Re
 | 
			
		||||
		f.Destinations[key] = dests
 | 
			
		||||
	}
 | 
			
		||||
	f.Destinations[key] = append(f.Destinations[key], dest)
 | 
			
		||||
	// The tests assumes that the slice is sorted
 | 
			
		||||
	sort.Sort(byAddress(f.Destinations[key]))
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user