Repository navigation
Stop concurrent CKS operations clobbering each other, recover stuck states - #14609
Open
bhouse-nexthop wants to merge 1 commit into
Open
bhouse-nexthop wants to merge 1 commit into
bhouse-nexthop wants to merge 1 commit into
Conversation
3 of 12 tasks
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.22 #14609 +/- ##
============================================
+ Coverage 18.32% 18.34% +0.01%
- Complexity 16644 16665 +21
============================================
Files 5939 5939
Lines 537768 537892 +124
Branches 65929 65950 +21
============================================
+ Hits 98551 98676 +125
+ Misses 428008 427995 -13
- Partials 11209 11221 +12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…tates A Kubernetes cluster's state was written by id alone, so two operations started on the same cluster at once both got past their first transition. Each then ran its steps against VMs the other was changing, and whichever finished last decided the final state. The status scanner could also overwrite the state of an operation that started after it read the cluster. The state is now compared and set in one update, as the VM and volume states are. Each operation moves the cluster into its own state before it changes anything, and fails without touching the cluster when another operation got there first. From then on it only moves the cluster while the cluster is in a state the operation moved it to. Starting a cluster in Alert now moves it to Starting like any other start. A start from Error, a stop from Created or Error, and a retried destroy still go on without a state change, as they did before; the start and stop then leave the state alone when they end. From any other state with no transition for it, an operation is now refused instead of running alongside the one that holds the cluster. The scanner only completes a stop or a recovery that it started itself. A management server that stopped during an operation left the cluster in that operation's state. Nothing moved it on, and every later operation on it was refused until the database was edited by hand. The scanner now fails the operation of a cluster in an operation's state when no job is in progress for it on any management server. The existing Alert reconciliation then returns a healthy cluster to Running. To find those jobs, the start, stop, scale and upgrade jobs now record their cluster, as the create, delete and node jobs already did. A cluster named by a job in progress on a management server of an older version, which does not record it, is left alone. This replaces the scanner's first-run handling of Starting clusters, which tried a transition that does not exist. No schema or API change. Signed-off-by: Brad House <[email protected]>
bhouse-nexthop
force-pushed
the
cks-stuck-state-recovery
branch
from
November 7, 2026 12:08
f5c2ea9 to
fee9834
Compare
Collaborator
Author
|
Updated the commit (now
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Two related fixes to how a CKS cluster's state is kept.
Fixes #14608
Concurrent operations
KubernetesClusterDaoImpl.updateStatewrote the state by id alone, so two operations on one cluster both got past their first transition. The workers also ignored a failed entry transition, and carried on.KubernetesClusterDaoImpl.updateState): the update now hasWHERE id = ? AND state = ?and reports whether a row changed, asVolumeDaoImplandVMInstanceDaoImplalready do.KubernetesClusterActionWorker.transitToOperationState): each worker moves the cluster into its operation's state before it changes anything. If another operation got there first, the worker fails with a "please retry" message. It does not move the cluster, and does not undo anything the other operation may need, such as the template launch permission.Alert -StartRequested-> Startingtransition), like any other start. Before, the start ran without a state, so adding or removing nodes, a stop, or the scanner's Alert reconciliation could take the cluster partway through.KubernetesClusterActionWorker.stateTransitTo). So a failure or completion never ends another operation that has taken the cluster since. An operation that went ahead without a state change leaves the state alone when it ends, except a retried destroy, which completes Destroying.KubernetesClusterResourceModifierActionWorker.enterScalingState): an operation enters Scaling or ScalingStoppedCluster once, at its first scaling step. A scale or autoscale of a Created cluster still only changes the stored settings, decided from the state the worker started from.reconcileAlertClusteronly completes a recovery that it started itself.Stuck states
Before this change, if a management server stopped during an operation, the async job was failed when the server came back or a peer saw it leave. The cluster stayed in Scaling, Upgrading, Starting and so on, and every later operation was refused.
KubernetesClusterManagerImpl.recoverOrphanedOperationStates, run by the status scanner on every pass): it covers a cluster in Starting, Stopping, Scaling, ScalingStoppedCluster, Upgrading, Importing, RemovingNodes or Recovering that has no IN_PROGRESS job on any management server. The scanner fails its operation; Upgrading, for example, goes to Alert. The existing Alert reconciliation then returns a healthy cluster to Running.getApiResourceId). Create, delete and add/remove nodes already did. This also fills in the resource on those commands' events.FaultsDetected, which has no transition from Starting.No schema or API change. The binaries ISO that an interrupted operation attached is left on the VMs. The next operation's attach replaces it.
Relation to #14604
#14604 lets a cluster in Alert be scaled. It adds
Alert -> Scalingtransitions, whichenterScalingStateuses as they are. Its own check of the state when the scale worker starts still applies. This PR closes the narrow window between that check and the transition, which #14604 mentions. The two branches merge with one trivial conflict inKubernetesClusterManagerImplTest, where both add tests at the end.Types of changes
Feature/Enhancement Scale or Bug Severity
Bug Severity
How Has This Been Tested?
mvn -pl plugins/integrations/kubernetes-service verifypasses: all of the plugin's unit tests, plus checkstyle.KubernetesClusterDaoImplTest: the update is restricted to the current state, and returns false when no row changed.KubernetesClusterActionWorkerTest:transitToOperationStatemoves the cluster;failOperationIfStillInleaves a cluster that has moved on.KubernetesClusterResourceModifierActionWorkerTest:enterScalingStatetransitions once for all steps of an operation;KubernetesClusterManagerImplTest:How did you try to break this feature and the system with this change?
job.expire.minutes, which is 1440 by default. If that setting is lowered below the length of a long operation, recovery can fail the operation while it is still running.Starting -> Stopping.