From f9513cd98aa325088dc408384d41fd0fb6337822 Mon Sep 17 00:00:00 2001 From: gyurix Date: Mon, 15 Jun 2026 11:55:00 +0200 Subject: [PATCH] fix(resolver): strip all dashes when matching container names 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. --- network-go/implementation.md | 2 +- network-go/resolver/resolver.go | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/network-go/implementation.md b/network-go/implementation.md index 6e2bb62..ba4988e 100644 --- a/network-go/implementation.md +++ b/network-go/implementation.md @@ -230,4 +230,4 @@ docker run -d \ -e WATCH_PERIOD_SECONDS=30 \ -e DEBUG=false \ --name network-go \ - network-go \ No newline at end of file + safebox/network-go \ No newline at end of file diff --git a/network-go/resolver/resolver.go b/network-go/resolver/resolver.go index c5a867a..09a6f31 100644 --- a/network-go/resolver/resolver.go +++ b/network-go/resolver/resolver.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, "-") { - 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) } }