Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions internal/cli/alpha/internal/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package internal

import (
"context"
"fmt"
"io"
log "log/slog"
Expand All @@ -25,6 +26,7 @@ import (
"os/exec"
"runtime"
"strings"
"time"

"github.com/spf13/afero"
"golang.org/x/mod/semver"
Expand Down Expand Up @@ -130,7 +132,15 @@ func (opts *Update) downloadKubebuilderBinary() (string, error) {
}()

// Download the binary from GitHub releases
response, err := http.Get(url)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
Comment on lines +135 to +136
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.


req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return "", fmt.Errorf("failed to build download request: %w", err)
}

response, err := http.DefaultClient.Do(req)
if err != nil {
return "", fmt.Errorf("failed to download the binary: %w", err)
}
Expand Down Expand Up @@ -475,7 +485,15 @@ func (opts *Update) validateBinaryAvailability() error {
opts.BinaryURL = fmt.Sprintf("https://github.com/kubernetes-sigs/kubebuilder/releases/download/%s/kubebuilder_%s_%s",
opts.CliVersion, runtime.GOOS, runtime.GOARCH)

resp, err := http.Head(opts.BinaryURL)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()

req, err := http.NewRequestWithContext(ctx, http.MethodHead, opts.BinaryURL, nil)
if err != nil {
return fmt.Errorf("failed to build binary availability request: %w", err)
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("failed to check binary availability: %w", err)
}
Expand Down
13 changes: 12 additions & 1 deletion internal/cli/alpha/internal/update/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ limitations under the License.
package update

import (
"context"
"encoding/json"
"fmt"
log "log/slog"
"net/http"
"strings"
"time"

"sigs.k8s.io/kubebuilder/v4/internal/cli/alpha/internal/common"
"sigs.k8s.io/kubebuilder/v4/pkg/config/store"
Expand Down Expand Up @@ -92,7 +94,16 @@ func (opts *Update) defineToVersion() string {
}

func fetchLatestRelease() (string, error) {
resp, err := http.Get("https://api.github.com/repos/kubernetes-sigs/kubebuilder/releases/latest")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()

req, err := http.NewRequestWithContext(ctx, http.MethodGet,
"https://api.github.com/repos/kubernetes-sigs/kubebuilder/releases/latest", nil)
if err != nil {
return "", fmt.Errorf("failed to build release request: %w", err)
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", fmt.Errorf("failed to fetch latest release: %w", err)
}
Expand Down