Skip to content

Add InterlinkClient request plumbing and Ping - #617

Draft
dciangot wants to merge 2 commits into
interlink-hq:mainfrom
dciangot:refactor/interlink-client-2-roundtrip-ping
Draft

dciangot wants to merge 2 commits into
interlink-hq:mainfrom
dciangot:refactor/interlink-client-2-roundtrip-ping

Conversation

@dciangot

Copy link
Copy Markdown
Member

Summary

Second PR of the InterlinkClient stack (see #616). It is based on #616, so until that one is merged this diff also shows its commit: review only the second commit, "Add InterlinkClient request plumbing and Ping" (392 changed lines in 2 files). It stays a draft until then.

It adds the code every call to the interLink API goes through (pkg/virtualkubelet/interlink_client.go):

  • roundTrip builds the request, reads the token, sets the headers and the session context, and wraps the HTTP call in a tracing span.
  • doJSON reads the whole response body and maps any status other than 200 to a typed *InterlinkStatusError, so callers can check the code with errors.As.
  • Ping, the first operation built on top of those two.

Compared with the existing helpers:

  • errors never embed the request, which carries the bearer token;
  • the token file is trimmed and read on every call, so a rotated token is picked up;
  • a missing token file is an error returned to the caller, not a log.Fatal;
  • a non-200 ping reports the real status code.

Nothing uses the client yet, so there is no change in behavior.

Tested:

  • go build ./... and go vet ./pkg/virtualkubelet/.
  • go test -race ./pkg/virtualkubelet/, with new tests for the request shape (method, path, headers, body), the absence of an Authorization header without a token file, the typed status error, Ping (ok, non-200, unreachable API), token handling (missing file, rotation, no token in errors) and context cancellation.
  • golangci-lint v2.14.0 with the repo config: 0 issues.
  • Dagger/E2E tests were not run locally.

Related issue :

First step towards replacing the copy-pasted HTTP request helpers
with a single client for the VK to interLink API. This only adds the
endpoint resolution and the constructor, together with their tests;
nothing uses the client yet.

The constructor validates the URL scheme up front and captures the HTTP
client at construction time. Loopback hosts are allowed, since the
interLink API commonly runs next to the VK.

Signed-off-by: dciangot <dciangot@cern.ch>
Add the shared code every call to the interLink API will go through:
roundTrip builds the request, reads the token and starts the tracing
span, doJSON reads the body and maps non-200 answers to a typed
InterlinkStatusError. Ping is the first operation built on top.

Unlike the existing helpers, errors never embed the request, which
carries the bearer token, and the token file is trimmed and read on
every call so that a rotated token is picked up.

Nothing uses the client yet.

Signed-off-by: dciangot <dciangot@cern.ch>
@netlify

netlify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for interlink-dev canceled.

Name Link
🔨 Latest commit 6185059
🔍 Latest deploy log https://app.netlify.com/projects/interlink-dev/deploys/6b0176169431784fbf53f4ee

This branch has not been deployed

No deployments
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