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) } }