58 Commits
Author SHA1 Message Date
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 65b5255f3c fix: correct compare for port ranges on policy 2025-11-24 12:57:25 +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 9e8acde836 fix: error handling for auth errors, no adopt for setkey, accesskey 2025-07-22 09:25:36 +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 Fry f5d40229ef feature: add auth caching 2025-06-05 09:35:41 +01:00
David Fry ff2a0513af fix: updated logging and cleanup of update methods 2025-05-27 15:45:18 +01:00
David Fry 528c109bb3 try remove caching 2025-05-26 17:05:31 +01:00
David Fry 90ce664308 revert changes 2025-05-26 16:45:24 +01:00
David Fry 02d219f922 fix: make autogroups optional on status 2025-05-26 16:23:33 +01:00
David Fry 36046f78bf fix: update at provider 2025-05-26 15:09:47 +01:00
David Fry 7356f363db fix: add logging 2025-05-26 14:41:17 +01:00
David Fry 6d5443255e fix: delete on nserver 2025-05-26 13:17:59 +01:00
David Fry d081c5dbbb fix: add check on empty non-service user email 2025-05-22 08:34:26 +01:00
David Fry 8bce5f4900 fix: user update 2025-05-21 16:45:04 +01:00
David Fry 723b311a25 fix: filter userlist for only regular users 2025-05-21 13:01:04 +01:00
David Fry be2c0db0a5 fix: fix expiration logic 2025-05-21 00:23:36 +01:00
David Fry c4b97bf647 fix update on nbnetresource 2025-05-12 12:17:08 +01:00
David Fry 29dca77774 fixes to observe is up to date method 2025-05-06 10:46:30 +01:00
David Fry b6127d5b8b fix: isuptodate on nbaccount 2025-05-03 14:42:29 +01:00
David Fry 9c4731ffce update isuptodate method for account 2025-05-03 00:56:00 +01:00