fix(client): let a caller context reach the report upload - #60
Merged
matthyx merged 1 commit intoAug 25, 2026
Merged
Conversation
SubmitReport had no way to take a context, so the POST always ran with context.Background(). Once an upload started, a cancelled scan or a shutdown could not stop it and the caller waited for the client timeout. Add SubmitReportWithContext, which passes the caller context through the existing WithContext request option, and keep SubmitReport as a wrapper over it using context.Background() so existing callers are unaffected. This follows how GetExceptionsWithContext and GetControlsInputsWithContext were added in kubescape#57. Fixes kubescape#58 Signed-off-by: Arnesh Banerjee <linkrinku13@gmail.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
matthyx
approved these changes
Aug 25, 2026
matthyx
left a comment
Contributor
There was a problem hiding this comment.
Reviewed against #58's acceptance criteria — all met:
SubmitReportWithContext(ctx, report, opts...)is additive;SubmitReportstays a thin wrapper overcontext.Background(), so existing callers are unaffected.- The context reaches the transport via the existing
WithContextrequest option →http.NewRequestWithContext, same shape asGetExceptionsWithContext/GetControlsInputsWithContextfrom #57. opts = append([]RequestOption{WithContext(ctx), WithContentJSON(true)}, opts...)preserves the originalWithContentJSON(true)behavior for callers while still letting explicitoptswin, consistent with the functional-options pattern inkscloudoption.go.- The recording
RoundTrippertests are solid: they verify the context value reaches the request, that cancelling an in-flight (blocked) request surfacescontext.Canceled, that a timeout surfacescontext.DeadlineExceeded(both checked witherrors.Is, so they survive the*url.Errorwrapping fromhttp.Client), that extra request options still apply, and that plainSubmitReportstill works. - Checks are green (GitGuardian, DCO); the
go vetcopylocks findings mentioned in the description are pre-existing onmainand untouched here.
No blockers. Approving.
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.
Fixes #58
SubmitReporttakes no context, so the report POST always ran withcontext.Background(). Kubescape checksctx.Err()between report chunks, but once an upload was on the wire nothing could stop it, and a cancelled scan or a shutdown had to wait out the client timeout.This adds
SubmitReportWithContext(ctx, report, opts...)and keepsSubmitReportas a wrapper over it withcontext.Background(), so existing callers are unchanged. The context goes through theWithContextrequest option that is already used byget/post, so no new plumbing was needed. This is the same shape asGetExceptionsWithContextandGetControlsInputsWithContextfrom #57.Tests use a recording
RoundTripperthat can block until the request context is done, and cover:context.Canceledcontext.DeadlineExceededSubmitReportbehaving as beforeVerified locally with
go build ./...,go test ./...andgo test -race ./..., all passing.go vet ./...reports fourcopylocksfindings inpkg/server/v1/systemreports/datastructures_test.go, which are present onmainbefore this change and are untouched here.