Skip to content

Fix peer reconcilication - #11

Merged
nocturo merged 2 commits into
mainfrom
fix/peerracecondition
Apr 16, 2026
Merged

Fix peer reconcilication#11
nocturo merged 2 commits into
mainfrom
fix/peerracecondition

Conversation

@nocturo

@nocturo nocturo commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

This addresses a race condition between WireguardPeerReconciler and WireguardReconciler that leaves peers stuck without keys.

WireguardReconciler and WireguardPeerReconciler are both trying to update WireguardPeer .spec concurrently leading to a race condition where an address is assigned, ResourceVersion updated but no wireguardpeer can be further configured as Update() is using a different version. We use patch instead so only the changed fields get updated.

Added a test which confirms the bug.

@nocturo
nocturo merged commit bfb1efe into main Apr 16, 2026
3 checks passed
@nocturo
nocturo deleted the fix/peerracecondition branch April 16, 2026 11:26
mxhob1 referenced this pull request in node-networks-au/wireguard-operator May 27, 2026
…lreadyExists

When the <peer>-peer Secret exists before the WireguardPeer CR is
reconciled (ops pre-clones keys for tenant migrations or 1Password-backed
key sharing across tenants), the reconciler erred with
`secrets "<peer>-peer" already exists` and bailed out — it never
populated spec.publicKey or spec.privateKeyRef on the CR, so wg0 never
got the [Peer] block for that peer and incoming handshakes landed on an
empty config.

Replace the unconditional Create with a Get-first pattern:
- Found: parse data.privateKey, derive pubkey via wgtypes.ParseKey
- NotFound: generate fresh keypair + Create the Secret (existing path)
- Other error: surface it
Then in both branches, populate spec.publicKey + spec.privateKeyRef on
the CR via Patch (NOT Update) so we don't clobber KRO's labels /
ownerRefs / other field-manager owned fields.

Upstream PR #11 (already in v2.11.0) covered this for the Wireguard CR's
keypair Secret but not the per-peer Secret. This closes that gap.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

3 participants