Skip to content

Commit

Permalink
fix(aws): don't try to create records for invalid endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
yurrriq committed Mar 4, 2024
1 parent 6cf4783 commit 1750513
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@ func (p *AWSProvider) newChanges(action string, endpoints []*endpoint.Endpoint)
changes := make(Route53Changes, 0, len(endpoints))

for _, endpoint := range endpoints {
if endpoint == nil {
continue
}
change, dualstack := p.newChange(action, endpoint)
changes = append(changes, change)
if dualstack {
Expand All @@ -681,6 +684,10 @@ func (p *AWSProvider) newChanges(action string, endpoints []*endpoint.Endpoint)
// added to match the endpoints generated from existing alias records in Route53.
func (p *AWSProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) ([]*endpoint.Endpoint, error) {
for _, ep := range endpoints {
if ep == nil {
continue
}

alias := false

if aliasString, ok := ep.GetProviderSpecificProperty(providerSpecificAlias); ok {
Expand Down
40 changes: 40 additions & 0 deletions provider/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,28 @@ func TestAWSsubmitChangesRetryOnError(t *testing.T) {
require.True(t, containsRecordWithDNSName(records, "fail__edns_housekeeping.zone-1.ext-dns-test-2.teapot.zalan.do"))
}


func TestAWSsubmitChangesWithNilEndpoint(t *testing.T) {
provider, _ := newAWSProvider(t, endpoint.NewDomainFilter([]string{"ext-dns-test-2.teapot.zalan.do."}), provider.NewZoneIDFilter([]string{}), provider.NewZoneTypeFilter(""), defaultEvaluateTargetHealth, false, nil)

endpoints := []*endpoint.Endpoint{
nil,
}

ctx := context.Background()
zones, _ := provider.Zones(ctx)
records, _ := provider.Records(ctx)
cs := make(Route53Changes, 0, len(endpoints))
cs = append(cs, provider.newChanges(route53.ChangeActionCreate, endpoints)...)

require.NoError(t, provider.submitChanges(ctx, cs, zones))

records, err := provider.Records(ctx)
require.NoError(t, err)

validateEndpoints(t, provider, records, []*endpoint.Endpoint{})
}

func TestAWSBatchChangeSet(t *testing.T) {
var cs Route53Changes

Expand Down Expand Up @@ -1734,6 +1756,24 @@ func TestAWSCreateRecordsWithALIAS(t *testing.T) {
}
}

func TestAWSAdjustEndpointsWithNilEndpoint(t *testing.T) {
provider, _ := newAWSProvider(t, endpoint.NewDomainFilter([]string{"ext-dns-test-2.teapot.zalan.do."}), provider.NewZoneIDFilter([]string{}), provider.NewZoneTypeFilter(""), defaultEvaluateTargetHealth, false, nil)

records := []*endpoint.Endpoint{
nil,
}

adjusted, err := provider.AdjustEndpoints(records)
require.NoError(t, err)
require.NoError(t, provider.ApplyChanges(context.Background(), &plan.Changes{
Create: adjusted,
}))

recordSets := listAWSRecords(t, provider.client, "/hostedzone/zone-1.ext-dns-test-2.teapot.zalan.do.")

validateRecords(t, recordSets, []*route53.ResourceRecordSet{})
}

func TestAWSisLoadBalancer(t *testing.T) {
for _, tc := range []struct {
target string
Expand Down

0 comments on commit 1750513

Please sign in to comment.