fix(resolver): strip all dashes when matching container names
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:
gyurix
2026-06-15 11:55:00 +02:00
parent dea2fca7fb
commit f9513cd98a
2 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -230,4 +230,4 @@ docker run -d \
-e WATCH_PERIOD_SECONDS=30 \
-e DEBUG=false \
--name network-go \
network-go
safebox/network-go
+5 -3
View File
@@ -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, "-") {
prefix := name[:strings.Index(name, "-")]
strippedName := strings.ReplaceAll(name, "-", "")
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)
}
}