Repository navigation
fix(rfc2136): surface record build errors and skip partial updates in ApplyChanges - #6868
Conversation
|
Hi @mmontes11. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
Coverage Report for CI Build 41238936273Coverage increased (+0.04%) to 83.053%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions55 previously-covered lines in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
There was a problem hiding this comment.
Thanks, the refactor behaves the same as before.
The three apply*Batches helpers are still mostly copy-paste. Only the per-endpoint call differs.
Wdyt of collapsing them into one helper, e.g.:
func (r *rfc2136Provider) applyBatches(action string, eps []*endpoint.Endpoint, apply func(m *dns.Msg, idx int, ep *endpoint.Endpoint) error) []errorThe update closure would then use updateOld[idx]. Otherwise any future change has to be made three times.
@mloiseleur Fair point, still a lot of boilerplate, agreed. Will work on the changes |
2045f6b to
62a2126
Compare
mmontes11
left a comment
There was a problem hiding this comment.
Review comments addressed:
- Replaced the three
apply*Batcheshelpers with a singleapplyBatches(action, eps, apply)used from all three call sites. - Extended
TestRfc2136ApplyChangesAllFilteredSendsNothingwith filteredUpdateOld/UpdateNewpairs and asendCounton the stub, asserting no packets are sent at all.
One small behavior change to note: the previous loop ignored per-endpoint apply errors; this version collects them into the returned error. Please let me know if this acceptable or you rather keep the previous behaviour.
Verified locally: go test -race ./provider/rfc2136/... passes, golangci-lint clean, ApplyChanges cc=2.
|
Also, it seems like this CI step is not happy, but seems unrelated to the changes: |
|
/retest |
There was a problem hiding this comment.
Yes, collecting the errors is better than ignoring them.
#6896 will drop most invalid targets before they reach the provider, but TXT still slips through: "unbalanced passes CheckEndpoint and fails dns.NewRR. On an update that sends the delete without the add.
Could you build each endpoint into a scratch msg and merge it into m[zone] only on success, wrapping the error with ep.DNSName? A test with an invalid TXT target on UpdateNew would cover it. Fine as a follow-up.
Nits: drop // Add the root zone, shorten the idx comment, and update the PR body (it still names the three apply*Batches helpers) to mention the error behavior change.
|
Thanks @mloiseleur for the review — all three comments are addressed (
One extra change since your review: update batches now build into a scratch message and merge only on success, so a failed endpoint does not leave a partial update in the batch (
|
|
Thanks, cf620f2 looks right: the scratch msg keeps a failed update from sending its delete. |
|
@mloiseleur Very much appreciated for the in-depth review, I've updated the PR body to reflect all the changes. |
| for c, chunk := range chunkBy(changes.Create, r.batchChangeSize) { | ||
| log.Debugf("Processing batch %d of create changes", c) | ||
| if len(errs) > 0 { | ||
| return provider.NewSoftErrorf("RFC2136 had errors in one or more of its batches: %v", errs) |
There was a problem hiding this comment.
Wrong wrapping. flattens %w wrappers, so errors.Is can't recover inner causes
| } | ||
|
|
||
| zone := findMsgZone(ep, r.zoneNames) | ||
| m[zone].SetUpdate(zone) |
There was a problem hiding this comment.
could be called once per batch, no need to call it per endpoint.
|
|
||
| r.AddRecord(m[zone], ep) | ||
| } | ||
| func (r *rfc2136Provider) acceptsEndpoint(ep *endpoint.Endpoint) bool { |
There was a problem hiding this comment.
The helper is called in exactly one place, and is quite simple logic
for i, ep := range chunk {
if !r.domainFilter.Match(ep.DNSName) {
log.Debugf("Skipping record %s because it was filtered out by the specified --domain-filter", ep.DNSName)
continue
}
...
}
Signed-off-by: Martin Montes <martin11lrx@gmail.com>
Address review comments: - collapse applyCreateBatches/applyUpdateBatches/applyDeleteBatches into one applyBatches(action, eps, apply) helper, with the update closure indexing changes.UpdateOld[idx] - test stub now counts SendMessage calls and the all-filtered test asserts a zero count and covers the update path (UpdateOld/UpdateNew) - drop doc comments that restate the helper names Signed-off-by: Martin Montes <martin11lrx@gmail.com>
Address review comments: - build each endpoint into a scratch message and merge it into the batch only on success, so a failed endpoint (e.g. an invalid TXT target) no longer leaves a partial update behind; wrap the error with the endpoint's DNS name - drop the root-zone comment and shorten the idx comment - new test with an invalid TXT target on UpdateNew asserts the error is a SoftError naming the endpoint and that nothing is sent Signed-off-by: Martin Montes <martin11lrx@gmail.com>
…h setup Address review comments: - join the batch errors with errors.Join and wrap them with %w so the soft error keeps the inner causes recoverable via errors.Is - call SetUpdate once per zone per batch instead of once per endpoint - inline the one-use acceptsEndpoint helper back into the batch loop Signed-off-by: Martin Montes <martin11lrx@gmail.com>
cf620f2 to
2c9d408
Compare
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ivankatliarchuk The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What does it do ?
Splits the RFC2136
ApplyChangesbatch handling into a singleapplyBatchesloop driven by a per-action closure (create/update/delete), and pulls the
shared pieces into
newBatchMsgs(per-zone message map),acceptsEndpoint(domain filter) and
sendBatchMsgs(send non-empty messages, collecterrors).
ApplyChangeskeeps the log line, the three batch calls and thefinal
SoftErroraggregation; the update path'sUpdateOldindex mapping(
c * batchChangeSize + i) is preserved.Beyond the refactor, two behavior changes:
AddRecord,UpdateRecordandRemoveRecorderrors are collected asRFC2136 <action> <dns name>: <err>and surfaced in the
SoftErrorreturned byApplyChanges.into a scratch message and merged into the batch only on success, so a
failed update (e.g. an invalid target) never sends its delete without its
add.
Cyclomatic complexity of
ApplyChangesdrops from 23 to 2 (helpers are allcc <= 4).
Motivation
Each batch loop duplicated the message-map construction, endpoint filtering,
zone lookup and send loop, so a behavior change had to be replicated three
times and the function was the most complex one in the provider. With the
loops collapsed into one, the silently dropped error handling (record build
errors, partial batch updates) could be fixed in a single place.
More
New tests:
TestRfc2136ApplyChangesAllFilteredSendsNothingpins thelen(z.Ns) > 0guard — a changeset whose endpoints are all filtered out sends no DNS
messages at all (the stub counts
SendMessagecalls, withUpdateOld/UpdateNewentries covering the update path).TestRfc2136ApplyChangesInvalidTargetSendsNothingpins that an invalidtarget produces a
SoftErrornaming the endpoint, and that no partialupdate reaches the nameserver.
Note: this change was drafted with AI assistance and reviewed locally before submission.