Repository navigation
refactor(cmd): reduce cognitive complexity to <=15 in binary mains (part of #556) - #563
Merged
Merged
Conversation
…art of #556) Extract coherent setup phases from runAgent (51→≤15), runEdge (32→≤15), runRegistrar (58→≤15), and runController (19→≤15) into named helpers. Zero behavior change: extraction is structure-only, runnable registration order, flag defaults, log messages, and error wrapping are preserved verbatim. agent/internal/cmd: - setupSpireSource: opens SPIRE Workload API + resolves trust domain - configureSnapshotCache: cache flags + meshDNS via wireMeshDNS - wireSpireBridge: optional SPIRE bridge for SDS - wireGAMMA: GAMMA reconciler + scheme installs - wireAuthzAndConfigImport: authz-sidecar config + config importer - wireL4Routes: L4 route reconciler + scheme installs - wireCaptureReconciler: transparent-capture reconciler - deferLogShutdown / deferTelemetryShutdown: eliminates nested defer/if patterns - buildEdgeScheme: edge manager scheme (client-go + GW API + config.aether.io) - resolveEdgeIdentity: edge SPIRE source + trust domain + SVID - configureEdgeSnapshotCache: edge cache flags + proxy globals - wireGatewayAPIReconciler: Gateway API reconciler + TLS secret provider registrar/internal/cmd: - buildMCSScheme: MCS bootstrap scheme options - bootstrapManager: combines scheme build + manager.Bootstrap - wireServerCore: metrics + snapshot + broadcaster + syncer + mesh-svc generator - wireMCS: MCS controllers + config-export controller (proposal 026) - wireReplication: cross-region etcd replication (proposal 006) - buildSpireGRPCCreds: SPIRE mTLS gRPC credentials with lifetime-safe closer - wireGRPCServer: gRPC server assembly + write-behind + m.Start controller/internal/cmd: - buildControllerBootstrapOpts: scheme + SPIRE webhook opts - wireCABundleInjector: SPIRE CA bundle injector - deferControllerLogShutdown / deferControllerTelemetryShutdown: same pattern Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR
bpalermo
added a commit
that referenced
this pull request
Jul 19, 2026
The #556 campaign (PRs #558-#563) refactored all 65 production functions over 15. This flips the ratchet from 109 to the 15 target, scopes the aspect to go_library/go_binary (complexity-gating validated e2e and conformance test harnesses adds churn risk for no production value), and fixes the one offender the lane partition missed: RegistryRefresher.Start (23 -> extracted refreshLoop helpers, semantics byte-identical). Closes #556 Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR Co-authored-by: Claude Fable 5 <[email protected]>
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.
Summary
Extract coherent setup phases from the four binary main functions that exceeded the gocognit ≤15 threshold. Zero behavior change: runnable registration order, flag defaults, log messages, and error wrapping are all preserved verbatim.
Before → After
registrar/internal/cmd.runRegistraragent/internal/cmd.runAgentagent/internal/cmd.runEdgecontroller/internal/cmd.runControllerExtractions per package
agent/internal/cmd (root.go + edge.go):
setupSpireSource— opens SPIRE Workload API + resolves trust domainconfigureSnapshotCache— snapshot cache flags + meshDNS viawireMeshDNSwireMeshDNS— in-process DNS resolver setupwireSpireBridge— optional SPIRE bridge for SDSwireGAMMA— GAMMA reconciler + scheme installswireAuthzAndConfigImport— authz-sidecar config + config importerwireL4Routes— L4 route reconciler + scheme installswireCaptureReconciler— transparent-capture reconcilerdeferLogShutdown/deferTelemetryShutdown— eliminate nested defer/if patternsbuildEdgeScheme— edge manager scheme (client-go + GW API + config.aether.io)resolveEdgeIdentity— edge SPIRE source + trust domain + SVIDconfigureEdgeSnapshotCache— edge cache flags + proxy globalswireGatewayAPIReconciler— Gateway API reconciler + TLS secret providerregistrar/internal/cmd:
buildMCSScheme— MCS bootstrap scheme optionsbootstrapManager— combines scheme build + manager.BootstrapwireServerCore— metrics + snapshot + broadcaster + syncer + mesh-svc generatorwireMCS— MCS controllers + config-export controller (proposal 026)wireReplication— cross-region etcd replication (proposal 006)buildSpireGRPCCreds— SPIRE mTLS gRPC credentials with lifetime-safe closerwireGRPCServer— gRPC server assembly + write-behind + m.Startcontroller/internal/cmd:
buildControllerBootstrapOpts— scheme + SPIRE webhook optswireCABundleInjector— SPIRE CA bundle injectordeferControllerLogShutdown/deferControllerTelemetryShutdown— same patternTest plan
gocognit -over 15 agent/internal/cmd/ registrar/internal/cmd/ controller/internal/cmd/outputs nothing (exit 0)bazel test //agent/... //registrar/... //controller/...— 39/39 passmake gazelle— no BUILD.bazel changes neededmake format— code formattedPart of #556
🤖 Generated with Claude Code
https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR