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

@@ -196,6 +196,12 @@ func NewWatcher(cache memory.Cache, opts ...WatcherOption) (provider.Watcher, er
}
}
func WithVport(vport *apiv1.RegistryConfig_VPort) WatcherOption {
return func(w *watcher) {
w.Vport = vport
}
}
func WithNacosAddressServer(nacosAddressServer string) WatcherOption {
return func(w *watcher) {
w.NacosAddressServer = nacosAddressServer
@@ -529,7 +535,7 @@ func (w *watcher) generateServiceEntry(host string, services []model.Instance) *
portList := make([]*v1alpha3.ServicePort, 0)
endpoints := make([]*v1alpha3.WorkloadEntry, 0)
isDnsService := false
sePort := provider.GetServiceVport(host, w.Vport)
for _, service := range services {
protocol := common.HTTP
if service.Metadata != nil && service.Metadata["protocol"] != "" {
@@ -541,7 +547,13 @@ func (w *watcher) generateServiceEntry(host string, services []model.Instance) *
Protocol: protocol.String(),
}
if len(portList) == 0 {
portList = append(portList, port)
if sePort != nil {
sePort.Name = port.Name
sePort.Protocol = port.Protocol
portList = append(portList, sePort)
} else {
portList = append(portList, port)
}
}
if !isValidIP(service.Ip) {
isDnsService = true