Skip to content

fix: three correctness bugs in context parsing, the memory cache and the Scaleway search - #295

Open
ZeikoFr wants to merge 3 commits into
MichaelSp:mainfrom
ZeikoFr:fix/search-correctness
Open

fix: three correctness bugs in context parsing, the memory cache and the Scaleway search#295
ZeikoFr wants to merge 3 commits into
MichaelSp:mainfrom
ZeikoFr:fix/search-correctness

Conversation

@ZeikoFr

@ZeikoFr ZeikoFr commented Aug 30, 2026

Copy link
Copy Markdown

Three independent bugs found while profiling the live search. Each commit is
self-contained and comes with a test that fails against the current behaviour.

GetContextNames panics on a context entry without a name

valueOf(contextNode, "name") returns nil when the entry is not a mapping or
has no name key, and the result was dereferenced unconditionally. One such
entry in a kubeconfig crashes the whole search with a nil pointer dereference
instead of being skipped.

The in-memory kubeconfig cache is unsynchronised

memoryCache.GetKubeconfigForPath reads and writes its map without a lock.
Nothing calls it concurrently today, so this is latent, but any caller that
retrieves several kubeconfigs at once turns it into
fatal error: concurrent map writes. The added test fails under -race.

The upstream call is deliberately made without holding the lock: it is a remote
call taking seconds and would otherwise serialise every caller.

The Scaleway search loses clusters

  • ListProjects and ListClusters were called without scw.WithAllPages(), so
    the SDK requested a single page. Every project past the server-side default
    page size, and every cluster past it within a project, was silently missing
    from the results.
  • A project whose cluster listing fails, typically one the credentials cannot
    read, aborted StartSearch entirely. Every project after it was never
    reported. The error is now surfaced and the search continues.
  • The "failed to create Kubernetes API instance" error wrapped an err that is
    necessarily nil in that branch, so the message ended in %!w(<nil>).

Verification

gofmt, go build, go vet, golangci-lint run (0 issues) and
go test -race -count=1 ./... are clean, and every commit passes them
individually.

🤖 Generated with Claude Code

ZeikoFr and others added 3 commits August 30, 2026 15:22
…king

GetContextNames dereferenced the result of valueOf(contextNode, "name")
unconditionally. valueOf returns nil when the entry is not a mapping or has no
"name" key, so a hand-edited or provider-generated kubeconfig whose contexts
list holds such an entry crashed the whole search with a nil pointer
dereference rather than skipping the entry.

The added test panics without the guard.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
memoryCache.GetKubeconfigForPath read and wrote its map without
synchronisation. Nothing calls it concurrently today, so the race is latent,
but any store or caller that retrieves several kubeconfigs at once turns it
into a "fatal error: concurrent map writes" crash.

The upstream call is deliberately made without holding the lock: it is a
remote call taking seconds and would otherwise serialise every caller.

The added test fails under -race without the mutex.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…hers

Three problems in the Scaleway search:

  - ListProjects and ListClusters were called without scw.WithAllPages, so the
    SDK requested a single page. Every project past the server-side default
    page size, and every cluster past it within a project, was silently
    missing from the search results.
  - A project whose cluster listing fails, typically one the credentials
    cannot read, aborted StartSearch. The clusters of every project after it
    were never reported. The error is now reported and the search carries on.
  - The "failed to create Kubernetes API instance" error wrapped err, which is
    necessarily nil in that branch, so the message ended in "%!w(<nil>)".

Adds a fake Scaleway API serving paginated project and cluster listings; both
new tests fail against the previous behaviour.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ZeikoFr
ZeikoFr force-pushed the fix/search-correctness branch from e0545a7 to f73db95 Compare August 30, 2026 13:25
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.

1 participant