The default port is used when there is no port number for k8s (#2598)

* k8s 没有端口号时使用默认端口

* Modify the not port test
This commit is contained in:
bigrocs
2022-11-27 09:00:11 +08:00
committed by GitHub
parent b1c3c21c81
commit 90828a0d4a
3 changed files with 29 additions and 17 deletions

View File

@@ -32,18 +32,21 @@ func ParseTarget(target resolver.Target) (Service, error) {
}
endpoints := targets.GetEndpoints(target)
segs := strings.SplitN(endpoints, colon, 2)
if len(segs) < 2 {
return emptyService, fmt.Errorf("bad endpoint: %s", endpoints)
if strings.Contains(endpoints, colon) {
segs := strings.SplitN(endpoints, colon, 2)
if len(segs) < 2 {
return emptyService, fmt.Errorf("bad endpoint: %s", endpoints)
}
service.Name = segs[0]
port, err := strconv.Atoi(segs[1])
if err != nil {
return emptyService, err
}
service.Port = port
} else {
service.Name = endpoints
}
service.Name = segs[0]
port, err := strconv.Atoi(segs[1])
if err != nil {
return emptyService, err
}
service.Port = port
return service, nil
}