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 route53 wildcard handling #1370

Merged
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
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