From e5e19835f94aeb396848c23f77ded078e52b8245 Mon Sep 17 00:00:00 2001 From: gyurix Date: Mon, 15 Jun 2026 12:00:26 +0200 Subject: [PATCH] fix: use prefix matching instead of dash stripping for container resolution The previous logic stripped dashes from both the lookup name and container/selector names, performing an exact match after removal. This failed for cases like "wireguardproxy-client" matching "wireguardproxyclient" or "app-1"/"app-2" matching "app-x", because the dash removal produced different strings. Change to extract the prefix before the first dash in the lookup name, then match it against the beginning of container/selector names. This preserves the intended relationship while allowing matching of dashed variants with prefix-based patterns. --- network-go/resolver/resolver.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/network-go/resolver/resolver.go b/network-go/resolver/resolver.go index 09a6f31..8d4dae3 100644 --- a/network-go/resolver/resolver.go +++ b/network-go/resolver/resolver.go @@ -47,13 +47,14 @@ func (r *Resolver) Resolve(name string) []string { } } - // If no exact match, try stripping dashes from the lookup name + // If no exact match, try prefix matching: extract the prefix before the first dash + // and match any container/selector starting with that prefix. + // This allows "wireguardproxy-client" to match "wireguardproxyclient" (after dash stripping) + // or "app-1"/"app-2" to match "app-x". if len(ips) == 0 && strings.Contains(name, "-") { - strippedName := strings.ReplaceAll(name, "-", "") + prefix := name[:strings.Index(name, "-")] for _, ipCfg := range r.cfg.IPs { - strippedContainer := strings.ReplaceAll(ipCfg.ContainerName, "-", "") - strippedSelector := strings.ReplaceAll(ipCfg.Selector, "-", "") - if strippedContainer == strippedName || strippedSelector == strippedName { + if strings.HasPrefix(ipCfg.ContainerName, prefix) || strings.HasPrefix(ipCfg.Selector, prefix) { ips = append(ips, ipCfg.IP) } }