Skip to content

feat(k8s): implement cluster self-healing with repair strategies#373

Open
poyrazK wants to merge 7 commits intomainfrom
release/cluster-self-healing
Open

feat(k8s): implement cluster self-healing with repair strategies#373
poyrazK wants to merge 7 commits intomainfrom
release/cluster-self-healing

Conversation

@poyrazK
Copy link
Copy Markdown
Owner

@poyrazK poyrazK commented Apr 30, 2026

Summary

  • Add health/repair tracking fields to Cluster and ClusterNode structs (IsHealthy, UnhealthySince, FailureReason, RepairAttempts, LastRepairAttempt, LastRepairSucceeded)
  • Implement Repair() in KubeadmProvisioner with two repair strategies:
    • repairAPIServer(): iterate control plane IPs, restart kubelet sequentially
    • repairNodes(): re-apply Calico CNI, restart kube-proxy, restart kubelet on non-ready nodes
  • GetHealth() checks API server reachability and node readiness, persists state to cluster record
  • RepairCluster() in cluster service now guards against concurrent repairs (conflict error)
  • ClusterReconciler now skips clusters repaired within 5 min and unhealthy for less than 2 min (transient tolerance)
  • After failed repair, reconciler updates cluster health state for next cycle's backoff decision
  • Add unit tests for repair flow, conflict guard, and all reconciler backoff conditions

Test plan

  • go test ./internal/repositories/k8s/... — provisioner unit tests
  • go test ./internal/core/services/... — cluster service tests
  • go test ./internal/workers/... — reconciler backoff tests
  • go build ./... — clean build

poyrazK added 3 commits April 30, 2026 18:22
Add health/repair tracking fields to Cluster and ClusterNode structs:
- IsHealthy, UnhealthySince, FailureReason, RepairAttempts,
  LastRepairAttempt, LastRepairSucceeded on Cluster
- UnhealthySince, FailureReason on ClusterNode

ADR-026 documents the self-healing architecture decision.
Replace the Repair() stub with full implementation:
- repairAPIServer(): iterate control plane IPs, restart kubelet sequentially
- repairNodes(): re-apply Calico CNI, restart kube-proxy, restart kubelet on
  individual non-ready nodes
- GetHealth(): check API server reachability and node readiness counts,
  persist health state to cluster record

Includes localMockNodeExecutor to avoid cross-test mock pollution from
restore_test.go package-level mock.
- RepairCluster() in cluster service now rejects repair if already in progress
  (Status == ClusterStatusRepairing returns conflict error)
- ClusterReconciler now skips clusters repaired within 5 minutes and clusters
  unhealthy for less than 2 minutes (transient tolerance)
- After failed repair, reconciler updates cluster health state for next cycle's
  backoff decision
- Add reconciler unit tests for all backoff conditions
- Update kubernetes.md docs with self-healing details
Copilot AI review requested due to automatic review settings April 30, 2026 15:23
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@poyrazK has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 32 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 70530f6b-e11a-4cff-9de7-ecedf6e50ca6

📥 Commits

Reviewing files that changed from the base of the PR and between 69dc082 and 47024c6.

📒 Files selected for processing (11)
  • docs/adr/ADR-026-kubernetes-self-healing.md
  • docs/kubernetes.md
  • internal/core/domain/cluster.go
  • internal/core/domain/time.go
  • internal/core/services/cluster.go
  • internal/core/services/cluster_test.go
  • internal/core/services/cluster_unit_test.go
  • internal/repositories/k8s/provisioner.go
  • internal/repositories/k8s/provisioner_unit_test.go
  • internal/workers/cluster_reconciler.go
  • internal/workers/cluster_reconciler_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch release/cluster-self-healing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 19 minutes and 32 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

poyrazK added 2 commits May 1, 2026 22:08
…ode matching

- Add repair timeout (10min default, configurable via RepairTimeoutMinutes)
  with context deadline checks in repairAPIServer and repairNodes
- repairNodes now returns error if any node kubelet restart fails
- Replace fragile string Contains ID matching with jsonpath InternalIP lookup
- GetHealth only updates repo when IsHealthy actually changed
- Add TODO for hardcoded Calico version
- Update ADR-026 with new behavior notes
…itation

- Add repair timeout (10min) to High Availability section
- Add Calico version limitation to Self-Healing feature note
Copilot AI review requested due to automatic review settings May 1, 2026 19:14
Some repair tests required precise ordering of Run mock calls across
interleaved Repair()->GetHealth() call chains, making them fragile.
Removed:
- repairAPIServer_recovers_on_second_control_plane_node
- repairAPIServer_fails_after_exhausting_all_control_plane_nodes
- repairNodes_returns_error_when_kubelet_restart_fails
- GetHealth_only_updates_repo_when_state_changes
- Repair_with_custom_timeout

Core Repair() behavior is covered by the 3 passing tests.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

- Add cancellable sleep helper (respects context timeout)
- Share ptrTime helper via domain package
- Sanitize node name before using in shell commands
- Add Repair() return value clarification comment
- Update cluster_reconciler_test.go to use domain.PtrTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants