Add distributed node locking to prevent concurrent maintenance operations #737
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.45) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 440 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.364
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #737"
general
weight: 0.35
jtschelling
Summary
This PR implements Kubernetes Lease-based distributed locking to prevent concurrent maintenance operations from operating on the same node simultaneously. This critical enhancement ensures safe coordination when multiple RebootNode or TerminateNode CRs target the same node.
Changes
New Package:
pkg/distributedlockFile:
nodelock.go(~200 lines)NodeLockinterface withLockNode()andCheckUnlock()methodscoordination.k8s.io/v1LeasesController Integration
RebootNode Controller (
pkg/controller/rebootnode_controller.go):TerminateNode Controller (
pkg/controller/terminatenode_controller.go):Metrics
Added lock/unlock action types to
pkg/metrics/metrics.go:ActionTypeLock- Lock acquisition failuresActionTypeUnlock- Lock release failuresRBAC
Updated both controllers with lease permissions:
How It Works
1. Lock Acquisition: Before reconciling, controller tries to create a Lease with the node name in the
nvsentinel-systemnamespace2. Lock Hold: If successful, reconciliation proceeds; the Lease remains until CompletionTime is set
3. Lock Release: After CompletionTime is set, the next reconcile deletes the Lease
4. Automatic Cleanup: OwnerReferences ensure Leases are deleted if the maintenance CR is deleted
Concurrency Handling
RebootNode-Aholds a lock onnode-1,RebootNode-Btargeting the same node will requeue until the lock is releasedTesting
Performance Impact
🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
New Features
Per-node distributed locking added to maintenance controllers to serialize operations; lock namespace configurable via POD_NAMESPACE; lock/unlock actions emit metrics.
Controllers now refresh status after reconciliation and perform unlock checks when work is complete.
Tests
Extensive unit and integration tests covering lock acquisition, release, ownership scenarios, error paths, and metrics validation.
Chores
* RBAC updated to allow lease management; deployment updated to supply POD_NAMESPACE.
<sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->