Skip to content

Commit

Permalink
Merge pull request #1370 from nabuskey/bugfix/route53-wildcard
Browse files Browse the repository at this point in the history
fix route53 wildcard handling
  • Loading branch information
haarchri committed Jun 24, 2022
2 parents 90bf411 + 56fe141 commit 715b032
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/clients/resourcerecordset/resourcerecordset.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (

const (
errResourceRecordSetNotFound = "ResourceRecordSet.NotFound"
wildCardCharacters = "\\052"
)

// Client defines ResourceRecordSet operations
Expand Down Expand Up @@ -84,8 +85,14 @@ func GetResourceRecordSet(ctx context.Context, name string, params v1alpha1.Reso
}
return s
}
replaceWithWildCard := func(s string) string {
if strings.HasPrefix(s, wildCardCharacters) {
return strings.Replace(s, wildCardCharacters, "*", 1)
}
return s
}
for _, rr := range res.ResourceRecordSets {
if appendDot(aws.ToString(rr.Name)) == appendDot(name) &&
if replaceWithWildCard(appendDot(aws.ToString(rr.Name))) == appendDot(name) &&
string(rr.Type) == params.Type &&
aws.ToString(rr.SetIdentifier) == aws.ToString(params.SetIdentifier) {
return &rr, nil
Expand Down
80 changes: 80 additions & 0 deletions pkg/controller/route53/resourcerecordset/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package resourcerecordset

import (
"context"
"fmt"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -112,6 +113,13 @@ func TestObserve(t *testing.T) {
err error
}

addWildcardPrefix := func(rr *v1alpha1.ResourceRecordSet) {
meta.SetExternalName(rr, fmt.Sprintf("*.%s", rr.Name))
}
addTwoWildcardPrefix := func(rr *v1alpha1.ResourceRecordSet) {
meta.SetExternalName(rr, fmt.Sprintf("*.test*.%s", rr.Name))
}

cases := map[string]struct {
args
want
Expand Down Expand Up @@ -174,6 +182,78 @@ func TestObserve(t *testing.T) {
},
},
},
"WildcardRecord": {
args: args{
kube: &test.MockClient{
MockStatusUpdate: test.NewMockStatusUpdateFn(nil),
},
route53: &fake.MockResourceRecordSetClient{
MockListResourceRecordSets: func(ctx context.Context, input *route53.ListResourceRecordSetsInput, opts []func(*route53.Options)) (*route53.ListResourceRecordSetsOutput, error) {
return &route53.ListResourceRecordSetsOutput{
ResourceRecordSets: []route53types.ResourceRecordSet{
{
Name: aws.String(fmt.Sprintf("*.%s", name)),
Type: "A",
TTL: TTL,
ResourceRecords: []route53types.ResourceRecord{
{
Value: aws.String("0.0.0.0"),
},
},
},
},
}, nil
},
},
cr: instance(addWildcardPrefix),
},
want: want{
cr: instance(
withConditions(xpv1.Available()),
addWildcardPrefix,
),
result: managed.ExternalObservation{
ResourceExists: true,
ResourceUpToDate: true,
},
},
},
"RecordWithTwoWildCards": {
args: args{
kube: &test.MockClient{
MockStatusUpdate: test.NewMockStatusUpdateFn(nil),
},
route53: &fake.MockResourceRecordSetClient{
MockListResourceRecordSets: func(ctx context.Context, input *route53.ListResourceRecordSetsInput, opts []func(*route53.Options)) (*route53.ListResourceRecordSetsOutput, error) {
return &route53.ListResourceRecordSetsOutput{
ResourceRecordSets: []route53types.ResourceRecordSet{
{
Name: aws.String(fmt.Sprintf("*.test*.%s", name)),
Type: "A",
TTL: TTL,
ResourceRecords: []route53types.ResourceRecord{
{
Value: aws.String("0.0.0.0"),
},
},
},
},
}, nil
},
},
cr: instance(addTwoWildcardPrefix),
},
want: want{
cr: instance(
withConditions(xpv1.Available()),
addTwoWildcardPrefix,
),
result: managed.ExternalObservation{
ResourceExists: true,
ResourceUpToDate: true,
},
},
},
}

for name, tc := range cases {
Expand Down

0 comments on commit 715b032

Please sign in to comment.