From 28228edfe520394cb7a6920e3cfc3bd4f02e4209 Mon Sep 17 00:00:00 2001 From: Iris Date: Thu, 11 Sep 2025 14:02:35 +0800 Subject: [PATCH] =?UTF-8?q?mcpbridge=E6=96=B0=E5=A2=9Evport=E5=85=83?= =?UTF-8?q?=E7=B4=A0=EF=BC=8C=E4=BB=A5=E4=BF=AE=E5=A4=8D=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E7=AB=AF=E5=8F=A3=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20||=20=3Dmcpbridge=20added=20a=20vport=20element=20t?= =?UTF-8?q?o=20fix=20compatibility=20issues=20caused=20by=20inconsistent?= =?UTF-8?q?=20ports=20in=20the=20service=20backend=20(#2859)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customresourcedefinitions.gen.yaml | 14 + api/networking/v1/mcp_bridge.pb.go | 317 +++++++++++++----- api/networking/v1/mcp_bridge.proto | 9 + api/networking/v1/mcp_bridge_deepcopy.gen.go | 42 +++ api/networking/v1/mcp_bridge_json.gen.go | 22 ++ .../crds/customresourcedefinitions.gen.yaml | 14 + registry/eureka/watcher.go | 23 +- registry/nacos/v2/watcher.go | 16 +- registry/nacos/watcher.go | 16 +- registry/reconcile/reconcile.go | 3 + registry/watcher.go | 30 ++ 11 files changed, 420 insertions(+), 86 deletions(-) diff --git a/api/kubernetes/customresourcedefinitions.gen.yaml b/api/kubernetes/customresourcedefinitions.gen.yaml index a7faf4fa4..c5c899464 100644 --- a/api/kubernetes/customresourcedefinitions.gen.yaml +++ b/api/kubernetes/customresourcedefinitions.gen.yaml @@ -332,6 +332,20 @@ spec: type: string type: type: string + vport: + properties: + default: + type: integer + services: + items: + properties: + name: + type: string + value: + type: integer + type: object + type: array + type: object zkServicesPath: items: type: string diff --git a/api/networking/v1/mcp_bridge.pb.go b/api/networking/v1/mcp_bridge.pb.go index a7e359e0c..d2fdb3354 100644 --- a/api/networking/v1/mcp_bridge.pb.go +++ b/api/networking/v1/mcp_bridge.pb.go @@ -119,32 +119,33 @@ type RegistryConfig struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - Domain string `protobuf:"bytes,3,opt,name=domain,proto3" json:"domain,omitempty"` - Port uint32 `protobuf:"varint,4,opt,name=port,proto3" json:"port,omitempty"` - NacosAddressServer string `protobuf:"bytes,5,opt,name=nacosAddressServer,proto3" json:"nacosAddressServer,omitempty"` - NacosAccessKey string `protobuf:"bytes,6,opt,name=nacosAccessKey,proto3" json:"nacosAccessKey,omitempty"` - NacosSecretKey string `protobuf:"bytes,7,opt,name=nacosSecretKey,proto3" json:"nacosSecretKey,omitempty"` - NacosNamespaceId string `protobuf:"bytes,8,opt,name=nacosNamespaceId,proto3" json:"nacosNamespaceId,omitempty"` - NacosNamespace string `protobuf:"bytes,9,opt,name=nacosNamespace,proto3" json:"nacosNamespace,omitempty"` - NacosGroups []string `protobuf:"bytes,10,rep,name=nacosGroups,proto3" json:"nacosGroups,omitempty"` - NacosRefreshInterval int64 `protobuf:"varint,11,opt,name=nacosRefreshInterval,proto3" json:"nacosRefreshInterval,omitempty"` - ConsulNamespace string `protobuf:"bytes,12,opt,name=consulNamespace,proto3" json:"consulNamespace,omitempty"` - ZkServicesPath []string `protobuf:"bytes,13,rep,name=zkServicesPath,proto3" json:"zkServicesPath,omitempty"` - ConsulDatacenter string `protobuf:"bytes,14,opt,name=consulDatacenter,proto3" json:"consulDatacenter,omitempty"` - ConsulServiceTag string `protobuf:"bytes,15,opt,name=consulServiceTag,proto3" json:"consulServiceTag,omitempty"` - ConsulRefreshInterval int64 `protobuf:"varint,16,opt,name=consulRefreshInterval,proto3" json:"consulRefreshInterval,omitempty"` - AuthSecretName string `protobuf:"bytes,17,opt,name=authSecretName,proto3" json:"authSecretName,omitempty"` - Protocol string `protobuf:"bytes,18,opt,name=protocol,proto3" json:"protocol,omitempty"` - Sni string `protobuf:"bytes,19,opt,name=sni,proto3" json:"sni,omitempty"` - McpServerExportDomains []string `protobuf:"bytes,20,rep,name=mcpServerExportDomains,proto3" json:"mcpServerExportDomains,omitempty"` - McpServerBaseUrl string `protobuf:"bytes,21,opt,name=mcpServerBaseUrl,proto3" json:"mcpServerBaseUrl,omitempty"` - EnableMCPServer *wrappers.BoolValue `protobuf:"bytes,22,opt,name=enableMCPServer,proto3" json:"enableMCPServer,omitempty"` - EnableScopeMcpServers *wrappers.BoolValue `protobuf:"bytes,23,opt,name=enableScopeMcpServers,proto3" json:"enableScopeMcpServers,omitempty"` - AllowMcpServers []string `protobuf:"bytes,24,rep,name=allowMcpServers,proto3" json:"allowMcpServers,omitempty"` - Metadata map[string]*InnerMap `protobuf:"bytes,25,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - ProxyName string `protobuf:"bytes,26,opt,name=proxyName,proto3" json:"proxyName,omitempty"` + Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Domain string `protobuf:"bytes,3,opt,name=domain,proto3" json:"domain,omitempty"` + Port uint32 `protobuf:"varint,4,opt,name=port,proto3" json:"port,omitempty"` + NacosAddressServer string `protobuf:"bytes,5,opt,name=nacosAddressServer,proto3" json:"nacosAddressServer,omitempty"` + NacosAccessKey string `protobuf:"bytes,6,opt,name=nacosAccessKey,proto3" json:"nacosAccessKey,omitempty"` + NacosSecretKey string `protobuf:"bytes,7,opt,name=nacosSecretKey,proto3" json:"nacosSecretKey,omitempty"` + NacosNamespaceId string `protobuf:"bytes,8,opt,name=nacosNamespaceId,proto3" json:"nacosNamespaceId,omitempty"` + NacosNamespace string `protobuf:"bytes,9,opt,name=nacosNamespace,proto3" json:"nacosNamespace,omitempty"` + NacosGroups []string `protobuf:"bytes,10,rep,name=nacosGroups,proto3" json:"nacosGroups,omitempty"` + NacosRefreshInterval int64 `protobuf:"varint,11,opt,name=nacosRefreshInterval,proto3" json:"nacosRefreshInterval,omitempty"` + ConsulNamespace string `protobuf:"bytes,12,opt,name=consulNamespace,proto3" json:"consulNamespace,omitempty"` + ZkServicesPath []string `protobuf:"bytes,13,rep,name=zkServicesPath,proto3" json:"zkServicesPath,omitempty"` + ConsulDatacenter string `protobuf:"bytes,14,opt,name=consulDatacenter,proto3" json:"consulDatacenter,omitempty"` + ConsulServiceTag string `protobuf:"bytes,15,opt,name=consulServiceTag,proto3" json:"consulServiceTag,omitempty"` + ConsulRefreshInterval int64 `protobuf:"varint,16,opt,name=consulRefreshInterval,proto3" json:"consulRefreshInterval,omitempty"` + AuthSecretName string `protobuf:"bytes,17,opt,name=authSecretName,proto3" json:"authSecretName,omitempty"` + Protocol string `protobuf:"bytes,18,opt,name=protocol,proto3" json:"protocol,omitempty"` + Sni string `protobuf:"bytes,19,opt,name=sni,proto3" json:"sni,omitempty"` + McpServerExportDomains []string `protobuf:"bytes,20,rep,name=mcpServerExportDomains,proto3" json:"mcpServerExportDomains,omitempty"` + McpServerBaseUrl string `protobuf:"bytes,21,opt,name=mcpServerBaseUrl,proto3" json:"mcpServerBaseUrl,omitempty"` + EnableMCPServer *wrappers.BoolValue `protobuf:"bytes,22,opt,name=enableMCPServer,proto3" json:"enableMCPServer,omitempty"` + EnableScopeMcpServers *wrappers.BoolValue `protobuf:"bytes,23,opt,name=enableScopeMcpServers,proto3" json:"enableScopeMcpServers,omitempty"` + AllowMcpServers []string `protobuf:"bytes,24,rep,name=allowMcpServers,proto3" json:"allowMcpServers,omitempty"` + Metadata map[string]*InnerMap `protobuf:"bytes,25,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + ProxyName string `protobuf:"bytes,26,opt,name=proxyName,proto3" json:"proxyName,omitempty"` + Vport *RegistryConfig_VPort `protobuf:"bytes,27,opt,name=vport,proto3" json:"vport,omitempty"` } func (x *RegistryConfig) Reset() { @@ -361,6 +362,13 @@ func (x *RegistryConfig) GetProxyName() string { return "" } +func (x *RegistryConfig) GetVport() *RegistryConfig_VPort { + if x != nil { + return x.Vport + } + return nil +} + type ProxyConfig struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -495,6 +503,116 @@ func (x *InnerMap) GetInnerMap() map[string]string { return nil } +type RegistryConfig_VPort struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Default uint32 `protobuf:"varint,1,opt,name=default,proto3" json:"default,omitempty"` + Services []*RegistryConfig_VPort_Services `protobuf:"bytes,2,rep,name=services,proto3" json:"services,omitempty"` +} + +func (x *RegistryConfig_VPort) Reset() { + *x = RegistryConfig_VPort{} + if protoimpl.UnsafeEnabled { + mi := &file_networking_v1_mcp_bridge_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RegistryConfig_VPort) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegistryConfig_VPort) ProtoMessage() {} + +func (x *RegistryConfig_VPort) ProtoReflect() protoreflect.Message { + mi := &file_networking_v1_mcp_bridge_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RegistryConfig_VPort.ProtoReflect.Descriptor instead. +func (*RegistryConfig_VPort) Descriptor() ([]byte, []int) { + return file_networking_v1_mcp_bridge_proto_rawDescGZIP(), []int{1, 1} +} + +func (x *RegistryConfig_VPort) GetDefault() uint32 { + if x != nil { + return x.Default + } + return 0 +} + +func (x *RegistryConfig_VPort) GetServices() []*RegistryConfig_VPort_Services { + if x != nil { + return x.Services + } + return nil +} + +type RegistryConfig_VPort_Services struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Value uint32 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *RegistryConfig_VPort_Services) Reset() { + *x = RegistryConfig_VPort_Services{} + if protoimpl.UnsafeEnabled { + mi := &file_networking_v1_mcp_bridge_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RegistryConfig_VPort_Services) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegistryConfig_VPort_Services) ProtoMessage() {} + +func (x *RegistryConfig_VPort_Services) ProtoReflect() protoreflect.Message { + mi := &file_networking_v1_mcp_bridge_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RegistryConfig_VPort_Services.ProtoReflect.Descriptor instead. +func (*RegistryConfig_VPort_Services) Descriptor() ([]byte, []int) { + return file_networking_v1_mcp_bridge_proto_rawDescGZIP(), []int{1, 1, 0} +} + +func (x *RegistryConfig_VPort_Services) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *RegistryConfig_VPort_Services) GetValue() uint32 { + if x != nil { + return x.Value + } + return 0 +} + var File_networking_v1_mcp_bridge_proto protoreflect.FileDescriptor var file_networking_v1_mcp_bridge_proto_rawDesc = []byte{ @@ -516,7 +634,7 @@ var file_networking_v1_mcp_bridge_proto_rawDesc = []byte{ 0x72, 0x6f, 0x78, 0x69, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x68, 0x69, 0x67, 0x72, 0x65, 0x73, 0x73, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x52, 0x07, 0x70, 0x72, 0x6f, 0x78, 0x69, 0x65, 0x73, 0x22, 0xc6, 0x09, 0x0a, 0x0e, 0x52, 0x65, + 0x52, 0x07, 0x70, 0x72, 0x6f, 0x78, 0x69, 0x65, 0x73, 0x22, 0xb5, 0x0b, 0x0a, 0x0e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x17, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x03, 0xe0, 0x41, 0x02, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, @@ -587,39 +705,54 @@ var file_networking_v1_mcp_bridge_proto_rawDesc = []byte{ 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x1a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x78, 0x79, - 0x4e, 0x61, 0x6d, 0x65, 0x1a, 0x5c, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, - 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x35, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x68, 0x69, 0x67, 0x72, 0x65, 0x73, 0x73, - 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x49, - 0x6e, 0x6e, 0x65, 0x72, 0x4d, 0x61, 0x70, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, - 0x38, 0x01, 0x22, 0xdb, 0x01, 0x0a, 0x0b, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x43, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x12, 0x17, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x42, 0x03, 0xe0, 0x41, 0x02, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x17, 0x0a, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x03, 0xe0, 0x41, 0x02, 0x52, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x29, 0x0a, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, - 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x03, 0xe0, 0x41, 0x02, - 0x52, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, - 0x23, 0x0a, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x50, 0x6f, 0x72, 0x74, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x0d, 0x42, 0x03, 0xe0, 0x41, 0x02, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x50, 0x6f, 0x72, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x65, 0x72, - 0x50, 0x6f, 0x72, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0c, 0x6c, 0x69, 0x73, 0x74, - 0x65, 0x6e, 0x65, 0x72, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x26, 0x0a, 0x0e, 0x63, 0x6f, 0x6e, 0x6e, - 0x65, 0x63, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x0e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, - 0x22, 0x93, 0x01, 0x0a, 0x08, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x4d, 0x61, 0x70, 0x12, 0x4a, 0x0a, - 0x09, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x2d, 0x2e, 0x68, 0x69, 0x67, 0x72, 0x65, 0x73, 0x73, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, - 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x4d, 0x61, - 0x70, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, - 0x08, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x4d, 0x61, 0x70, 0x1a, 0x3b, 0x0a, 0x0d, 0x49, 0x6e, 0x6e, - 0x65, 0x72, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, - 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x6c, 0x69, 0x62, 0x61, 0x62, 0x61, 0x2f, 0x68, 0x69, 0x67, - 0x72, 0x65, 0x73, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, - 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x41, 0x0a, 0x05, 0x76, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x1b, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x68, 0x69, 0x67, 0x72, 0x65, 0x73, 0x73, 0x2e, 0x6e, 0x65, + 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x67, 0x69, + 0x73, 0x74, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x56, 0x50, 0x6f, 0x72, 0x74, + 0x52, 0x05, 0x76, 0x70, 0x6f, 0x72, 0x74, 0x1a, 0x5c, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, + 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x35, 0x0a, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x68, 0x69, 0x67, 0x72, + 0x65, 0x73, 0x73, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x4d, 0x61, 0x70, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0xa9, 0x01, 0x0a, 0x05, 0x56, 0x50, 0x6f, 0x72, 0x74, 0x12, + 0x18, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x50, 0x0a, 0x08, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x34, 0x2e, 0x68, 0x69, + 0x67, 0x72, 0x65, 0x73, 0x73, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x2e, 0x56, 0x50, 0x6f, 0x72, 0x74, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x73, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x1a, 0x34, 0x0a, 0x08, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x22, 0xdb, 0x01, 0x0a, 0x0b, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x12, 0x17, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, + 0x03, 0xe0, 0x41, 0x02, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x17, 0x0a, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x03, 0xe0, 0x41, 0x02, 0x52, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x12, 0x29, 0x0a, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x03, 0xe0, 0x41, 0x02, 0x52, + 0x0d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x23, + 0x0a, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x50, 0x6f, 0x72, 0x74, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x0d, 0x42, 0x03, 0xe0, 0x41, 0x02, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x50, + 0x6f, 0x72, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x6c, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x65, 0x72, 0x50, + 0x6f, 0x72, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0c, 0x6c, 0x69, 0x73, 0x74, 0x65, + 0x6e, 0x65, 0x72, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x26, 0x0a, 0x0e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, + 0x63, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x0e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x22, + 0x93, 0x01, 0x0a, 0x08, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x4d, 0x61, 0x70, 0x12, 0x4a, 0x0a, 0x09, + 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x2d, 0x2e, 0x68, 0x69, 0x67, 0x72, 0x65, 0x73, 0x73, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x4d, 0x61, 0x70, + 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, + 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x4d, 0x61, 0x70, 0x1a, 0x3b, 0x0a, 0x0d, 0x49, 0x6e, 0x6e, 0x65, + 0x72, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x6c, 0x69, 0x62, 0x61, 0x62, 0x61, 0x2f, 0x68, 0x69, 0x67, 0x72, + 0x65, 0x73, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x69, + 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -634,29 +767,33 @@ func file_networking_v1_mcp_bridge_proto_rawDescGZIP() []byte { return file_networking_v1_mcp_bridge_proto_rawDescData } -var file_networking_v1_mcp_bridge_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_networking_v1_mcp_bridge_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_networking_v1_mcp_bridge_proto_goTypes = []interface{}{ - (*McpBridge)(nil), // 0: higress.networking.v1.McpBridge - (*RegistryConfig)(nil), // 1: higress.networking.v1.RegistryConfig - (*ProxyConfig)(nil), // 2: higress.networking.v1.ProxyConfig - (*InnerMap)(nil), // 3: higress.networking.v1.InnerMap - nil, // 4: higress.networking.v1.RegistryConfig.MetadataEntry - nil, // 5: higress.networking.v1.InnerMap.InnerMapEntry - (*wrappers.BoolValue)(nil), // 6: google.protobuf.BoolValue + (*McpBridge)(nil), // 0: higress.networking.v1.McpBridge + (*RegistryConfig)(nil), // 1: higress.networking.v1.RegistryConfig + (*ProxyConfig)(nil), // 2: higress.networking.v1.ProxyConfig + (*InnerMap)(nil), // 3: higress.networking.v1.InnerMap + nil, // 4: higress.networking.v1.RegistryConfig.MetadataEntry + (*RegistryConfig_VPort)(nil), // 5: higress.networking.v1.RegistryConfig.VPort + (*RegistryConfig_VPort_Services)(nil), // 6: higress.networking.v1.RegistryConfig.VPort.Services + nil, // 7: higress.networking.v1.InnerMap.InnerMapEntry + (*wrappers.BoolValue)(nil), // 8: google.protobuf.BoolValue } var file_networking_v1_mcp_bridge_proto_depIdxs = []int32{ 1, // 0: higress.networking.v1.McpBridge.registries:type_name -> higress.networking.v1.RegistryConfig 2, // 1: higress.networking.v1.McpBridge.proxies:type_name -> higress.networking.v1.ProxyConfig - 6, // 2: higress.networking.v1.RegistryConfig.enableMCPServer:type_name -> google.protobuf.BoolValue - 6, // 3: higress.networking.v1.RegistryConfig.enableScopeMcpServers:type_name -> google.protobuf.BoolValue + 8, // 2: higress.networking.v1.RegistryConfig.enableMCPServer:type_name -> google.protobuf.BoolValue + 8, // 3: higress.networking.v1.RegistryConfig.enableScopeMcpServers:type_name -> google.protobuf.BoolValue 4, // 4: higress.networking.v1.RegistryConfig.metadata:type_name -> higress.networking.v1.RegistryConfig.MetadataEntry - 5, // 5: higress.networking.v1.InnerMap.inner_map:type_name -> higress.networking.v1.InnerMap.InnerMapEntry - 3, // 6: higress.networking.v1.RegistryConfig.MetadataEntry.value:type_name -> higress.networking.v1.InnerMap - 7, // [7:7] is the sub-list for method output_type - 7, // [7:7] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 5, // 5: higress.networking.v1.RegistryConfig.vport:type_name -> higress.networking.v1.RegistryConfig.VPort + 7, // 6: higress.networking.v1.InnerMap.inner_map:type_name -> higress.networking.v1.InnerMap.InnerMapEntry + 3, // 7: higress.networking.v1.RegistryConfig.MetadataEntry.value:type_name -> higress.networking.v1.InnerMap + 6, // 8: higress.networking.v1.RegistryConfig.VPort.services:type_name -> higress.networking.v1.RegistryConfig.VPort.Services + 9, // [9:9] is the sub-list for method output_type + 9, // [9:9] is the sub-list for method input_type + 9, // [9:9] is the sub-list for extension type_name + 9, // [9:9] is the sub-list for extension extendee + 0, // [0:9] is the sub-list for field type_name } func init() { file_networking_v1_mcp_bridge_proto_init() } @@ -713,6 +850,30 @@ func file_networking_v1_mcp_bridge_proto_init() { return nil } } + file_networking_v1_mcp_bridge_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RegistryConfig_VPort); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_networking_v1_mcp_bridge_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RegistryConfig_VPort_Services); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -720,7 +881,7 @@ func file_networking_v1_mcp_bridge_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_networking_v1_mcp_bridge_proto_rawDesc, NumEnums: 0, - NumMessages: 6, + NumMessages: 8, NumExtensions: 0, NumServices: 0, }, diff --git a/api/networking/v1/mcp_bridge.proto b/api/networking/v1/mcp_bridge.proto index e52d51644..f2a296961 100644 --- a/api/networking/v1/mcp_bridge.proto +++ b/api/networking/v1/mcp_bridge.proto @@ -76,6 +76,15 @@ message RegistryConfig { repeated string allowMcpServers = 24; map metadata = 25; string proxyName = 26; + message VPort { + uint32 default = 1; + message Services { + string name = 1; + uint32 value = 2; + } + repeated Services services = 2; + } + VPort vport = 27; } message ProxyConfig { diff --git a/api/networking/v1/mcp_bridge_deepcopy.gen.go b/api/networking/v1/mcp_bridge_deepcopy.gen.go index 076d85f4a..4b80a66b5 100644 --- a/api/networking/v1/mcp_bridge_deepcopy.gen.go +++ b/api/networking/v1/mcp_bridge_deepcopy.gen.go @@ -47,6 +47,48 @@ func (in *RegistryConfig) DeepCopyInterface() interface{} { return in.DeepCopy() } +// DeepCopyInto supports using RegistryConfig_VPort within kubernetes types, where deepcopy-gen is used. +func (in *RegistryConfig_VPort) DeepCopyInto(out *RegistryConfig_VPort) { + p := proto.Clone(in).(*RegistryConfig_VPort) + *out = *p +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RegistryConfig_VPort. Required by controller-gen. +func (in *RegistryConfig_VPort) DeepCopy() *RegistryConfig_VPort { + if in == nil { + return nil + } + out := new(RegistryConfig_VPort) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInterface is an autogenerated deepcopy function, copying the receiver, creating a new RegistryConfig_VPort. Required by controller-gen. +func (in *RegistryConfig_VPort) DeepCopyInterface() interface{} { + return in.DeepCopy() +} + +// DeepCopyInto supports using RegistryConfig_VPort_Services within kubernetes types, where deepcopy-gen is used. +func (in *RegistryConfig_VPort_Services) DeepCopyInto(out *RegistryConfig_VPort_Services) { + p := proto.Clone(in).(*RegistryConfig_VPort_Services) + *out = *p +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RegistryConfig_VPort_Services. Required by controller-gen. +func (in *RegistryConfig_VPort_Services) DeepCopy() *RegistryConfig_VPort_Services { + if in == nil { + return nil + } + out := new(RegistryConfig_VPort_Services) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInterface is an autogenerated deepcopy function, copying the receiver, creating a new RegistryConfig_VPort_Services. Required by controller-gen. +func (in *RegistryConfig_VPort_Services) DeepCopyInterface() interface{} { + return in.DeepCopy() +} + // DeepCopyInto supports using ProxyConfig within kubernetes types, where deepcopy-gen is used. func (in *ProxyConfig) DeepCopyInto(out *ProxyConfig) { p := proto.Clone(in).(*ProxyConfig) diff --git a/api/networking/v1/mcp_bridge_json.gen.go b/api/networking/v1/mcp_bridge_json.gen.go index a129f4bc0..bd719b572 100644 --- a/api/networking/v1/mcp_bridge_json.gen.go +++ b/api/networking/v1/mcp_bridge_json.gen.go @@ -28,6 +28,28 @@ func (this *RegistryConfig) UnmarshalJSON(b []byte) error { return McpBridgeUnmarshaler.Unmarshal(bytes.NewReader(b), this) } +// MarshalJSON is a custom marshaler for RegistryConfig_VPort +func (this *RegistryConfig_VPort) MarshalJSON() ([]byte, error) { + str, err := McpBridgeMarshaler.MarshalToString(this) + return []byte(str), err +} + +// UnmarshalJSON is a custom unmarshaler for RegistryConfig_VPort +func (this *RegistryConfig_VPort) UnmarshalJSON(b []byte) error { + return McpBridgeUnmarshaler.Unmarshal(bytes.NewReader(b), this) +} + +// MarshalJSON is a custom marshaler for RegistryConfig_VPort_Services +func (this *RegistryConfig_VPort_Services) MarshalJSON() ([]byte, error) { + str, err := McpBridgeMarshaler.MarshalToString(this) + return []byte(str), err +} + +// UnmarshalJSON is a custom unmarshaler for RegistryConfig_VPort_Services +func (this *RegistryConfig_VPort_Services) UnmarshalJSON(b []byte) error { + return McpBridgeUnmarshaler.Unmarshal(bytes.NewReader(b), this) +} + // MarshalJSON is a custom marshaler for ProxyConfig func (this *ProxyConfig) MarshalJSON() ([]byte, error) { str, err := McpBridgeMarshaler.MarshalToString(this) diff --git a/helm/core/crds/customresourcedefinitions.gen.yaml b/helm/core/crds/customresourcedefinitions.gen.yaml index a7faf4fa4..c5c899464 100644 --- a/helm/core/crds/customresourcedefinitions.gen.yaml +++ b/helm/core/crds/customresourcedefinitions.gen.yaml @@ -332,6 +332,20 @@ spec: type: string type: type: string + vport: + properties: + default: + type: integer + services: + items: + properties: + name: + type: string + value: + type: integer + type: object + type: array + type: object zkServicesPath: items: type: string diff --git a/registry/eureka/watcher.go b/registry/eureka/watcher.go index e7ed054bf..8b3b06158 100644 --- a/registry/eureka/watcher.go +++ b/registry/eureka/watcher.go @@ -81,6 +81,12 @@ func NewWatcher(cache memory.Cache, opts ...WatcherOption) (provider.Watcher, er return w, nil } +func WithVport(vport *apiv1.RegistryConfig_VPort) WatcherOption { + return func(w *watcher) { + w.Vport = vport + } +} + func WithEurekaFullRefreshInterval(refreshInterval int64) WatcherOption { return func(w *watcher) { if refreshInterval < int64(DefaultFullRefreshIntervalLimit) { @@ -151,6 +157,9 @@ func (w *watcher) Stop() { w.cache.DeleteServiceWrapper(makeHost(serviceName)) } w.UpdateService() + w.isStop = true + close(w.stop) + w.Ready(false) } func (w *watcher) IsHealthy() bool { @@ -200,7 +209,7 @@ func (w *watcher) subscribe(service *fargo.Application) error { defer w.UpdateService() if len(service.Instances) != 0 { - se, err := generateServiceEntry(service) + se, err := w.generateServiceEntry(service) if err != nil { return err } @@ -252,10 +261,10 @@ func convertMap(m map[string]interface{}) map[string]string { return result } -func generateServiceEntry(app *fargo.Application) (*v1alpha3.ServiceEntry, error) { +func (w *watcher) generateServiceEntry(app *fargo.Application) (*v1alpha3.ServiceEntry, error) { portList := make([]*v1alpha3.ServicePort, 0) endpoints := make([]*v1alpha3.WorkloadEntry, 0) - + sePort := provider.GetServiceVport(makeHost(app.Name), w.Vport) for _, instance := range app.Instances { protocol := common.HTTP if val, _ := instance.Metadata.GetString("protocol"); val != "" { @@ -269,7 +278,13 @@ func generateServiceEntry(app *fargo.Application) (*v1alpha3.ServiceEntry, error 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) + } } endpoint := v1alpha3.WorkloadEntry{ Address: instance.IPAddr, diff --git a/registry/nacos/v2/watcher.go b/registry/nacos/v2/watcher.go index b2834a321..2125598f1 100644 --- a/registry/nacos/v2/watcher.go +++ b/registry/nacos/v2/watcher.go @@ -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 diff --git a/registry/nacos/watcher.go b/registry/nacos/watcher.go index 3c86c67f0..07f3b134b 100644 --- a/registry/nacos/watcher.go +++ b/registry/nacos/watcher.go @@ -119,6 +119,12 @@ func NewWatcher(cache memory.Cache, opts ...WatcherOption) (provider.Watcher, er return w, nil } +func WithVport(vport *apiv1.RegistryConfig_VPort) WatcherOption { + return func(w *watcher) { + w.Vport = vport + } +} + func WithNacosNamespaceId(nacosNamespaceId string) WatcherOption { return func(w *watcher) { if nacosNamespaceId == "" { @@ -326,7 +332,7 @@ func (w *watcher) getSubscribeCallback(groupName string, serviceName string) fun func (w *watcher) generateServiceEntry(host string, services []model.SubscribeService) *v1alpha3.ServiceEntry { portList := make([]*v1alpha3.ServicePort, 0) endpoints := make([]*v1alpha3.WorkloadEntry, 0) - + sePort := provider.GetServiceVport(host, w.Vport) for _, service := range services { protocol := common.HTTP if service.Metadata != nil && service.Metadata["protocol"] != "" { @@ -340,7 +346,13 @@ func (w *watcher) generateServiceEntry(host string, services []model.SubscribeSe 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) + } } endpoint := v1alpha3.WorkloadEntry{ Address: service.Ip, diff --git a/registry/reconcile/reconcile.go b/registry/reconcile/reconcile.go index e7c1baeeb..fb1f8f150 100644 --- a/registry/reconcile/reconcile.go +++ b/registry/reconcile/reconcile.go @@ -205,6 +205,7 @@ func (r *Reconciler) generateWatcherFromRegistryConfig(registry *apiv1.RegistryC nacos.WithNacosGroups(registry.NacosGroups), nacos.WithNacosRefreshInterval(registry.NacosRefreshInterval), nacos.WithAuthOption(authOption), + nacos.WithVport(registry.Vport), ) case string(Nacos2), string(Nacos3): watcher, err = nacosv2.NewWatcher( @@ -226,6 +227,7 @@ func (r *Reconciler) generateWatcherFromRegistryConfig(registry *apiv1.RegistryC nacosv2.WithClusterId(r.clusterId), nacosv2.WithNamespace(r.namespace), nacosv2.WithAuthOption(authOption), + nacosv2.WithVport(registry.Vport), ) case string(Zookeeper): watcher, err = zookeeper.NewWatcher( @@ -266,6 +268,7 @@ func (r *Reconciler) generateWatcherFromRegistryConfig(registry *apiv1.RegistryC eureka.WithDomain(registry.Domain), eureka.WithType(registry.Type), eureka.WithPort(registry.Port), + eureka.WithVport(registry.Vport), ) default: return nil, errors.New("unsupported registry type:" + registry.Type) diff --git a/registry/watcher.go b/registry/watcher.go index 7c664a63c..82785387d 100644 --- a/registry/watcher.go +++ b/registry/watcher.go @@ -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 +} \ No newline at end of file