15 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 9e8acde836 fix: error handling for auth errors, no adopt for setkey, accesskey 2025-07-22 09:25:36 +01:00
David Fry c491843b8d fix: upgrade to latest nb and add adoption policy 2025-07-09 14:35:57 +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 c4b97bf647 fix update on nbnetresource 2025-05-12 12:17:08 +01:00
David Fry d0267a1666 fix: nbnetworkresource 2025-04-30 12:50:58 +01:00
David Fry 9ce340aba2 add policy object 2025-03-27 22:01:01 +00:00
David FryandGitHub c0a66bd305 Merge branch 'main' into dev 2025-03-26 16:17:33 +00:00
David Fry 237b9746e0 add network router and resource 2025-03-26 16:11:10 +00:00
Radek Forgac 0f6e27e09b feat: rename provider from "provider-netbird" to "netbird-crossplane-provider" 2025-03-26 16:06:46 +01:00
David Fry 8eafaa350b first draft network/route/resources 2025-03-25 22:45:33 +00:00
David Fry e10037f333 updates for users/accesstokens 2025-03-25 15:27:29 +00:00