mirror of
https://github.com/coredns/coredns.git
synced 2025-08-06 06:17:00 +02:00
Properly create hostname from IPv6 (#7431)
Generate valid hostname from IPv6 when the address ends with `::`. Signed-off-by: Guillaume Jacquet <guillaume.jacquet@gmail.com>
This commit is contained in:
parent
17020f09a8
commit
1025a199e9
@ -351,7 +351,11 @@ func endpointHostname(addr object.EndpointAddress, endpointNameMode bool) string
|
||||
return strings.ReplaceAll(addr.IP, ".", "-")
|
||||
}
|
||||
if strings.Contains(addr.IP, ":") {
|
||||
return strings.ReplaceAll(addr.IP, ":", "-")
|
||||
ipv6Hostname := strings.ReplaceAll(addr.IP, ":", "-")
|
||||
if strings.HasSuffix(ipv6Hostname, "-") {
|
||||
return ipv6Hostname + "0"
|
||||
}
|
||||
return ipv6Hostname
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ func TestEndpointHostname(t *testing.T) {
|
||||
{"10.11.12.13", "epname", "epname", "hello-abcde", false},
|
||||
{"10.11.12.13", "epname", "epname", "hello-abcde", true},
|
||||
{"10.11.12.13", "", "hello-abcde", "hello-abcde", true},
|
||||
{"2001:db8:3333:4444:5555:6666:7777:8888", "", "2001-db8-3333-4444-5555-6666-7777-8888", "", false},
|
||||
{"2001:db8:3333:4444:5555:6666::", "", "2001-db8-3333-4444-5555-6666--0", "", false},
|
||||
}
|
||||
for _, test := range tests {
|
||||
result := endpointHostname(object.EndpointAddress{IP: test.ip, Hostname: test.hostname, TargetRefName: test.podName}, test.endpointNameMode)
|
||||
|
Loading…
Reference in New Issue
Block a user