Repository navigation
Commit 8a8b89e
committed
CKS: fix node drain on scale-down and upgrade, make a failed upgrade resumable
Scale-down and upgrade both drain a node before touching it, each with its
own copy of the drain loop, and neither works well:
- Scale-down gives up at once when kubectl drain exits non-zero (a
PodDisruptionBudget that does not allow an eviction yet, say), and when
it does retry after an exception it counts the attempt twice. The node
is left cordoned, and the cluster goes to Alert although nothing has
been removed and every node still works.
- Upgrade retries straight away, with no wait for the eviction to become
possible, and on the last failure leaves the node cordoned.
- In both, kubectl drain has no --timeout, so it is cut off by a fixed
60s SSH timeout rather than a deadline of its own.
Both workers now use one drain helper in KubernetesClusterActionWorker:
one count per attempt, a retry (after a wait) on a non-zero exit or an
exception, kubectl drain --timeout from the new setting
cloud.kubernetes.cluster.node.drain.timeout (300s), cut down so that no
attempt runs past the operation's deadline, with the SSH wait derived
from it, and the end of the drain output in the error. The caller
uncordons the node, and only if it cordoned it. Scale-down cordons every node it is going to
remove (leaving alone the ones that were cordoned already), drains them, and if one cannot be drained uncordons them all and
puts the cluster back in the state it was in, with an error that names
the node, instead of Alert; the same happens if the scale times out
before every node is drained. Once they are drained, the removal is not
stopped part way by the timeout any more. If removing a node fails, the
nodes still in the cluster are uncordoned.
The upgrade had two more problems:
- It only waited for the first control node to be Ready, so the next
node could be drained while the previous one was still coming back.
It now waits for every node, after it has been uncordoned.
- It reached node i on sshPort + i. The port-forwarding rules are not
created in the order of the upgrade's VM list (manually upgraded nodes
are left out of that list, and nodes added later get the next free
port), so the script could run on the wrong node. It now looks up the
node's own SSH port-forwarding rule, as the remove worker already does.
A failed upgrade left the cluster in Alert with no way to finish it, as
upgradeKubernetesCluster only accepts a Running cluster. An upgrade now
records the version it is upgrading to as a cluster detail (an existing
key/value table) and removes it once the cluster is Running or Stopped
again. upgradeKubernetesCluster
accepts a cluster in Alert (Alert -> Upgrading) when that detail is the
requested version (or another one with the same semantic version), which
is a real upgrade of the cluster's own version,
and all of the cluster's VMs are running, and refuses
any other Alert cluster with a clear message. For an upgrade that failed
before this change, a cluster still at the old version with nodes
recorded at the target version (kubernetesnodeversion, which is set as
each node is done) is accepted too. Nodes that are already at the target
version, both as recorded and as reported by kubectl get node, and
that are Ready, are skipped. The first control node is still upgraded first; if it is
already done, kubeadm upgrade apply is not run again. The node version
check now compares versions exactly, so 1.28.1 no longer matches
1.28.10, line by line, as the SSH output can hold stderr too, and
ignoring semver build metadata. Failure messages name the node the upgrade stopped on. The upgrade
stops if it can't move the cluster to Upgrading, and the Alert state
scanner no longer marks a cluster Running when it couldn't move it to
Recovering, and a failed upgrade detaches its ISO before going to Alert,
so a retry and the scanner or the failing job don't undo each other's
work.
No schema change.
Signed-off-by: Brad House <bhouse@nexthop.ai>
(cherry picked from commit 0dcaa8f)1 parent 3c8049c commit 8a8b89e
13 files changed
Lines changed: 929 additions & 102 deletions
File tree
- api/src/main/java/com/cloud/kubernetes/cluster
- plugins/integrations/kubernetes-service/src
- main/java/com/cloud/kubernetes/cluster
- actionworkers
- utils
- test/java/com/cloud/kubernetes/cluster
- actionworkers
- utils
- ui/src/config/section
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
| |||
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
| 179 | + | |
178 | 180 | | |
179 | 181 | | |
180 | 182 | | |
| |||
1570 | 1572 | | |
1571 | 1573 | | |
1572 | 1574 | | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
1573 | 1609 | | |
1574 | 1610 | | |
1575 | 1611 | | |
| |||
1590 | 1626 | | |
1591 | 1627 | | |
1592 | 1628 | | |
1593 | | - | |
| 1629 | + | |
| 1630 | + | |
1594 | 1631 | | |
1595 | 1632 | | |
1596 | 1633 | | |
| |||
1604 | 1641 | | |
1605 | 1642 | | |
1606 | 1643 | | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
1607 | 1654 | | |
1608 | 1655 | | |
1609 | 1656 | | |
| |||
1640 | 1687 | | |
1641 | 1688 | | |
1642 | 1689 | | |
1643 | | - | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
1644 | 1697 | | |
1645 | 1698 | | |
1646 | 1699 | | |
| |||
3135 | 3188 | | |
3136 | 3189 | | |
3137 | 3190 | | |
| 3191 | + | |
3138 | 3192 | | |
3139 | 3193 | | |
3140 | 3194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
91 | 98 | | |
92 | 99 | | |
93 | 100 | | |
| |||
0 commit comments