Merge pull request #54016 from praseodym/kubeadm-upgrade-plan-offline

Automatic merge from submit-queue (batch tested with PRs 54160, 54016). 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>.

Fix `kubeadm upgrade plan` for offline operation

**What this PR does / why we need it**:
This PR allows `kubeadm upgrade plan` to work in firewalled/offline/otherwise restricted environments by ignoring errors when trying to reach dl.k8s.io. Instead, we fall back to the current kubeadm version as the latest stable version. This is a reasonable as a user is [expected to install a recent version of kubeadm before upgrading](https://kubernetes.io/docs/tasks/administer-cluster/kubeadm-upgrade-1-8/#upgrading-your-control-plane).

**Which issue this PR fixes**: Fixes kubernetes/kubeadm#498

**Special notes for your reviewer**: Should preferably be cherrypicked to 1.8.

```release-note
Fix `kubeadm upgrade plan` for offline operation: ignore errors when trying to fetch latest versions from dl.k8s.io
```
This commit is contained in:
Kubernetes Submit Queue 2017-10-31 01:23:18 -07:00 committed by GitHub
commit eb658d699a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 28 deletions

View File

@ -62,7 +62,7 @@ type ClusterState struct {
// GetAvailableUpgrades fetches all versions from the specified VersionGetter and computes which // GetAvailableUpgrades fetches all versions from the specified VersionGetter and computes which
// kinds of upgrades can be performed // kinds of upgrades can be performed
func GetAvailableUpgrades(versionGetterImpl VersionGetter, experimentalUpgradesAllowed, rcUpgradesAllowed bool) ([]Upgrade, error) { func GetAvailableUpgrades(versionGetterImpl VersionGetter, experimentalUpgradesAllowed, rcUpgradesAllowed bool) ([]Upgrade, error) {
fmt.Println("[upgrade] Fetching available versions to upgrade to:") fmt.Println("[upgrade] Fetching available versions to upgrade to")
// Collect the upgrades kubeadm can do in this list // Collect the upgrades kubeadm can do in this list
upgrades := []Upgrade{} upgrades := []Upgrade{}
@ -82,7 +82,9 @@ func GetAvailableUpgrades(versionGetterImpl VersionGetter, experimentalUpgradesA
// Get and output the current latest stable version // Get and output the current latest stable version
stableVersionStr, stableVersion, err := versionGetterImpl.VersionFromCILabel("stable", "stable version") stableVersionStr, stableVersion, err := versionGetterImpl.VersionFromCILabel("stable", "stable version")
if err != nil { if err != nil {
return nil, err fmt.Printf("[upgrade/versions] WARNING: %v\n", err)
fmt.Println("[upgrade/versions] WARNING: Falling back to current kubeadm version as latest stable version")
stableVersionStr, stableVersion = kubeadmVersionStr, kubeadmVersion
} }
// Get the kubelet versions in the cluster // Get the kubelet versions in the cluster
@ -115,9 +117,8 @@ func GetAvailableUpgrades(versionGetterImpl VersionGetter, experimentalUpgradesA
// Get and output the latest patch version for the cluster branch // Get and output the latest patch version for the cluster branch
patchVersionStr, patchVersion, err := versionGetterImpl.VersionFromCILabel(versionLabel, description) patchVersionStr, patchVersion, err := versionGetterImpl.VersionFromCILabel(versionLabel, description)
if err != nil { if err != nil {
return nil, err fmt.Printf("[upgrade/versions] WARNING: %v\n", err)
} } else {
// Check if a minor version upgrade is possible when a patch release exists // Check if a minor version upgrade is possible when a patch release exists
// It's only possible if the latest patch version is higher than the current patch version // It's only possible if the latest patch version is higher than the current patch version
// If that's the case, they must be on different branches => a newer minor version can be upgraded to // If that's the case, they must be on different branches => a newer minor version can be upgraded to
@ -145,6 +146,7 @@ func GetAvailableUpgrades(versionGetterImpl VersionGetter, experimentalUpgradesA
}) })
} }
} }
}
if canDoMinorUpgrade { if canDoMinorUpgrade {
upgrades = append(upgrades, Upgrade{ upgrades = append(upgrades, Upgrade{

View File

@ -86,7 +86,7 @@ func (g *KubeVersionGetter) KubeadmVersion() (string, *versionutil.Version, erro
func (g *KubeVersionGetter) VersionFromCILabel(ciVersionLabel, description string) (string, *versionutil.Version, error) { func (g *KubeVersionGetter) VersionFromCILabel(ciVersionLabel, description string) (string, *versionutil.Version, error) {
versionStr, err := kubeadmutil.KubernetesReleaseVersion(ciVersionLabel) versionStr, err := kubeadmutil.KubernetesReleaseVersion(ciVersionLabel)
if err != nil { if err != nil {
return "", nil, fmt.Errorf("Couldn't fetch latest %s version from the internet: %v", description, err) return "", nil, fmt.Errorf("Couldn't fetch latest %s from the internet: %v", description, err)
} }
if description != "" { if description != "" {
@ -95,7 +95,7 @@ func (g *KubeVersionGetter) VersionFromCILabel(ciVersionLabel, description strin
ver, err := versionutil.ParseSemantic(versionStr) ver, err := versionutil.ParseSemantic(versionStr)
if err != nil { if err != nil {
return "", nil, fmt.Errorf("Couldn't parse latest %s version: %v", description, err) return "", nil, fmt.Errorf("Couldn't parse latest %s: %v", description, err)
} }
return versionStr, ver, nil return versionStr, ver, nil
} }