fix: use prefix matching instead of dash stripping for container resolution
continuous-integration/drone/push Build is passing

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.
This commit is contained in:
gyurix
2026-06-15 12:00:26 +02:00
parent f9513cd98a
commit e5e19835f9
+6 -5
View File
@@ -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)
}
}