105 Commits
Author SHA1 Message Date
David FryandGitHub c02c6fcc3f Merge pull request #3 from callum-stakater/pr/nbnetwork-dup-create-fix
fix(nbnetwork,nbnetworkresource,nbnetworkrouter): nil-safe group resolution + Observe error handling + external-name recovery
2026-05-22 20:48:29 +01:00
Callum MacDonald 35696201ee docs: add godoc comments to new and pre-existing symbols in changed files 2026-05-22 20:45:38 +02:00
Callum MacDonaldandClaude Opus 4.7 396459fb13 fix(nbnetwork,nbnetworkresource,nbnetworkrouter): Observe error handling and external-name recovery
Extends the pattern from #19 (nbsetupkey) to the three Network-family
controllers. Before this change, a transient failure on the by-ID Get
in Observe was silently swallowed (ResourceExists: false, nil error),
which then drove Crossplane into Create — producing duplicate netbird
resources whenever the upstream API hiccupped. We also defaulted the
external-name annotation to the Kubernetes object name on first
reconcile, so subsequent reconciles would 404 against the API and
trigger Create again.

For each of NbNetwork, NbNetworkResource, NbNetworkRouter:

- Disable the NameAsExternalName default via managed.WithInitializers()
  on the reconciler so external-name stays empty until we set it to
  the real provider ID.
- Add resolve<Type>LookupID(cr) that prefers external-name when it
  looks like a real provider ID, and falls back to
  status.atProvider.id when external-name is empty or was defaulted
  to the k8s object name by an older reconcile.
- Add is<Type>NotFoundError(err) that matches the
  "<type>: <id> not found" message returned by the netbird REST API.
- In Observe: gate the by-ID branch on the resolved lookup ID.
  - If the lookup ID is empty, fall through to the existing
    by-name adoption path (unchanged — these controllers have richer
    adoption than nbsetupkey did).
  - When the by-ID Get fails: treat real not-found as
    ResourceExists: false (delegate to Create); wrap and return
    every other error so Crossplane requeues without calling Create.
  - After a successful by-ID Get, repair a stale external-name
    annotation against the real ID.
- Update/Delete use the same resolver and error out on empty rather
  than passing an empty string to the API.
- Extract authClient interface on the external struct so tests can
  inject a netbird client backed by httptest.

Adds table-driven tests covering: empty external-name + empty status
ID, by-ID 404, transient by-ID error, and stale-external-name repair
via status fallback. The existing TestResolveGroupIDs cases on
nbnetworkresource (from PR #20) are preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 19:25:20 +02:00
Callum MacDonald afcc530509 fix(nbnetworkresource): nil-safe group resolution + prefer spec id
`Create` / `Update` previously did:

    for j, provgroup := range *cr.Spec.ForProvider.Groups {
        for _, apigroup := range groups {
            if apigroup.Name == *provgroup.Name { ... }
        }
    }

`provgroup.Name` is `*string` and the schema marks it optional. When a
user references a group by Id alone — the canonical pattern, since Id
is stable and Name is a free-text label — the unconditional `*Name`
deref panics the entire provider with nil pointer at this line.

Even when Name is supplied, the loop ignored the spec's Id entirely
and forced an account-wide group-name lookup, silently leaving the
slot empty (and the resource created with an empty group ref) if no
match was found.

Extract `resolveGroupIDs(spec, apiGroups)`:

  - Prefer Id when present and non-empty.
  - Fall back to Name lookup, guarded.
  - Return an explicit error if neither is usable, or if the named
    group does not exist on the account.

Both Create and Update now share the helper. Adds table-driven unit
test covering id-wins-over-name, name-fallback, nil-everything,
unknown-name, and empty-spec.

Repro: apply an `NbNetworkResource` whose `spec.forProvider.groups`
entries are `{id: <existing-group-id>}` (Name omitted). With v0.4.2
the provider crashes on the first reconcile; with this fix the
resource creates successfully.
2026-05-22 19:25:18 +02:00
David Fry 0ccfd1ba93 rm old references v0.4.2 2026-01-13 13:12:31 +00:00
David FryandGitHub eddf414741 Merge pull request #17 from infitx-org/fix/port-range-check
fix: correct compare for port ranges on policy
v0.4.0 v0.4.1
2025-11-26 11:51:06 +00:00
David Fry 65b5255f3c fix: correct compare for port ranges on policy 2025-11-24 12:57:25 +00:00
David FryandGitHub c1c13cb61f Merge pull request #15 from infitx-org/dev
fix: error handling for auth errors, no adopt for setkey, accesskey
2025-11-05 20:00:51 +00:00
David Fry a38a181aa9 fix: compare only ids instead of names on dest and src 2025-11-05 09:26:43 +00:00
David Fry 04f94a88b2 fix roles 2025-07-29 15:03:54 +01:00
David Fry 9e8acde836 fix: error handling for auth errors, no adopt for setkey, accesskey 2025-07-22 09:25:36 +01:00
David FryandGitHub fbe01e94ed Merge pull request #14 from infitx-org/dev
update to nb provider and use of adoption pattern to address duplicate resource creation
2025-07-17 13:14:12 +01:00
David Fry 446013e843 fix: fix ports on policy 2025-07-09 18:55:46 +01:00
David Fry c491843b8d fix: upgrade to latest nb and add adoption policy 2025-07-09 14:35:57 +01:00
David Fry 0971f8932f fix: update user object to remove permissions 2025-06-06 09:49:51 +01:00
David FryandGitHub 9c68bdcd9a Merge pull request #13 from infitx-org/dev
feature: add auth caching
2025-06-05 13:28:33 +01:00
David Fry f5d40229ef feature: add auth caching 2025-06-05 09:35:41 +01:00
David FryandGitHub 2dc15e98f4 Merge pull request #11 from infitx-org/dev
Dev
2025-05-27 16:17:00 +01:00
David Fry ff2a0513af fix: updated logging and cleanup of update methods 2025-05-27 15:45:18 +01:00
David FryandGitHub aaa590c8fc Merge pull request #12 from infitx-org/dev-2
Dev 2
2025-05-26 23:40:33 +01:00
David Fry 0ec002225b fix go tidy 2025-05-26 22:48:54 +01:00
David Fry b658899d68 update config files 2025-05-26 19:32:14 +01:00
Radek Forgac a316a6d7b4 feat: go mod tidy 2025-05-26 21:06:36 +03:00
David Fry 9a255ee85a revert ci changes 2025-05-26 18:03:51 +01:00
David Fry 528c109bb3 try remove caching 2025-05-26 17:05:31 +01:00