Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws): add soft error #4886

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func (p *AWSProvider) records(ctx context.Context, zones map[string]*profiledZon
for paginator.HasMorePages() {
resp, err := paginator.NextPage(ctx)
if err != nil {
return nil, fmt.Errorf("failed to list resource records sets for zone %s using aws profile %q: %w", *z.zone.Id, z.profile, err)
return nil, provider.NewSoftError(fmt.Errorf("failed to list resource records sets for zone %s using aws profile %q: %w", *z.zone.Id, z.profile, err))
}

for _, r := range resp.ResourceRecordSets {
Expand Down
28 changes: 28 additions & 0 deletions provider/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func NewRoute53APIStub(t *testing.T) *Route53APIStub {
}

func (r *Route53APIStub) ListResourceRecordSets(ctx context.Context, input *route53.ListResourceRecordSetsInput, optFns ...func(options *route53.Options)) (*route53.ListResourceRecordSetsOutput, error) {
if r.m.isMocked("ListResourceRecordSets", input) {
return r.m.ListResourceRecordSets(ctx, input, optFns...)
}

output := &route53.ListResourceRecordSetsOutput{} // TODO: Support optional input args.
require.NotNil(r.t, input.MaxItems)
assert.EqualValues(r.t, route53PageSize, *input.MaxItems)
Expand Down Expand Up @@ -240,6 +244,14 @@ type dynamicMock struct {
mock.Mock
}

func (m *dynamicMock) ListResourceRecordSets(ctx context.Context, input *route53.ListResourceRecordSetsInput, optFns ...func(options *route53.Options)) (*route53.ListResourceRecordSetsOutput, error) {
args := m.Called(input)
if args.Get(0) != nil {
return args.Get(0).(*route53.ListResourceRecordSetsOutput), args.Error(1)
}
return nil, args.Error(1)
}

func (m *dynamicMock) ChangeResourceRecordSets(input *route53.ChangeResourceRecordSetsInput) (*route53.ChangeResourceRecordSetsOutput, error) {
args := m.Called(input)
if args.Get(0) != nil {
Expand Down Expand Up @@ -518,6 +530,22 @@ func TestAWSRecords(t *testing.T) {
})
}

func TestAWSRecordsSoftError(t *testing.T) {
pvd, subClient := newAWSProvider(t, endpoint.NewDomainFilter([]string{"ext-dns-test-2.teapot.zalan.do."}), provider.NewZoneIDFilter([]string{}), provider.NewZoneTypeFilter(""), false, false, []route53types.ResourceRecordSet{
{
Name: aws.String("list-test.zone-1.ext-dns-test-2.teapot.zalan.do."),
Type: route53types.RRTypeA,
TTL: aws.Int64(recordTTL),
ResourceRecords: []route53types.ResourceRecord{{Value: aws.String("1.2.3.4")}},
},
})

subClient.MockMethod("ListResourceRecordSets", mock.Anything).Return(nil, fmt.Errorf("Mock route53 failure"))
_, err := pvd.Records(context.Background())
require.Error(t, err)
require.ErrorIs(t, err, provider.SoftError)
}

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

Expand Down