From b1084bef4f6dfb934074212025b7221fd2ed4375 Mon Sep 17 00:00:00 2001 From: itspngu Date: Thu, 15 Jun 2023 15:52:08 +0100 Subject: [PATCH 1/2] fix: filter peering zones in google provider --- provider/google/google.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/provider/google/google.go b/provider/google/google.go index 5fce653f58..cc01a96423 100644 --- a/provider/google/google.go +++ b/provider/google/google.go @@ -177,11 +177,15 @@ func (p *GoogleProvider) Zones(ctx context.Context) (map[string]*dns.ManagedZone f := func(resp *dns.ManagedZonesListResponse) error { for _, zone := range resp.ManagedZones { - if p.domainFilter.Match(zone.DnsName) && p.zoneTypeFilter.Match(zone.Visibility) && (p.zoneIDFilter.Match(fmt.Sprintf("%v", zone.Id)) || p.zoneIDFilter.Match(fmt.Sprintf("%v", zone.Name))) { - zones[zone.Name] = zone - log.Debugf("Matched %s (zone: %s) (visibility: %s)", zone.DnsName, zone.Name, zone.Visibility) + if zone.PeeringConfig == nil { + if p.domainFilter.Match(zone.DnsName) && p.zoneTypeFilter.Match(zone.Visibility) && (p.zoneIDFilter.Match(fmt.Sprintf("%v", zone.Id)) || p.zoneIDFilter.Match(fmt.Sprintf("%v", zone.Name))) { + zones[zone.Name] = zone + log.Debugf("Matched %s (zone: %s) (visibility: %s)", zone.DnsName, zone.Name, zone.Visibility) + } else { + log.Debugf("Filtered %s (zone: %s) (visibility: %s)", zone.DnsName, zone.Name, zone.Visibility) + } } else { - log.Debugf("Filtered %s (zone: %s) (visibility: %s)", zone.DnsName, zone.Name, zone.Visibility) + log.Debugf("Filtered peering zone %s (zone: %s) (visibility: %s)", zone.DnsName, zone.Name, zone.Visibility) } } From a7884f191a5d1e8a77984c79ae98df1cc7f54f4d Mon Sep 17 00:00:00 2001 From: Andrew Chinnadorai Date: Mon, 19 Jun 2023 16:17:32 +0100 Subject: [PATCH 2/2] Add tests for filtering peering zones --- provider/google/google_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/provider/google/google_test.go b/provider/google/google_test.go index bc321200b7..55dff0fb5d 100644 --- a/provider/google/google_test.go +++ b/provider/google/google_test.go @@ -237,6 +237,17 @@ func TestGoogleZonesVisibilityFilterPrivate(t *testing.T) { }) } +func TestGoogleZonesVisibilityFilterPrivatePeering(t *testing.T) { + provider := newGoogleProviderZoneOverlap(t, endpoint.NewDomainFilter([]string{"svc.local."}), provider.NewZoneIDFilter([]string{""}), provider.NewZoneTypeFilter("private"), false, []*endpoint.Endpoint{}) + + zones, err := provider.Zones(context.Background()) + require.NoError(t, err) + + validateZones(t, zones, map[string]*dns.ManagedZone{ + "svc-local": {Name: "svc-local", DnsName: "svc.local.", Id: 1005, Visibility: "private"}, + }) +} + func TestGoogleZones(t *testing.T) { provider := newGoogleProvider(t, endpoint.NewDomainFilter([]string{"ext-dns-test-2.gcp.zalan.do."}), provider.NewZoneIDFilter([]string{""}), false, []*endpoint.Endpoint{}) @@ -744,6 +755,22 @@ func newGoogleProviderZoneOverlap(t *testing.T, domainFilter endpoint.DomainFilt Visibility: "private", }) + + createZone(t, provider, &dns.ManagedZone{ + Name: "svc-local", + DnsName: "svc.local.", + Id: 10005, + Visibility: "private", + }) + + createZone(t, provider, &dns.ManagedZone{ + Name: "svc-local-peer", + DnsName: "svc.local.", + Id: 10006, + Visibility: "private", + PeeringConfig: &dns.ManagedZonePeeringConfig{TargetNetwork: nil}, + }) + provider.dryRun = dryRun return provider