Skip to content

🐛 (CLI): Add context timeout to HTTP calls in alpha update#5695

Merged
k8s-ci-robot merged 1 commit into
kubernetes-sigs:masterfrom
SebTardif:fix/http-get-no-timeout
May 19, 2026
Merged

🐛 (CLI): Add context timeout to HTTP calls in alpha update#5695
k8s-ci-robot merged 1 commit into
kubernetes-sigs:masterfrom
SebTardif:fix/http-get-no-timeout

Conversation

@SebTardif
Copy link
Copy Markdown
Contributor

What

Replace http.Get (no timeout) with http.NewRequestWithContext in two call sites in the alpha update command.

Why

Both call sites use http.DefaultClient with no timeout. If GitHub is unreachable, the CLI blocks indefinitely with no way to cancel. The newer helpers/download.go in the same package already uses context.WithTimeout correctly for the same kind of download operation.

Call sites fixed:

  • downloadKubebuilderBinary (update.go:133): downloads a release binary from GitHub. Now uses a 2-minute timeout, matching helpers/download.go:71.
  • fetchLatestRelease (prepare.go:95): fetches the latest release tag from the GitHub API. Now uses a 30-second timeout (generous for a single JSON response).

How

  • Replaced http.Get(url) with http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + http.DefaultClient.Do(req)
  • Added context.WithTimeout with appropriate durations for each call site
  • Follows the existing pattern in helpers/download.go:71-81

Both call sites were introduced in #4871 (2025-06-12).

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 13, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @SebTardif. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 13, 2026

func fetchLatestRelease() (string, error) {
resp, err := http.Get("https://api.github.com/repos/kubernetes-sigs/kubebuilder/releases/latest")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
Copy link
Copy Markdown
Member

@camilamacedo86 camilamacedo86 May 15, 2026

Choose a reason for hiding this comment

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

30 secs is really enough?
Should we add a bigger timeout?

What about 1 or 2 minutes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Increased the timeout to 2 minutes for all three HTTP call sites.

@SebTardif
Copy link
Copy Markdown
Contributor Author

@camilamacedo86 The 30s is for fetchLatestRelease(), which is a small JSON API call to GitHub (a few KB). The binary download in downloadKubebuilderBinary() uses 2 minutes, consistent with the existing helpers/download.go:71 precedent in this package.

That said, happy to bump the API call timeout if you have a preferred value.

@camilamacedo86
Copy link
Copy Markdown
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 15, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds bounded contexts to two GitHub HTTP GET calls in the alpha update flow to avoid indefinite blocking during release lookup and binary download.

Changes:

  • Adds a 30-second timeout to fetching the latest Kubebuilder release.
  • Adds a 2-minute timeout to downloading a Kubebuilder release binary.
  • Replaces direct http.Get calls with context-aware requests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/cli/alpha/internal/update/prepare.go Adds a context timeout around the GitHub latest-release API request.
internal/cli/alpha/internal/update.go Adds a context timeout around downloading the Kubebuilder binary from GitHub releases.

Comment on lines +135 to +136
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we address this one?
Could you please ensure that we have only 1 commit after the changes ? (squash)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Added a 2-minute context timeout to validateBinaryAvailability (the http.Head call) as well. Everything is squashed into a single commit.

Comment on lines +97 to +98
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we address this one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in the same update. All three HTTP calls (fetchLatestRelease, downloadKubebuilderBinary, validateBinaryAvailability) now use a 2-minute context timeout.

@camilamacedo86
Copy link
Copy Markdown
Member

/override pull-kubebuilder-e2e-k8s-1-36-0

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@camilamacedo86: Overrode contexts on behalf of camilamacedo86: pull-kubebuilder-e2e-k8s-1-36-0

Details

In response to this:

/override pull-kubebuilder-e2e-k8s-1-36-0

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Replace bare http.Get and http.Head calls with context-bounded
requests using http.NewRequestWithContext so that alpha update
never hangs when GitHub is unreachable.

Affected call sites:
- fetchLatestRelease (GET, 2 min timeout)
- downloadKubebuilderBinary (GET, 2 min timeout)
- validateBinaryAvailability (HEAD, 2 min timeout)

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@SebTardif SebTardif force-pushed the fix/http-get-no-timeout branch from b3d62cb to 2e38fe5 Compare May 15, 2026 19:36
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 15, 2026
@SebTardif
Copy link
Copy Markdown
Contributor Author

/retest pull-kubebuilder-e2e-k8s-1-36-0

@SebTardif
Copy link
Copy Markdown
Contributor Author

/test pull-kubebuilder-e2e-k8s-1-36-0

@camilamacedo86
Copy link
Copy Markdown
Member

/override pull-kubebuilder-e2e-k8s-1-36-0

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@camilamacedo86: Overrode contexts on behalf of camilamacedo86: pull-kubebuilder-e2e-k8s-1-36-0

Details

In response to this:

/override pull-kubebuilder-e2e-k8s-1-36-0

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Copy Markdown
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 19, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, SebTardif

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 19, 2026
@camilamacedo86
Copy link
Copy Markdown
Member

/override pull-kubebuilder-e2e-k8s-1-36-0

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@camilamacedo86: Overrode contexts on behalf of camilamacedo86: pull-kubebuilder-e2e-k8s-1-36-0

Details

In response to this:

/override pull-kubebuilder-e2e-k8s-1-36-0

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@camilamacedo86
Copy link
Copy Markdown
Member

/override pull-kubebuilder-e2e-k8s-1-36-0

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@camilamacedo86: Overrode contexts on behalf of camilamacedo86: pull-kubebuilder-e2e-k8s-1-36-0

Details

In response to this:

/override pull-kubebuilder-e2e-k8s-1-36-0

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot merged commit 10f36ad into kubernetes-sigs:master May 19, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants