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(dedup): records with different type are not duplicates #4889

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 source/dedupsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (ms *dedupSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, err
}

for _, ep := range endpoints {
identifier := ep.DNSName + " / " + ep.SetIdentifier + " / " + ep.Targets.String()
identifier := ep.RecordType + " / " + ep.DNSName + " / " + ep.SetIdentifier + " / " + ep.Targets.String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other options could be

identifier := strings.Join([]string{ep.DNSName, ep.SetIdentifier, ep.Targets.String()}, " / ")
or
identifier := fmt.Sprintf("%s / %s / %s", ep.DNSName, ep.SetIdentifier, ep.Targets.String())

Do we know why there are empty spaces " / "? Just a question?


if _, ok := collected[identifier]; ok {
log.Debugf("Removing duplicate endpoint %s", ep)
Expand Down
21 changes: 21 additions & 0 deletions source/dedupsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ func testDedupEndpoints(t *testing.T) {
{DNSName: "foo.example.org", Targets: endpoint.Targets{"1.2.3.4"}},
},
},
{
"two endpoints with same dnsname, same type, and same target return one endpoint",
[]*endpoint.Endpoint{
{DNSName: "foo.example.org", RecordType: "A", Targets: endpoint.Targets{"1.2.3.4"}},
{DNSName: "foo.example.org", RecordType: "A", Targets: endpoint.Targets{"1.2.3.4"}},
},
[]*endpoint.Endpoint{
{DNSName: "foo.example.org", RecordType: "A", Targets: endpoint.Targets{"1.2.3.4"}},
},
},
{
"two endpoints with same dnsname, different record type, and same target return two endpoints",
[]*endpoint.Endpoint{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about case when one endpoint have no RecordType type and another one does?

{DNSName: "foo.example.org", RecordType: "A", Targets: endpoint.Targets{"1.2.3.4"}},
{DNSName: "foo.example.org", RecordType: "AAAA", Targets: endpoint.Targets{"1.2.3.4"}},
},
[]*endpoint.Endpoint{
{DNSName: "foo.example.org", RecordType: "A", Targets: endpoint.Targets{"1.2.3.4"}},
{DNSName: "foo.example.org", RecordType: "AAAA", Targets: endpoint.Targets{"1.2.3.4"}},
},
},
} {
t.Run(tc.title, func(t *testing.T) {
mockSource := new(testutils.MockSource)
Expand Down