mirror of
https://github.com/cloudnativelabs/kube-router.git
synced 2025-10-18 05:11:06 +02:00
use endpoint (IP, port) tuple to track active endpoints of a service in use. Currently only endpoint IP (#842)
used so any change in port of the endpoint leaves stale ipvs server config Fixes #841
This commit is contained in:
parent
4f627bc8bc
commit
0857436ec3
@ -241,6 +241,7 @@ type serviceInfo struct {
|
||||
namespace string
|
||||
clusterIP net.IP
|
||||
port int
|
||||
targetPort string
|
||||
protocol string
|
||||
nodePort int
|
||||
sessionAffinity bool
|
||||
@ -1040,6 +1041,7 @@ func (nsc *NetworkServicesController) buildServicesInfo() serviceInfoMap {
|
||||
svcInfo := serviceInfo{
|
||||
clusterIP: net.ParseIP(svc.Spec.ClusterIP),
|
||||
port: int(port.Port),
|
||||
targetPort: port.TargetPort.String(),
|
||||
protocol: strings.ToLower(string(port.Protocol)),
|
||||
nodePort: int(port.NodePort),
|
||||
name: svc.ObjectMeta.Name,
|
||||
@ -1925,6 +1927,10 @@ func generateIpPortId(ip, protocol, port string) string {
|
||||
return ip + "-" + protocol + "-" + port
|
||||
}
|
||||
|
||||
func generateEndpointId(ip, port string) string {
|
||||
return ip + ":" + port
|
||||
}
|
||||
|
||||
// returns all IP addresses found on any network address in the system, excluding dummy and docker interfaces
|
||||
func getAllLocalIPs() ([]netlink.Addr, error) {
|
||||
links, err := netlink.LinkList()
|
||||
|
@ -139,7 +139,7 @@ func (nsc *NetworkServicesController) setupClusterIPServices(serviceInfoMap serv
|
||||
if err != nil {
|
||||
glog.Errorf(err.Error())
|
||||
} else {
|
||||
activeServiceEndpointMap[clusterServiceId] = append(activeServiceEndpointMap[clusterServiceId], endpoint.ip)
|
||||
activeServiceEndpointMap[clusterServiceId] = append(activeServiceEndpointMap[clusterServiceId], generateEndpointId(endpoint.ip, strconv.Itoa(endpoint.port)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -231,7 +231,7 @@ func (nsc *NetworkServicesController) setupNodePortServices(serviceInfoMap servi
|
||||
if err != nil {
|
||||
glog.Errorf(err.Error())
|
||||
} else {
|
||||
activeServiceEndpointMap[nodeServiceIds[i]] = append(activeServiceEndpointMap[nodeServiceIds[i]], endpoint.ip)
|
||||
activeServiceEndpointMap[nodeServiceIds[i]] = append(activeServiceEndpointMap[nodeServiceIds[i]], generateEndpointId(endpoint.ip, strconv.Itoa(endpoint.port)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -341,7 +341,7 @@ func (nsc *NetworkServicesController) setupExternalIPServices(serviceInfoMap ser
|
||||
activeServiceEndpointMap[externalIpServiceId] = make([]string, 0)
|
||||
for _, endpoint := range endpoints {
|
||||
if !svc.local || (svc.local && endpoint.isLocal) {
|
||||
activeServiceEndpointMap[externalIpServiceId] = append(activeServiceEndpointMap[externalIpServiceId], endpoint.ip)
|
||||
activeServiceEndpointMap[externalIpServiceId] = append(activeServiceEndpointMap[externalIpServiceId], generateEndpointId(endpoint.ip, strconv.Itoa(endpoint.port)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -485,9 +485,9 @@ func (nsc *NetworkServicesController) cleanupStaleIPVSConfig(activeServiceEndpoi
|
||||
continue
|
||||
}
|
||||
|
||||
endpoints, ok := activeServiceEndpointMap[key]
|
||||
endpointIds, ok := activeServiceEndpointMap[key]
|
||||
// Only delete the service if it's not there anymore to prevent flapping
|
||||
// old: if !ok || len(endpoints) == 0 {
|
||||
// old: if !ok || len(endpointIds) == 0 {
|
||||
if !ok {
|
||||
excluded := false
|
||||
for _, excludedCidr := range nsc.excludedCidrs {
|
||||
@ -518,8 +518,8 @@ func (nsc *NetworkServicesController) cleanupStaleIPVSConfig(activeServiceEndpoi
|
||||
}
|
||||
for _, dst := range dsts {
|
||||
validEp := false
|
||||
for _, ep := range endpoints {
|
||||
if ep == dst.Address.String() {
|
||||
for _, epId := range endpointIds {
|
||||
if epId == generateEndpointId(dst.Address.String(), strconv.Itoa(int(dst.Port))) {
|
||||
validEp = true
|
||||
break
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user