mirror of
https://github.com/cloudnativelabs/kube-router.git
synced 2025-10-13 02:41:05 +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"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -422,6 +423,14 @@ func buildServicesInfo() serviceInfoMap {
|
|||||||
return serviceMap
|
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 {
|
func buildEndpointsInfo() endpointsInfoMap {
|
||||||
endpointsMap := make(endpointsInfoMap)
|
endpointsMap := make(endpointsInfoMap)
|
||||||
for _, ep := range watchers.EndpointsWatcher.List() {
|
for _, ep := range watchers.EndpointsWatcher.List() {
|
||||||
@ -432,7 +441,7 @@ func buildEndpointsInfo() endpointsInfoMap {
|
|||||||
for _, addr := range ep_subset.Addresses {
|
for _, addr := range ep_subset.Addresses {
|
||||||
endpoints = append(endpoints, endpointsInfo{ip: addr.IP, port: int(port.Port)})
|
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.EndpointsWatcher.RegisterHandler(&nsc)
|
||||||
watchers.ServiceWatcher.RegisterHandler(&nsc)
|
watchers.ServiceWatcher.RegisterHandler(&nsc)
|
||||||
|
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
return &nsc, nil
|
return &nsc, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user