From 6e2a70eac7ce3458e2fcb61a86384914efa17e3b Mon Sep 17 00:00:00 2001 From: "Rostislav M. Georgiev" Date: Wed, 2 Sep 2020 12:52:02 +0300 Subject: [PATCH] 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 --- cmd/kubeadm/app/cmd/upgrade/common.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/kubeadm/app/cmd/upgrade/common.go b/cmd/kubeadm/app/cmd/upgrade/common.go index fe8e54a4143..71b2fab6bcc 100644 --- a/cmd/kubeadm/app/cmd/upgrade/common.go +++ b/cmd/kubeadm/app/cmd/upgrade/common.go @@ -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)