mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-04 20:57:38 +08:00
fix service mesh not support multiple port issues
This commit is contained in:
parent
14187d84c9
commit
da0f653218
@ -45,27 +45,15 @@ func OneNodeClusterLoadAssignment(serviceAlias, namespace string, endpoints []*c
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
clusterName := fmt.Sprintf("%s_%s_%s_%d", namespace, serviceAlias, destServiceAlias, service.Spec.Ports[0].Port)
|
clusterName := fmt.Sprintf("%s_%s_%s_%d", namespace, serviceAlias, destServiceAlias, service.Spec.Ports[0].Port)
|
||||||
name := fmt.Sprintf("%sService", destServiceAlias)
|
selectEndpoint := getEndpointsByServiceName(endpoints, service.Name)
|
||||||
if destServiceAlias == serviceAlias {
|
logrus.Debugf("select endpoints %d for service %s", len(selectEndpoint), service.Name)
|
||||||
name = fmt.Sprintf("%sServiceOUT", destServiceAlias)
|
|
||||||
}
|
|
||||||
selectEndpoint := getEndpointsByLables(endpoints, map[string]string{"name": name})
|
|
||||||
var lendpoints []endpoint.LocalityLbEndpoints // localityLbEndpoints just support only one content
|
var lendpoints []endpoint.LocalityLbEndpoints // localityLbEndpoints just support only one content
|
||||||
if len(selectEndpoint) > 0 {
|
|
||||||
for _, en := range selectEndpoint {
|
for _, en := range selectEndpoint {
|
||||||
if len(en.Subsets) > 0 {
|
for _, subset := range en.Subsets {
|
||||||
subset := en.Subsets[0]
|
|
||||||
if len(subset.Ports) < 1 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, port := range subset.Ports {
|
for _, port := range subset.Ports {
|
||||||
toport := int(port.Port)
|
toport := int(port.Port)
|
||||||
//if haven multiple port, will get other port endpoint
|
|
||||||
//so must ignore
|
|
||||||
if (len(service.Spec.Ports) == 0 || service.Spec.Ports[0].TargetPort.IntVal != int32(toport)) && en.Labels["service_kind"] != "third_party" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if serviceAlias == destServiceAlias {
|
if serviceAlias == destServiceAlias {
|
||||||
|
//use real port
|
||||||
if originPort, ok := service.Labels["origin_port"]; ok {
|
if originPort, ok := service.Labels["origin_port"]; ok {
|
||||||
origin, err := strconv.Atoi(originPort)
|
origin, err := strconv.Atoi(originPort)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -73,12 +61,12 @@ func OneNodeClusterLoadAssignment(serviceAlias, namespace string, endpoints []*c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protocol := string(subset.Ports[0].Protocol)
|
protocol := string(port.Protocol)
|
||||||
addressList := subset.Addresses
|
addressList := subset.Addresses
|
||||||
var notready bool
|
var notready bool
|
||||||
if len(addressList) == 0 {
|
if len(addressList) == 0 && len(subset.NotReadyAddresses) > 0 {
|
||||||
notready = true
|
notready = true
|
||||||
addressList = subset.NotReadyAddresses
|
addressList = subset.NotReadyAddresses[:1]
|
||||||
}
|
}
|
||||||
getHealty := func() *endpoint.Endpoint_HealthCheckConfig {
|
getHealty := func() *endpoint.Endpoint_HealthCheckConfig {
|
||||||
if notready {
|
if notready {
|
||||||
@ -89,9 +77,8 @@ func OneNodeClusterLoadAssignment(serviceAlias, namespace string, endpoints []*c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var lbe []endpoint.LbEndpoint // just support one content
|
var lbe []endpoint.LbEndpoint // just support one content
|
||||||
if len(addressList) > 0 {
|
for _, address := range addressList {
|
||||||
envoyAddress := envoyv2.CreateSocketAddress(protocol, addressList[0].IP, uint32(toport))
|
envoyAddress := envoyv2.CreateSocketAddress(protocol, address.IP, uint32(toport))
|
||||||
|
|
||||||
lbe = append(lbe, endpoint.LbEndpoint{
|
lbe = append(lbe, endpoint.LbEndpoint{
|
||||||
HostIdentifier: &endpoint.LbEndpoint_Endpoint{
|
HostIdentifier: &endpoint.LbEndpoint_Endpoint{
|
||||||
Endpoint: &endpoint.Endpoint{
|
Endpoint: &endpoint.Endpoint{
|
||||||
@ -105,8 +92,6 @@ func OneNodeClusterLoadAssignment(serviceAlias, namespace string, endpoints []*c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
cla := &v2.ClusterLoadAssignment{
|
cla := &v2.ClusterLoadAssignment{
|
||||||
ClusterName: clusterName,
|
ClusterName: clusterName,
|
||||||
Endpoints: lendpoints,
|
Endpoints: lendpoints,
|
||||||
@ -138,3 +123,12 @@ func getEndpointsByLables(endpoints []*corev1.Endpoints, slabels map[string]stri
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEndpointsByServiceName(endpoints []*corev1.Endpoints, serviceName string) (re []*corev1.Endpoints) {
|
||||||
|
for _, en := range endpoints {
|
||||||
|
if serviceName == en.Name {
|
||||||
|
re = append(re, en)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -183,7 +184,14 @@ func (d *DiscoverServerManager) UpdateNodeConfig(nc *NodeConfig) error {
|
|||||||
if selector != nil {
|
if selector != nil {
|
||||||
upServices, upEndpoints := d.GetServicesAndEndpoints(nc.namespace, selector)
|
upServices, upEndpoints := d.GetServicesAndEndpoints(nc.namespace, selector)
|
||||||
for i, service := range upServices {
|
for i, service := range upServices {
|
||||||
if service.Spec.Ports[0].TargetPort.IntVal == int32(dep.Port) {
|
listenPort := service.Spec.Ports[0].Port
|
||||||
|
if value, ok := service.Labels["origin_port"]; ok {
|
||||||
|
origin, _ := strconv.Atoi(value)
|
||||||
|
if origin != 0 {
|
||||||
|
listenPort = int32(origin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if listenPort == int32(dep.Port) {
|
||||||
services = append(services, upServices[i])
|
services = append(services, upServices[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,12 +199,10 @@ func (d *DiscoverServerManager) UpdateNodeConfig(nc *NodeConfig) error {
|
|||||||
if len(end.Subsets) == 0 || len(end.Subsets[0].Ports) == 0 {
|
if len(end.Subsets) == 0 || len(end.Subsets[0].Ports) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if end.Subsets[0].Ports[0].Port == int32(dep.Port) {
|
|
||||||
endpoint = append(endpoint, upEndpoints[i])
|
endpoint = append(endpoint, upEndpoints[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if nc.configModel.BasePorts != nil && len(nc.configModel.BasePorts) > 0 {
|
if nc.configModel.BasePorts != nil && len(nc.configModel.BasePorts) > 0 {
|
||||||
labelname := fmt.Sprintf("name=%sServiceOUT", nc.serviceAlias)
|
labelname := fmt.Sprintf("name=%sServiceOUT", nc.serviceAlias)
|
||||||
selector, err := labels.Parse(labelname)
|
selector, err := labels.Parse(labelname)
|
||||||
|
Loading…
Reference in New Issue
Block a user