diff --git a/pkg/controllers/proxy/network_services_controller.go b/pkg/controllers/proxy/network_services_controller.go index 712c9d2b..102820e2 100644 --- a/pkg/controllers/proxy/network_services_controller.go +++ b/pkg/controllers/proxy/network_services_controller.go @@ -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() diff --git a/pkg/controllers/proxy/service_endpoints_sync.go b/pkg/controllers/proxy/service_endpoints_sync.go index 9cf7e8fa..fe46fa88 100644 --- a/pkg/controllers/proxy/service_endpoints_sync.go +++ b/pkg/controllers/proxy/service_endpoints_sync.go @@ -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 }