kubeadm: Fix upgrade plan for air-gapped setups

A bug was discovered in the `enforceRequirements` func for `upgrade plan`.
If a command line argument that specifies the target Kubernetes version is
supplied, the returned `ClusterConfiguration` by `enforceRequirements` will
have its `KubernetesVersion` field set to the new version.
If no version was specified, the returned `KubernetesVersion` points to the
currently installed one.

This remained undetected for a couple of reasons
- It's only `upgrade plan` that allows for the version command line argument to
  be optional (in `upgrade plan` it's mandatory)
- Prior to 1.19, the implementation of `upgrade plan` did not make use of the
  `KubernetesVersion` returned by `enforceRequirements`.

`upgrade plan` supports this optional command line argument to enable
air-gapped setups (as not specifying a version on the command line will end up
looking for the latest version over the Interned).

Hence, the only option is to make `enforceRequirements` consistent in the
`upgrade plan` case and always return the currently installed version in the
`KubernetesVersion` field.

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
This commit is contained in:
Rostislav M. Georgiev 2020-09-02 12:52:02 +03:00
parent c236285708
commit 6e2a70eac7

View File

@ -185,7 +185,15 @@ func enforceRequirements(flags *applyPlanFlags, args []string, dryRun bool, upgr
// If option was specified in both args and config file, args will overwrite the config file.
if len(args) == 1 {
newK8sVersion = args[0]
cfg.KubernetesVersion = newK8sVersion
if upgradeApply {
// The `upgrade apply` version always overwrites the KubernetesVersion in the returned cfg with the target
// version. While this is not the same for `upgrade plan` where the KubernetesVersion should be the old
// one (because the call to getComponentConfigVersionStates requires the currently installed version).
// This also makes the KubernetesVersion value returned for `upgrade plan` consistent as that command
// allows to not specify a target version in which case KubernetesVersion will always hold the currently
// installed one.
cfg.KubernetesVersion = newK8sVersion
}
}
// If features gates are passed to the command line, use it (otherwise use featureGates from configuration)