kubernetes: Deletion of upgrade-health-check during the upgrade preflight could fail due to a race condition and surfaced as CreateJob failure

What happened?

I have seen false positives in the upgrade preflight where CreateJob fails because kube-system/upgrade-health-check job is not found when trying to delete it.

Looking at the code, there is a bit of inconsistent treatment in the creation and the deletion of the job during the cluster health check.

When creating the job to test if a job can be created on the cluster, the job creation accounts for a possibility of race condition and have a retry to mitigate this.

However, the deletion code doesn’t take care of the same race condition in two places:

  1. https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/phases/upgrade/health.go#L142-L147
  2. https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/phases/upgrade/health.go#L149-L152

Specifically, I think deleteHealthCheckJob should ignore NotFound errors to be resilient to the cases where the job was deleted by another client (basically --ignore-not-found=true is what we want here).

What did you expect to happen?

Ignore NotFound error when attempting to delete the upgrade-health-check job.

How can we reproduce it (as minimally and precisely as possible)?

With 3 control plane node setup and run kubeadm upgrade plan on three nodes at the same time and this probably happens once in a while.

Anything else we need to know?

If the requested change sounds reasonable, I can work on making the changes.

Kubernetes version

$ kubectl version
Have observed this in 1.25.x to 1.27.x

Cloud provider

OS version

# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, …) and versions (if applicable)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 51 (42 by maintainers)

Most upvoted comments

/cc @neolit123 Do we support run kubeadm upgrade plan on three nodes at the same time?

we do not. please call “upgrade plan” only once - only on the node where you run “upgrade apply”. this is already in the docs.

Still observed this issue in 1.31.2

set -o pipefail
kubeadm upgrade plan --config=/etc/kubernetes/kubeadmin-config.yaml
echo "Y" | kubeadm upgrade apply --config=/etc/kubernetes/kubeadmin-config.yaml 1.31.2

[upgrade/health] FATAL: [preflight] Some fatal errors occurred:
        [ERROR CreateJob]: Job "upgrade-health-check-4qjpt" in the namespace "kube-system" did not complete in 15s: no condition of type Complete
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

[upgrade/health] FATAL: [preflight] Some fatal errors occurred:
        [ERROR CreateJob]: Job "upgrade-health-check-kkvjt" in the namespace "kube-system" did not complete in 15s: no condition of type Complete
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

We did come across same issue while upgrading to 1.31.4

what errors are you getting @taotriad ?

cc @carlory

Even in this case, we still don’t want to make it more reliable by simply ignoring the job NotFound when trying to delete it?

the delete code is being removed: https://github.com/kubernetes/kubernetes/pull/122079

this will land in 1.30. i don’t think we should backport a fix. IMO, just avoid calling plan for multiple places, that will never be supported.