mirror of https://github.com/k3s-io/k3s
Merge pull request #65676 from dkoshkin/kubeadm-version-timeout
Automatic merge from submit-queue (batch tested with PRs 66094, 65676). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add a timeout when fetching latest version **What this PR does / why we need it**: When there is no internet on the node and `--kubernetes-versio`n is not specified running `kubeadm init` hangs forever with no text output. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes https://github.com/kubernetes/kubeadm/issues/986 **Special notes for your reviewer**: Using the same duration as the existing timeout `externalEtcdRequestTimeout` Sample output: ``` kubeadm init unable to get URL "https://dl.k8s.io/release/stable-1.11.txt": Get https://dl.k8s.io/release/stable-1.11.txt: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) ``` **Release note**: ```release-note kubeadm: use an HTTP request timeout when fetching the latest version of Kubernetes from dl.k8s.io ```pull/8/head
commit
bc25b1a708
|
@ -22,10 +22,15 @@ import (
|
|||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
netutil "k8s.io/apimachinery/pkg/util/net"
|
||||
)
|
||||
|
||||
const (
|
||||
getReleaseVersionTimeout = time.Duration(10 * time.Second)
|
||||
)
|
||||
|
||||
var (
|
||||
kubeReleaseBucketURL = "https://dl.k8s.io"
|
||||
kubeReleaseRegex = regexp.MustCompile(`^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-0-9a-zA-Z_\.+]*)?$`)
|
||||
|
@ -69,7 +74,7 @@ func KubernetesReleaseVersion(version string) (string, error) {
|
|||
|
||||
if kubeReleaseLabelRegex.MatchString(versionLabel) {
|
||||
url := fmt.Sprintf("%s/%s.txt", bucketURL, versionLabel)
|
||||
body, err := fetchFromURL(url)
|
||||
body, err := fetchFromURL(url, getReleaseVersionTimeout)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -132,8 +137,8 @@ func splitVersion(version string) (string, string, error) {
|
|||
}
|
||||
|
||||
// Internal helper: return content of URL
|
||||
func fetchFromURL(url string) (string, error) {
|
||||
client := &http.Client{Transport: netutil.SetOldTransportDefaults(&http.Transport{})}
|
||||
func fetchFromURL(url string, timeout time.Duration) (string, error) {
|
||||
client := &http.Client{Timeout: timeout, Transport: netutil.SetOldTransportDefaults(&http.Transport{})}
|
||||
resp, err := client.Get(url)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to get URL %q: %s", url, err.Error())
|
||||
|
|
Loading…
Reference in New Issue