mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
kubeadm should always fall back to client version when there is any internet issue
This commit is contained in:
parent
c45b77541b
commit
a4ca944d53
@ -96,10 +96,6 @@ func kubernetesReleaseVersion(version string, fetcher func(string, time.Duration
|
|||||||
url := fmt.Sprintf("%s/%s.txt", bucketURL, versionLabel)
|
url := fmt.Sprintf("%s/%s.txt", bucketURL, versionLabel)
|
||||||
body, err := fetcher(url, getReleaseVersionTimeout)
|
body, err := fetcher(url, getReleaseVersionTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If the network operaton was successful but the server did not reply with StatusOK
|
|
||||||
if body != "" {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if clientVersionErr == nil {
|
if clientVersionErr == nil {
|
||||||
// Handle air-gapped environments by falling back to the client version.
|
// Handle air-gapped environments by falling back to the client version.
|
||||||
klog.Warningf("could not fetch a Kubernetes version from the internet: %v", err)
|
klog.Warningf("could not fetch a Kubernetes version from the internet: %v", err)
|
||||||
|
@ -19,6 +19,7 @@ package util
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -106,19 +107,23 @@ func TestValidConvenientForUserVersion(t *testing.T) {
|
|||||||
|
|
||||||
func TestVersionFromNetwork(t *testing.T) {
|
func TestVersionFromNetwork(t *testing.T) {
|
||||||
type T struct {
|
type T struct {
|
||||||
Content string
|
Content string
|
||||||
Expected string
|
Expected string
|
||||||
ErrorExpected bool
|
FetcherErrorExpected bool
|
||||||
|
ErrorExpected bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentVersion := normalizedBuildVersion(constants.CurrentKubernetesVersion.String())
|
||||||
|
|
||||||
cases := map[string]T{
|
cases := map[string]T{
|
||||||
"stable": {"stable-1", "v1.4.6", false}, // recursive pointer to stable-1
|
"stable": {"stable-1", "v1.4.6", false, false}, // recursive pointer to stable-1
|
||||||
"stable-1": {"v1.4.6", "v1.4.6", false},
|
"stable-1": {"v1.4.6", "v1.4.6", false, false},
|
||||||
"stable-1.3": {"v1.3.10", "v1.3.10", false},
|
"stable-1.3": {"v1.3.10", "v1.3.10", false, false},
|
||||||
"latest": {"v1.6.0-alpha.0", "v1.6.0-alpha.0", false},
|
"latest": {"v1.6.0-alpha.0", "v1.6.0-alpha.0", false, false},
|
||||||
"latest-1.3": {"v1.3.11-beta.0", "v1.3.11-beta.0", false},
|
"latest-1.3": {"v1.3.11-beta.0", "v1.3.11-beta.0", false, false},
|
||||||
"empty": {"", "", true},
|
"empty": {"", currentVersion, true, false},
|
||||||
"garbage": {"<?xml version='1.0'?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message></Error>", "", true},
|
"garbage": {"<?xml version='1.0'?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message></Error>", currentVersion, true, false},
|
||||||
"unknown": {"The requested URL was not found on this server.", "", true},
|
"unknown": {"The requested URL was not found on this server.", currentVersion, true, false},
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range cases {
|
for k, v := range cases {
|
||||||
@ -128,7 +133,7 @@ func TestVersionFromNetwork(t *testing.T) {
|
|||||||
key := strings.TrimSuffix(path.Base(url), ".txt")
|
key := strings.TrimSuffix(path.Base(url), ".txt")
|
||||||
res, found := cases[key]
|
res, found := cases[key]
|
||||||
if found {
|
if found {
|
||||||
if v.ErrorExpected {
|
if v.FetcherErrorExpected {
|
||||||
return "error", errors.New("expected error")
|
return "error", errors.New("expected error")
|
||||||
}
|
}
|
||||||
return res.Content, nil
|
return res.Content, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user