From 9e25a00ec0719986d615a1135e4e6f4cff936c0f Mon Sep 17 00:00:00 2001 From: Dmitry Rozhkov Date: Thu, 27 Dec 2018 12:21:47 +0200 Subject: [PATCH] kubeadm: add final fallback to constants.CurrentKubernetesVersion It may happen that both the git version and the remote version are broken/inaccessible. In this case the broken remote version would be used. To overcome this situation fall back to the constant CurrentKubernetesVersion. The alternative could be os.Exit(1). Also this change fixes Bazel-based unit tests in air-gapped environment. --- cmd/kubeadm/app/util/version.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/kubeadm/app/util/version.go b/cmd/kubeadm/app/util/version.go index 198e6d9d6b1e..4e90b27dda60 100644 --- a/cmd/kubeadm/app/util/version.go +++ b/cmd/kubeadm/app/util/version.go @@ -29,6 +29,7 @@ import ( netutil "k8s.io/apimachinery/pkg/util/net" versionutil "k8s.io/apimachinery/pkg/util/version" "k8s.io/klog" + "k8s.io/kubernetes/cmd/kubeadm/app/constants" pkgversion "k8s.io/kubernetes/pkg/version" ) @@ -92,13 +93,20 @@ func KubernetesReleaseVersion(version string) (string, error) { if body != "" { return "", err } - // Handle air-gapped environments by falling back to the client version. - klog.Infof("could not fetch a Kubernetes version from the internet: %v", err) - klog.Infof("falling back to the local client version: %s", clientVersion) - return KubernetesReleaseVersion(clientVersion) + if clientVersionErr == nil { + // 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("falling back to the local client version: %s", clientVersion) + return KubernetesReleaseVersion(clientVersion) + } } if clientVersionErr != nil { + if err != nil { + klog.Warningf("could not obtain neither client nor remote version; fall back to: %s", constants.CurrentKubernetesVersion) + return KubernetesReleaseVersion(constants.CurrentKubernetesVersion.String()) + } + klog.Warningf("could not obtain client version; using remote version: %s", body) return KubernetesReleaseVersion(body) }