-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Only update PiHole entries when they have actually changed #3297
Conversation
Welcome @sfleener! |
provider/pihole/pihole.go
Outdated
// Handle updated state - there are no endpoints for updating in place. | ||
updateNew := make(map[string]*endpoint.Endpoint) | ||
for _, ep := range changes.UpdateNew { | ||
updateNew[ep.DNSName] = ep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if changes.UpdateNew
has multiple endpoints with the same DNSName
? Shouldn't you put the RecordType
in the map key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! PiHole doesn't allow two records of the same RecordType with the same DNS name, but it does allow two records with the same DNS name if the record types are different. Fixed
provider/pihole/pihole_test.go
Outdated
createRequests int | ||
deleteRequests int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better unit tests would explicitly specify the expected requests, verifying the dnsname, recordtype, and target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the tests to compare the actual and expected requests instead of just the counts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new version of the tests is asserting that the three new records are created in order, which isn't actually a requirement.
I would have written this to put the expected calls in the tracker. The client would then find the request in the tracker and remove it, asserting that the request was found in the tracker. At the end, the test would assert that there were no remaining expected calls in the tracker.
/lgtm |
@sfleener can you fix the linter issues? I'm happy to approve after those are fixed |
@Raffo The lints appear to be |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Raffo, sfleener The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm |
Description
While testing the PiHole provider, I noticed some behavior that caused issues with internal hostnames being resolved.
Even when the DNS entries have not changed, the provider first deletes all entries it manages before re-adding them one by one with the same endpoint they originally had. With a moderate amount of entries managed by external-dns (~10-15 or so in my testing), this process takes about 10 seconds total. Using the default update interval of 60 seconds, this leaves a 5-10 second window every minute where these hostnames don't exist on PiHole and fail to resolve.
This PR adds a simple dedupe check that makes sure the entries have actually changed before deleting and re-adding them. This removes any time period where unchanged hostnames do not resolve, and only leaves an unresolvable window in cases where the target has actually changed (which is probably what you'd want anyway).
Considered Alternatives
Checklist