Repository navigation
Conversation
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>
✅ Deploy Preview for interlink-dev canceled.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Second PR of the
InterlinkClientstack (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):roundTripbuilds the request, reads the token, sets the headers and the session context, and wraps the HTTP call in a tracing span.doJSONreads the whole response body and maps any status other than 200 to a typed*InterlinkStatusError, so callers can check the code witherrors.As.Ping, the first operation built on top of those two.Compared with the existing helpers:
log.Fatal;Nothing uses the client yet, so there is no change in behavior.
Tested:
go build ./...andgo vet ./pkg/virtualkubelet/.go test -race ./pkg/virtualkubelet/, with new tests for the request shape (method, path, headers, body), the absence of anAuthorizationheader 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.Related issue :