Skip to content

Commit 4078ff5

Browse files
ZhengYa-0110SongZhen0704
authored andcommitted
feat: ip/port type biz service vpc is not required
1 parent 46851f4 commit 4078ff5

2 files changed

Lines changed: 346 additions & 130 deletions

File tree

server/controller/trisolaris/metadata/service_data.go

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

374374
var ipPorts []customServiceIPPortKey
375-
if len(cs.VPCIDs) != 1 {
375+
var vpcID int
376+
switch len(cs.VPCIDs) {
377+
case 0:
378+
// VPCIDs 为空,vpcID=0 代表匹配所有 VPC
379+
vpcID = 0
380+
case 1:
381+
vpcID = cs.VPCIDs[0]
382+
default:
376383
log.Warningf("multi vpcs not supported for ip/port type custom_service (id: %v)", cs.ID)
377384
continue
378385
}
379-
vpcID := cs.VPCIDs[0]
380386
if cs.Type == CUSTOM_SERVICE_TYPE_IP {
381387
ips := resources
382388
for _, ip := range ips {
@@ -766,10 +772,13 @@ func (s *ServiceDataOP) mergeCustomServices(dbDataCache *dbcache.DBDataCache) []
766772
service := &trident.ServiceInfo{
767773
Type: &serviceTypeCustomService,
768774
Id: proto.Uint32(uint32(customService.ID)),
769-
EpcId: proto.Uint32(uint32(ipPort.vpcID)),
770775
Ips: []string{ipPort.ip},
771776
ServerPorts: serverPorts,
772777
}
778+
// vpcID=0 代表匹配所有 VPC,不设置 EpcId(保持 nil)
779+
if ipPort.vpcID != 0 {
780+
service.EpcId = proto.Uint32(uint32(ipPort.vpcID))
781+
}
773782
services = append(services, service)
774783
}
775784
}

0 commit comments

Comments
 (0)