mcpbridge新增vport元素,以修复服务后端端口不一致导致的兼容性问题 || =mcpbridge added a vport element to fix compatibility issues caused by inconsistent ports in the service backend (#2859)

This commit is contained in:
Iris
2025-09-11 14:02:35 +08:00
committed by GitHub
parent e2011cb805
commit 28228edfe5
11 changed files with 420 additions and 86 deletions

View File

@@ -15,7 +15,11 @@
package registry
import (
apiv1 "github.com/alibaba/higress/api/networking/v1"
"istio.io/api/networking/v1alpha3"
"istio.io/pkg/log"
"net"
"strings"
"time"
)
@@ -89,3 +93,29 @@ func ProbeWatcherStatus(host string, port string) WatcherStatus {
_ = conn.Close()
return Healthy
}
func GetServiceVport(host string, vport *apiv1.RegistryConfig_VPort) *v1alpha3.ServicePort {
if vport == nil {
log.Warnf("there is no vport exist for: %s, skip", host)
return nil
}
for _, service := range vport.Services {
if strings.EqualFold(service.Name, host) && isValidPort(service.Value) {
log.Infof("service %s vport exist, use service vport %d", host, service.Value)
return &v1alpha3.ServicePort{
Number: service.Value,
}
}
}
if isValidPort(vport.Default) {
log.Infof("there is only default vport exist, use default vport %d", vport.Default)
return &v1alpha3.ServicePort{
Number: vport.Default,
}
}
return nil
}
func isValidPort(port uint32) bool {
return port > 0 && port <= 65535
}