Repository navigation
Conversation
✅ Deploy Preview for interlink-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
🟡 Changes recommended
The IP refresh can discard local reservations and allow duplicate address allocation, while slice-based deduplication adds quadratic work under the allocator mutex.
2 open issues
What changed in this PR
This first-stage refactor adds synchronized containers for the virtual-kubelet provider’s pod registry and VPN IP tracking. The locks protect the containers, not the shared pod objects.
Changes:
- Replaces direct map and slice access with locked operations and snapshot iteration.
- Preserves tracked IPs when the status loop cannot list cluster pods.
- Adds tests for registry operations, snapshots, and concurrent IP allocation.
| File | Description |
|---|---|
pkg/virtualkubelet/virtualkubelet.go |
Integrates the stores into provider operations and status refreshes. |
pkg/virtualkubelet/podstore.go |
Adds the mutex-protected pod registry and IP tracker. |
pkg/virtualkubelet/podstore_test.go |
Tests store behavior, snapshot isolation, and concurrent allocation. |
pkg/virtualkubelet/execute.go |
Uses the retrieved pod for terminal-state checks. |
Review effort: Balanced
Provider.podIPs was a plain slice written by CreatePod and by the status loop at the same time, and the status loop emptied it before refilling it, so an allocation could run against a half-built list. Move it behind podIPTracker, which keeps the addresses observed on cluster pods apart from the ones reserved locally. A refresh replaces the observed set and only releases reservations made before the pod list was taken, so an IP handed out while the list is in flight cannot be given out twice. Lookups are set-based, and allocation picks and reserves an address in one critical section. The status loop now keeps the previous IP set when listing pods fails. Signed-off-by: dciangot <dciangot@cern.ch>
b6859b8 to
4cbc765
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Critical races in podiptracker.go can prematurely delete unpublished reservations or accept stale snapshots, allowing the same IP to be allocated to multiple pods.
2 open issues
2 resolved since last review
Review effort: Balanced
| seq uint64 | ||
| observed map[string]struct{} | ||
| reserved map[string]uint64 // IP -> value of seq when it was reserved | ||
| } | ||
|
|
||
| // begin must be called right before listing the pods from the cluster. The returned | ||
| // snapshot is passed to refresh together with the list result. | ||
| func (t *podIPTracker) begin() uint64 { | ||
| t.mu.Lock() | ||
| defer t.mu.Unlock() | ||
|
|
||
| return t.seq | ||
| } | ||
|
|
||
| // refresh replaces the observed addresses and releases the reservations made up to | ||
| // snapshot. Reservations made after it are kept. | ||
| func (t *podIPTracker) refresh(snapshot uint64, observed []string) { | ||
| t.mu.Lock() | ||
| defer t.mu.Unlock() | ||
|
|
There was a problem hiding this comment.
@copilot Fix the code for this review comment.
When a review comment includes a suggested change, apply the suggestion exactly.
Do not make changes beyond what is described in the linked review comment.
| if seq <= snapshot { | ||
| delete(t.reserved, ip) |
There was a problem hiding this comment.
@copilot Fix the code for this review comment.
When a review comment includes a suggested change, apply the suggestion exactly.
Do not make changes beyond what is described in the linked review comment.
|
@copilot Fix the code for all comments in this review thread. When a review comment includes a suggested change, apply the suggestion exactly. Do not make changes beyond what is described in the linked review thread. |


Summary
Provider.podIPsis read and written byCreatePod(setupVPNPodIP) and bystatusLoopat the same time, with no lock. The status loop also emptied the slice before refilling it, so an allocation could run against a half-built list and hand out an address already in use.This moves it behind a
podIPTracker(new filepkg/virtualkubelet/podiptracker.go):allocate.CreatePodcalls cannot get the same address.begin()returns a snapshot that is passed torefresh). An IP reserved while the list is in flight is kept, so it cannot be given out twice.Provider{}literals used in tests keep working.When listing pods fails in the status loop, the previous IP set is kept instead of being cleared.
p.podsis not touched:mainalready protects it withpodsMu.This is step 1 of a larger maintainability refactor of
pkg/virtualkubelet, and has no other user-facing change.Tested:
go build ./...andgo vet ./pkg/virtualkubelet/.go test -race ./pkg/virtualkubelet/, with new tests inpodiptracker_test.go. They include a regression test for an allocation made between taking the list snapshot and applying the refresh, and for concurrent allocations.Size: 226 changed lines in 3 files.
Rebased on
mainat 5f60ce8. It addresses the two Copilot findings from the first revision.Related issue :