mirror of
https://github.com/cloudnativelabs/kube-router.git
synced 2025-10-12 18:31:04 +02:00
Merge pull request #100 from cloudnativelabs/99-randomize-service-endpoints
Randomize service endpoint addition when configuring destination on ipvs service
This commit is contained in:
commit
fbdd9e9a6f
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"reflect"
|
||||
@ -422,6 +423,14 @@ func buildServicesInfo() serviceInfoMap {
|
||||
return serviceMap
|
||||
}
|
||||
|
||||
func shuffle(endPoints []endpointsInfo) []endpointsInfo {
|
||||
for index1 := range endPoints {
|
||||
index2 := rand.Intn(index1 + 1)
|
||||
endPoints[index1], endPoints[index2] = endPoints[index2], endPoints[index1]
|
||||
}
|
||||
return endPoints
|
||||
}
|
||||
|
||||
func buildEndpointsInfo() endpointsInfoMap {
|
||||
endpointsMap := make(endpointsInfoMap)
|
||||
for _, ep := range watchers.EndpointsWatcher.List() {
|
||||
@ -432,7 +441,7 @@ func buildEndpointsInfo() endpointsInfoMap {
|
||||
for _, addr := range ep_subset.Addresses {
|
||||
endpoints = append(endpoints, endpointsInfo{ip: addr.IP, port: int(port.Port)})
|
||||
}
|
||||
endpointsMap[svcId] = endpoints
|
||||
endpointsMap[svcId] = shuffle(endpoints)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -856,5 +865,7 @@ func NewNetworkServicesController(clientset *kubernetes.Clientset, config *optio
|
||||
watchers.EndpointsWatcher.RegisterHandler(&nsc)
|
||||
watchers.ServiceWatcher.RegisterHandler(&nsc)
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
return &nsc, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user