fix(resolver): strip all dashes when matching container names
continuous-integration/drone/push Build is failing
continuous-integration/drone/push Build is failing
Instead of prefix matching on the part before the first dash, now strip all dashes from both the lookup name and the stored container/selector names and compare exactly. This improves matching accuracy for names containing multiple dashes or dashes in varying positions.
This commit is contained in:
@@ -230,4 +230,4 @@ docker run -d \
|
|||||||
-e WATCH_PERIOD_SECONDS=30 \
|
-e WATCH_PERIOD_SECONDS=30 \
|
||||||
-e DEBUG=false \
|
-e DEBUG=false \
|
||||||
--name network-go \
|
--name network-go \
|
||||||
network-go
|
safebox/network-go
|
||||||
@@ -47,11 +47,13 @@ func (r *Resolver) Resolve(name string) []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no exact match, try prefix matching (extract prefix before first dash)
|
// If no exact match, try stripping dashes from the lookup name
|
||||||
if len(ips) == 0 && strings.Contains(name, "-") {
|
if len(ips) == 0 && strings.Contains(name, "-") {
|
||||||
prefix := name[:strings.Index(name, "-")]
|
strippedName := strings.ReplaceAll(name, "-", "")
|
||||||
for _, ipCfg := range r.cfg.IPs {
|
for _, ipCfg := range r.cfg.IPs {
|
||||||
if strings.HasPrefix(ipCfg.ContainerName, prefix) || strings.HasPrefix(ipCfg.Selector, prefix) {
|
strippedContainer := strings.ReplaceAll(ipCfg.ContainerName, "-", "")
|
||||||
|
strippedSelector := strings.ReplaceAll(ipCfg.Selector, "-", "")
|
||||||
|
if strippedContainer == strippedName || strippedSelector == strippedName {
|
||||||
ips = append(ips, ipCfg.IP)
|
ips = append(ips, ipCfg.IP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user