Skip to content

Commit 6e2a70e

Browse files
committed
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 <[email protected]>
1 parent c236285 commit 6e2a70e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cmd/kubeadm/app/cmd/upgrade/common.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,15 @@ func enforceRequirements(flags *applyPlanFlags, args []string, dryRun bool, upgr
185185
// If option was specified in both args and config file, args will overwrite the config file.
186186
if len(args) == 1 {
187187
newK8sVersion = args[0]
188-
cfg.KubernetesVersion = newK8sVersion
188+
if upgradeApply {
189+
// The `upgrade apply` version always overwrites the KubernetesVersion in the returned cfg with the target
190+
// version. While this is not the same for `upgrade plan` where the KubernetesVersion should be the old
191+
// one (because the call to getComponentConfigVersionStates requires the currently installed version).
192+
// This also makes the KubernetesVersion value returned for `upgrade plan` consistent as that command
193+
// allows to not specify a target version in which case KubernetesVersion will always hold the currently
194+
// installed one.
195+
cfg.KubernetesVersion = newK8sVersion
196+
}
189197
}
190198

191199
// If features gates are passed to the command line, use it (otherwise use featureGates from configuration)

0 commit comments

Comments
 (0)