diff --git a/controller/execute.go b/controller/execute.go index d6b465526d..4a4654adb8 100644 --- a/controller/execute.go +++ b/controller/execute.go @@ -161,8 +161,6 @@ func buildProvider( zoneNameFilter := endpoint.NewDomainFilter(cfg.ZoneNameFilter) zoneIDFilter := provider.NewZoneIDFilter(cfg.ZoneIDFilter) - zoneTypeFilter := provider.NewZoneTypeFilter(cfg.AWSZoneType) - zoneTagFilter := provider.NewZoneTagFilter(cfg.AWSZoneTagFilter) switch cfg.Provider { case "akamai": @@ -181,6 +179,10 @@ func buildProvider( case "alibabacloud": p, err = alibabacloud.NewAlibabaCloudProvider(cfg.AlibabaCloudConfigFile, domainFilter, zoneIDFilter, cfg.AlibabaCloudZoneType, cfg.DryRun) case "aws": + + zoneTypeFilter := provider.NewZoneTypeFilter(cfg.AWSZoneType) + zoneTagFilter := provider.NewZoneTagFilter(cfg.AWSZoneTagFilter) + configs := aws.CreateV2Configs(cfg) clients := make(map[string]aws.Route53API, len(configs)) for profile, config := range configs { diff --git a/provider/aws/aws.go b/provider/aws/aws.go index a5d964b67f..648e8a28de 100644 --- a/provider/aws/aws.go +++ b/provider/aws/aws.go @@ -397,8 +397,22 @@ func (p *AWSProvider) zones(ctx context.Context) (map[string]*profiledZone, erro if !p.zoneIDFilter.Match(*zone.Id) { continue } + var IsPublicZone = false - if !p.zoneTypeFilter.Match(zone) { + // If the zone has no config we assume it's a public zone since the config's field + // `PrivateZone` is false by default in go. + if zone.Config == nil { + IsPublicZone = p.zoneTypeFilter.ZoneType == provider.ZoneTypePublic + } + + switch p.zoneTypeFilter.ZoneType { + case provider.ZoneTypePublic: + IsPublicZone = !zone.Config.PrivateZone + case provider.ZoneTypePrivate: + IsPublicZone = zone.Config.PrivateZone + } + + if !IsPublicZone && !p.zoneTypeFilter.Match(zone) { continue } diff --git a/provider/zone_type_filter.go b/provider/zone_type_filter.go index c595a4a9c5..3459525756 100644 --- a/provider/zone_type_filter.go +++ b/provider/zone_type_filter.go @@ -16,56 +16,38 @@ limitations under the License. package provider -import ( - route53types "github.com/aws/aws-sdk-go-v2/service/route53/types" -) - const ( - zoneTypePublic = "public" - zoneTypePrivate = "private" + ZoneTypePublic = "public" + ZoneTypePrivate = "private" ) // ZoneTypeFilter holds a zone type to filter for. type ZoneTypeFilter struct { - zoneType string + ZoneType string } // NewZoneTypeFilter returns a new ZoneTypeFilter given a zone type to filter for. func NewZoneTypeFilter(zoneType string) ZoneTypeFilter { - return ZoneTypeFilter{zoneType: zoneType} + return ZoneTypeFilter{ZoneType: zoneType} } // Match checks whether a zone matches the zone type that's filtered for. func (f ZoneTypeFilter) Match(rawZoneType interface{}) bool { // An empty zone filter includes all hosted zones. - if f.zoneType == "" { + if f.ZoneType == "" { return true } switch zoneType := rawZoneType.(type) { // Given a zone type we return true if the given zone matches this type. case string: - switch f.zoneType { - case zoneTypePublic: - return zoneType == zoneTypePublic - case zoneTypePrivate: - return zoneType == zoneTypePrivate - } - case route53types.HostedZone: - // If the zone has no config we assume it's a public zone since the config's field - // `PrivateZone` is false by default in go. - if zoneType.Config == nil { - return f.zoneType == zoneTypePublic - } - - switch f.zoneType { - case zoneTypePublic: - return !zoneType.Config.PrivateZone - case zoneTypePrivate: - return zoneType.Config.PrivateZone + switch f.ZoneType { + case ZoneTypePublic: + return zoneType == ZoneTypePublic + case ZoneTypePrivate: + return zoneType == ZoneTypePrivate } } - // We return false on any other path, e.g. unknown zone type filter value. return false } diff --git a/provider/zone_type_filter_test.go b/provider/zone_type_filter_test.go index 903d8e8765..844701a0e0 100644 --- a/provider/zone_type_filter_test.go +++ b/provider/zone_type_filter_test.go @@ -19,16 +19,12 @@ package provider import ( "testing" - route53types "github.com/aws/aws-sdk-go-v2/service/route53/types" - "github.com/stretchr/testify/assert" ) func TestZoneTypeFilterMatch(t *testing.T) { publicZoneStr := "public" privateZoneStr := "private" - publicZoneAWS := route53types.HostedZone{Config: &route53types.HostedZoneConfig{PrivateZone: false}} - privateZoneAWS := route53types.HostedZone{Config: &route53types.HostedZoneConfig{PrivateZone: true}} for _, tc := range []struct { zoneTypeFilter string @@ -36,19 +32,19 @@ func TestZoneTypeFilterMatch(t *testing.T) { zones []interface{} }{ { - "", true, []interface{}{publicZoneStr, privateZoneStr, route53types.HostedZone{}}, + "", true, []interface{}{publicZoneStr, privateZoneStr}, }, { - "public", true, []interface{}{publicZoneStr, publicZoneAWS, route53types.HostedZone{}}, + "public", true, []interface{}{publicZoneStr}, }, { - "public", false, []interface{}{privateZoneStr, privateZoneAWS}, + "public", false, []interface{}{privateZoneStr}, }, { - "private", true, []interface{}{privateZoneStr, privateZoneAWS}, + "private", true, []interface{}{privateZoneStr}, }, { - "private", false, []interface{}{publicZoneStr, publicZoneAWS, route53types.HostedZone{}}, + "private", false, []interface{}{publicZoneStr}, }, { "unknown", false, []interface{}{publicZoneStr},