Skip to content

Add InterlinkClient constructor - #616

Open
dciangot wants to merge 1 commit into
interlink-hq:mainfrom
dciangot:refactor/interlink-client-1-constructor
Open

dciangot wants to merge 1 commit into
interlink-hq:mainfrom
dciangot:refactor/interlink-client-1-constructor

Conversation

@dciangot

Copy link
Copy Markdown
Member

Summary

Part of a refactor that replaces the six copy-pasted HTTP request functions in pkg/virtualkubelet/execute.go with one InterlinkClient. The work ships as a stack of small PRs, in this order: introduce the client, migrate the callers one group at a time, then remove the old helpers. This is the first one.

This PR adds NewInterlinkClient and the endpoint resolution (pkg/virtualkubelet/interlink_client.go). It builds the TLS HTTP client once at construction time, and a separate client for log retrieval with keep-alives disabled because the log body is streamed.

Nothing uses the client yet, so there is no change in behavior. The new code differs from the existing getSidecarEndpoint in three ways, which matter once callers move over in later PRs:

  • an unsupported URL scheme returns an error instead of calling log.Fatal;
  • an empty port no longer produces a trailing colon (http://host:);
  • loopback hosts such as http://localhost:3000 are accepted, since the interLink API commonly runs next to the VK.

Tested:

  • go build ./... and go vet ./pkg/virtualkubelet/.
  • go test -race ./pkg/virtualkubelet/, with new tests in interlink_client_test.go for the endpoint resolution (http, https, no port, unix socket, bad scheme, empty URL), localhost, TLS configuration errors, and the dedicated log transport (not shared with the input).
  • golangci-lint v2.14.0 with the repo config: 0 issues.
  • Dagger/E2E tests were not run locally.

Size: 170 changed lines in 2 files.

Next in the stack: request plumbing and Ping.


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>
Copilot AI balanced review requested due to automatic review settings November 21, 2026 10:44
@netlify

netlify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for interlink-dev canceled.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

With TLS enabled, a supplied log transport does not inherit the configured CA or client certificates, causing log requests to fail against private-CA or mTLS endpoints even when the regular client works.

1 open issue
What changed in this PR

Introduces InterlinkClient as the foundation for replacing duplicated HTTP request helpers in the Virtual Kubelet. No callers are migrated yet, so existing behavior remains unchanged.

Changes:

  • Adds a constructor that initializes HTTP clients and retains configuration for future requests.
  • Adds endpoint resolution for HTTP, HTTPS, and Unix sockets, accepting localhost and handling empty ports.
  • Adds tests for endpoint resolution, constructor configuration, TLS errors, and log transport isolation.
File Description
pkg/​virtualkubelet/​interlink_client.go Adds the client constructor and endpoint resolution.
pkg/​virtualkubelet/​interlink_client_test.go Tests constructor behavior, endpoints, and transport isolation.

Review effort: Balanced


logHTTPClient := httpClient
if logTransport != nil {
transport := logTransport.Clone()

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.

2 participants