mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2026-05-05 22:56:09 +02:00
chore: improve canonicalHostedZone handling
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
This commit is contained in:
parent
290f8c848d
commit
55e640bd43
@ -1161,8 +1161,10 @@ func isAWSAlias(ep *endpoint.Endpoint) string {
|
||||
|
||||
// canonicalHostedZone returns the matching canonical zone for a given hostname.
|
||||
func canonicalHostedZone(hostname string) string {
|
||||
for suffix, zone := range canonicalHostedZones {
|
||||
if strings.HasSuffix(hostname, suffix) {
|
||||
parts := strings.Split(hostname, ".")
|
||||
for i := 0; i < len(parts); i++ {
|
||||
suffix := strings.Join(parts[i:], ".")
|
||||
if zone, exists := canonicalHostedZones[suffix]; exists {
|
||||
return zone
|
||||
}
|
||||
}
|
||||
|
||||
@ -1882,6 +1882,14 @@ func TestAWSCanonicalHostedZone(t *testing.T) {
|
||||
assert.Equal(t, "", zone, "no canonical zone should be returned for a non-aws hostname")
|
||||
}
|
||||
|
||||
func BenchmarkTestAWSCanonicalHostedZone(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for suffix, _ := range canonicalHostedZones {
|
||||
_ = canonicalHostedZone(fmt.Sprintf("foo.%s", suffix))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAWSSuitableZones(t *testing.T) {
|
||||
zones := map[string]*profiledZone{
|
||||
// Public domain
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user