Skip to content

refactor: decompose KapeHandlerReconciler into focused files (#51) - #144

Merged
dzungtr merged 1 commit into
mainfrom
refactor/51-reconciler-decompose
Jul 19, 2026
Merged

dzungtr merged 1 commit into
mainfrom
refactor/51-reconciler-decompose

Conversation

@dzungtr

@dzungtr dzungtr commented Jun 7, 2026

Copy link
Copy Markdown
Owner

What

Pure internal refactor of operator/controller/reconcile/handler.go (was 541 lines, 14 functions) into purpose-named files. No behaviour change, no CRD changes.

Changes

  • Reconcile slimmed to 55 lines (was ~160). It now delegates each responsibility to an extracted step method: gateDependencies, gateScaling, reconcileWorkload (+ reconcileScaledObject), syncLabels, updateStatus.
  • handler_deps.go — resolvedDependencies struct + its EagerSkills/LazySkills methods, validateDependencies, and the unionToolMap/sortedToolsByName helpers. Fetch is split from validation via resolveSchema / resolveHandlerTool / resolveSkills. Dependency reason constants live here.
  • handler_hash.go — computeRolloutHash as a free function.
  • handler_conditions.go — buildHandlerConditions + computeReadyRollup.
  • Condition helpers replaced — removed findCond / isConditionTrue from production code; every call site now uses meta.FindStatusCondition / meta.IsStatusConditionTrue from k8s.io/apimachinery/pkg/api/meta (identical signatures, drop-in).
  • testhelpers_test.go — single home for the shared findCondition and fakeConfigLoader test helpers (previously declared in tool_test.go).

Verification

  • go build ./... — clean
  • go vet ./controller/reconcile/... — clean
  • go test ./operator/... — all green, no test assertions modified
  • golangci-lint run ./operator/controller/reconcile/... — no new errors (one pre-existing tool.go:174 errcheck on resp.Body.Close() is untouched, out of scope)
  • gofmt clean on all new/modified production files

Acceptance criteria

  • Reconcile body ≤ 80 lines (55)
  • handler_deps.go, handler_hash.go, handler_conditions.go exist
  • findCond/isConditionTrue removed; call sites use meta.*
  • Single findCondition declaration (no DuplicateDecl)
  • Existing operator tests pass unmodified
  • go test ./operator/... green
  • No new golangci-lint errors

Closes #51

🤖 Generated with Claude Code

Split the 541-line handler.go into purpose-named files and replace the
duplicated condition helpers with apimachinery stdlib equivalents. Pure
internal refactor — no behaviour change.

- Reconcile now delegates each responsibility (dependency gate, scaling
  gate, workload, label sync, status) to extracted step methods; body is
  55 lines (was ~160).
- handler_deps.go: resolvedDependencies + validateDependencies, with
  fetch/validation split into resolveSchema / resolveHandlerTool /
  resolveSkills. Reason constants live here.
- handler_hash.go: computeRolloutHash as a free function.
- handler_conditions.go: buildHandlerConditions + computeReadyRollup.
- Removed findCond / isConditionTrue from production code; all call sites
  use meta.FindStatusCondition / meta.IsStatusConditionTrue.
- testhelpers_test.go: single home for the shared findCondition and
  fakeConfigLoader test helpers (was declared in tool_test.go).

Closes #51

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dzungtr
dzungtr force-pushed the refactor/51-reconciler-decompose branch from c127c33 to 47fa06d Compare July 19, 2026 12:37
@dzungtr
dzungtr merged commit e37790a into main Jul 19, 2026
1 check passed
@dzungtr
dzungtr deleted the refactor/51-reconciler-decompose branch July 19, 2026 12:48
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.

refactor(operator): decompose KapeHandlerReconciler — complexity after Phase 6 slices 3-4

1 participant