Skip to content

Refactor Core::Controlplane (575 lines): resource-scoped managers + structured apply-result parsing #385

Description

@justin808

Summary

lib/core/controlplane.rb (575 lines, ~70 public methods) is the everything-wrapper for the cpln CLI: images, workloads, domains, volumesets, cron, logs, apply. Two specific pain points beyond sheer size:

  1. Regex-scraped apply results. parse_apply_result (#L449) carries three rubocop:disable Metrics/* and extracts created/updated resources by regex-matching cpln apply stdout. If Control Plane changes its output format, parsing silently returns an empty list — downstream code can't tell "nothing created" from "format changed".
  2. String-assembled commands. build_command (#L400-L443) mixes command construction, output-redirection suffixes, and temp-stderr bookkeeping in one method (see also Harden CLI command construction: resolve args_join quote-escaping TODO, prefer array-form subprocess args #381 for the argument-quoting side of this).

Proposed approach (slice per PR, behavior-preserving)

  1. Extract ApplyResultParser with its own unit spec built from captured real cpln apply outputs (fixtures). Emit a warning when the command succeeded but zero items parsed — that's the "format changed" tripwire.
  2. Check whether cpln apply (and other scraped commands) support structured output (--output json); prefer it where available and keep the regex parser as fallback.
  3. Split Controlplane incrementally into resource-scoped collaborators (e.g. image/workload/domain/volumeset managers) behind the existing facade so call sites migrate gradually. One resource family per PR.
  4. Extract command construction (build_command + redirection handling) into a small builder used by all managers — coordinate with Harden CLI command construction: resolve args_join quote-escaping TODO, prefer array-form subprocess args #381 rather than duplicating it.

Acceptance criteria

  • ApplyResultParser unit-tested against real captured outputs; zero-items-on-success warns
  • controlplane.rb reduced to a facade (or removed) with resource managers individually spec'd
  • rubocop:disable Metrics/* count reduced in touched files, not carried over
  • Full fast suite green in CI; at least one manual :slow/dispatch run before release since apply/deploy paths are load-bearing

Priority / size / dependencies

P3. Size: L (multiple PRs). Blocked by #380 (error paths raise, not exit) and #383 (retry/token changes touch the same seams). Coordinate with #381 on command building.


Origin: automated codebase health review, 2026-07-02, against 7c96df9.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low priority / cleanupenhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions