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:
- https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/phases/upgrade/health.go#L142-L147
- 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)
we do not. please call “upgrade plan” only once - only on the node where you run “upgrade apply”. this is already in the docs.
We did come across same issue while upgrading to 1.31.4
the chances of hitting an already generated name from a prior kubeadm run are minimal:
https://github.com/kubernetes/kubernetes/blob/16a594f907d0d4a6224dab2d0704793d5e7898f6/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go#L121-L134
what errors are you getting @taotriad ?
cc @carlory
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.