mirror of
https://github.com/cloudnativelabs/kube-router.git
synced 2025-10-18 13:21:19 +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
|
namespace string
|
||||||
clusterIP net.IP
|
clusterIP net.IP
|
||||||
port int
|
port int
|
||||||
|
targetPort string
|
||||||
protocol string
|
protocol string
|
||||||
nodePort int
|
nodePort int
|
||||||
sessionAffinity bool
|
sessionAffinity bool
|
||||||
@ -1040,6 +1041,7 @@ func (nsc *NetworkServicesController) buildServicesInfo() serviceInfoMap {
|
|||||||
svcInfo := serviceInfo{
|
svcInfo := serviceInfo{
|
||||||
clusterIP: net.ParseIP(svc.Spec.ClusterIP),
|
clusterIP: net.ParseIP(svc.Spec.ClusterIP),
|
||||||
port: int(port.Port),
|
port: int(port.Port),
|
||||||
|
targetPort: port.TargetPort.String(),
|
||||||
protocol: strings.ToLower(string(port.Protocol)),
|
protocol: strings.ToLower(string(port.Protocol)),
|
||||||
nodePort: int(port.NodePort),
|
nodePort: int(port.NodePort),
|
||||||
name: svc.ObjectMeta.Name,
|
name: svc.ObjectMeta.Name,
|
||||||
@ -1925,6 +1927,10 @@ func generateIpPortId(ip, protocol, port string) string {
|
|||||||
return ip + "-" + protocol + "-" + port
|
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
|
// returns all IP addresses found on any network address in the system, excluding dummy and docker interfaces
|
||||||
func getAllLocalIPs() ([]netlink.Addr, error) {
|
func getAllLocalIPs() ([]netlink.Addr, error) {
|
||||||
links, err := netlink.LinkList()
|
links, err := netlink.LinkList()
|
||||||
|
@ -139,7 +139,7 @@ func (nsc *NetworkServicesController) setupClusterIPServices(serviceInfoMap serv
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf(err.Error())
|
glog.Errorf(err.Error())
|
||||||
} else {
|
} 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 {
|
if err != nil {
|
||||||
glog.Errorf(err.Error())
|
glog.Errorf(err.Error())
|
||||||
} else {
|
} 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)
|
activeServiceEndpointMap[externalIpServiceId] = make([]string, 0)
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
if !svc.local || (svc.local && endpoint.isLocal) {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoints, ok := activeServiceEndpointMap[key]
|
endpointIds, ok := activeServiceEndpointMap[key]
|
||||||
// Only delete the service if it's not there anymore to prevent flapping
|
// 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 {
|
if !ok {
|
||||||
excluded := false
|
excluded := false
|
||||||
for _, excludedCidr := range nsc.excludedCidrs {
|
for _, excludedCidr := range nsc.excludedCidrs {
|
||||||
@ -518,8 +518,8 @@ func (nsc *NetworkServicesController) cleanupStaleIPVSConfig(activeServiceEndpoi
|
|||||||
}
|
}
|
||||||
for _, dst := range dsts {
|
for _, dst := range dsts {
|
||||||
validEp := false
|
validEp := false
|
||||||
for _, ep := range endpoints {
|
for _, epId := range endpointIds {
|
||||||
if ep == dst.Address.String() {
|
if epId == generateEndpointId(dst.Address.String(), strconv.Itoa(int(dst.Port))) {
|
||||||
validEp = true
|
validEp = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user