Add generic pre upgrade hook for node#13289
Conversation
This patch is based on kubernetes-sigs#11368 and adds the ability to run a hook job befor drain of a node. My specific use-case is doing live migration of all vm:s running in openstack in kubernetes, before draining a host, allowing openstack workloads to survive upgrades. I am sure other use-cases are available too :) Signed-off-by: Micke Nordin <kano@sunet.se>
|
Hi @mickenordin. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mickenordin The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for running configurable “pre-upgrade hooks” prior to draining a node during the pre-upgrade stage.
Changes:
- Introduces a
pre_upgrade_hooksloop that includes hook task files before the drain step whenneeds_cordoningis true.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/ok-to-test |
I don't see any comments about why adding these features is a bad idea, only that you preferred to add some special code for a few specific use-cases? Being able to do post-processing (already possible with a hook today) and pre-processing of generic tasks is extremely useful, as demonstrated by the multiple previous pr:s (that I had missed). How would I be able to achieve my use-case of live-migrating vm:s running in openstack during rolling upgrades with kubespray any other way, unless you want to add a special case code for that specific use case too? Not having that ability pretty much excludes anyone running any of the openstack kubernetes deployments for k8s out there from using kubespray to manage their cluster? |
The reasoning is already in those comments — let me put it more directly. The real problem isn't this particular use case; it's that the "generic hooks" mechanism lacks a unified design. The prior art ( This hook has no tests, no documentation, and no defined failure semantics — if a hook fails, should the upgrade stop or continue? That means there's no functional guarantee of any kind, and I don't think a maintainer can take responsibility for an execution point without a contract.
What's the actual relationship between |
You are of course entitled to manage your project as you wish, I was looking for a solution to my problem, found that you had implemented half of what I needed already, and wanted to add the other part.
This is definitely a valid concern. Given the number of PR's that you have had at this point, wanting to implement a complete hook system, rather than a single hook at one point in the upgrade process, maybe this is something to focus on? Perhaps a system of a small number of well defined hooks, with a well documented contract and usage documentation is something that would be of value to this project. I am willing to put some effort in adding such a mechanism, if you are not happy with just implementing a single hook, along the line of the one you already have.
Yes, exactly. There are several projects that package OpenStack as Kubernetes manifests with the compute happening on the worker nodes of the kubernetes cluster. |
|
I take it you won't be merging this? That is fine of course, I can soft-fork and maintain a patch set outside of the repo too, but I would prefer if it was not necessary 😅 |
…cordon) Replace the ad-hoc pre_upgrade_hooks with a symmetric set of four hook points around the node upgrade lifecycle: pre_cordon_hooks, pre_upgrade_hooks, post_upgrade_hooks (unchanged from kubernetes-sigs#11368) and post_uncordon_hooks. Cordon-lifecycle hooks gate on needs_cordoning; upgrade-lifecycle hooks always run. Hooks are fail-fast. Add defaults and document the contract, failure semantics and an OpenStack live-migration example in docs/operations/upgrades.md. Signed-off-by: Micke Nordin <kano@sunet.se>
|
I have now added a system of four hooks:
With documentation and a failure contract. If you don't like it, please close the PR as WONTFIX. |
I think it's reasonable. However, as for the specifics of how to implement or add it, you'll need to get the other approvers on board. At least for now, I'm not looking to turn down this proposal. If we can have systematic hooks, I think we can leverage advantages that other K8s distributions don't have. cc @VannTen |
This patch is based on #11368 and adds the ability to run a hook job before drain of a node. My specific use-case is doing live migration of all VMs running in OpenStack in Kubernetes before draining a host, allowing OpenStack workloads to survive upgrades. I am sure other use-cases are available too :)
What type of PR is this?
/kind feature
What this PR does / why we need it:
Kubespray already exposes
post_upgrade_hooksfor running custom tasks per-host after the kubelet/containerd upgrade but before uncordon. This PR adds a symmetricalpre_upgrade_hooksfor running custom tasks per-host before the drain happens.Without a pre-drain hook there is no clean place to inject workload-level prep work that has to happen while the node is still hosting workloads, such as live-migrating OpenStack VMs off a compute node, gracefully draining stateful clients, scheduling-policy adjustments, or anything else that needs the node to still be schedulable.
The hook fires from
roles/upgrade/pre-upgrade/tasks/main.ymlright afterneeds_cordoningis set and right before theNode drainingblock, mirroring the existing post-hook shape:Default is an empty list, so the change is a no-op for any user who does not set the variable.
Which issue(s) this PR fixes:
Fixes #13288
Special notes for your reviewer:
post_upgrade_hooks): same variable shape, sameinclude_tasksloop, just earlier in the per-host serial loop.needs_cordoningso the hook only fires for nodes that will actually be drained on this run, matching the gating of theNode drainingblock right below it.pre_upgrade_hooks.Does this PR introduce a user-facing change?:
Yes