Skip to content

Commit 76de14a

Browse files
ZhengYa-0110SongZhen0704
authored andcommitted
feat: ip/port type biz service vpc is not required
1 parent 71c59ce commit 76de14a

2 files changed

Lines changed: 314 additions & 98 deletions

File tree

server/controller/trisolaris/metadata/service_data.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,17 @@ func (r *ServiceRawData) mergeCustomServices(md *MetaData, dbDataCache *dbcache.
387387
}
388388

389389
var ipPorts []customServiceIPPortKey
390-
if len(cs.VPCIDs) != 1 {
390+
var vpcID int
391+
switch len(cs.VPCIDs) {
392+
case 0:
393+
// VPCIDs 为空,vpcID=0 代表匹配所有 VPC
394+
vpcID = 0
395+
case 1:
396+
vpcID = cs.VPCIDs[0]
397+
default:
391398
log.Warningf("multi vpcs not supported for ip/port type custom_service (id: %v)", cs.ID)
392399
continue
393400
}
394-
vpcID := cs.VPCIDs[0]
395401
if cs.Type == CUSTOM_SERVICE_TYPE_IP {
396402
ips := resources
397403
for _, ip := range ips {
@@ -896,10 +902,13 @@ func (s *ServiceDataOP) mergeCustomServices(dbDataCache *dbcache.DBDataCache) []
896902
service := &trident.ServiceInfo{
897903
Type: &serviceTypeCustomService,
898904
Id: proto.Uint32(uint32(customService.ID)),
899-
EpcId: proto.Uint32(uint32(ipPort.vpcID)),
900905
Ips: []string{ipPort.ip},
901906
ServerPorts: serverPorts,
902907
}
908+
// vpcID=0 代表匹配所有 VPC,不设置 EpcId(保持 nil)
909+
if ipPort.vpcID != 0 {
910+
service.EpcId = proto.Uint32(uint32(ipPort.vpcID))
911+
}
903912
services = append(services, service)
904913
}
905914
}

0 commit comments

Comments
 (0)