Skip to content

fix: create the record an UPDATE does not find, instead of failing forever - #84

Open
samudm98 wants to merge 1 commit into
AbsaOSS:mainfrom
mercadona:upstream-fix-upsert
Open

samudm98 wants to merge 1 commit into
AbsaOSS:mainfrom
mercadona:upstream-fix-upsert

Conversation

@samudm98

Copy link
Copy Markdown

Fixes #83.

An UPDATE for a record that is not in the zone fails with could not build record: not found, and keeps failing on every reconcile. ExternalDNS does not promise that an UpdateNew endpoint already exists: its TXT registry can emit an UpdateNew for an ownership record that is absent from the zone, so the condition is normal input, not an error. The issue has the full analysis.

Changes

recordSet() no longer leaks a tolerated not-found. The five lookup branches already tolerate NotFoundError; they just never cleared err, which is a named return, so it escaped through buildRecord anyway.

submitChanges upserts. With the above fixed, getRefID answers "" and no error for an absent record, so UPDATE now creates instead of calling UpdateObject with an empty ref. The record is rebuilt in its create shape, because that path sets the View — Infoblox needs it to find the parent zone and rejects it on an update.

DELETE of an absent record is a no-op, rather than DeleteObject(""). Its desired state is already met. This is needed to avoid a regression: before, such a delete failed earlier, at buildRecord.

recordSet works on a copy of the endpoint. Its TXT branch normalises Targets in place with strconv.Unquote, to match the API stripping the enclosing quotes of a value without whitespace. That was harmless while it ran once per change; the upsert calls it a second time, and without the copy a TXT whose value is itself a quoted string loses a layer — "\"token\"" would be stored as token where a plain create stores "token".

Tests

Two, both failing before the change and passing after:

  • TestInfobloxApplyChangesUpsertsMissingRecord — a zone holding the A record but not its TXT, with a matched UpdateOld/UpdateNew pair so CountDiff keeps the action an UPDATE. Asserts the TXT is created and the A is still updated.
  • TestInfobloxApplyChangesUpsertKeepsQuotedTXTIntact — asserts parity rather than a literal: an upsert must store exactly what a create of the same endpoint stores.

mockIBConnector gains one opt-in field, txtNotFound, so a TXT lookup matching nothing answers with the NotFoundError the real client returns instead of an empty result. It is off by default and no existing test changes.

…rever

ExternalDNS does not promise that an UpdateNew endpoint is already in the zone: its TXT
registry can emit an UpdateNew for an ownership record that is absent. This provider
fails such a change, and keeps failing it on every reconcile:

    could not build record (&{UPDATE <prefix>a-foo.example.com 0 IN TXT ...}): not found

recordSet() already tolerates a NotFoundError from the lookup -- that is what
isNotFoundError is for, and why the branch does not abort on it -- but err is a named
return and is never cleared, so the tolerated not-found leaves the function anyway and
buildRecord turns it into the error above.

With that fixed, getRefID answers "" and no error for a record that is absent, and
submitChanges would call UpdateObject with an empty ref. So UPDATE now creates when there
is nothing to update, rebuilding the record in its create shape because that path sets the
View that Infoblox needs to find the parent zone and rejects on an update. DELETE of an
absent record becomes a no-op for the same reason: its desired state is already met.

recordSet also works on a copy of the endpoint now. Its TXT branch normalises Targets in
place with strconv.Unquote, which was harmless while it ran once per change; the upsert
calls it a second time, and without the copy a TXT whose value is itself a quoted string
would lose a layer.

Both tests fail before the change and pass after it.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0114JL1WD4H4QL29Svh8mg3Z
@k0da

k0da commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@samudm98
Hi, thank you for your PR. Please rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An UPDATE for a record that is not in the zone fails permanently

2 participants