Daily Code QualityResearch and Plan #3192
Closed
Replies: 1 comment
-
|
This discussion was automatically closed because it expired on 2026-03-27T14:12:50.903Z.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This discussion captures the initial code quality research across three dimensions — refactoring, performance, and test coverage — for the KSail codebase. It serves as the living plan that the Daily Code Quality workflow will execute incrementally. Maintainers can comment here to guide or redirect the work.
Refactoring Landscape
File Size Diet (Files > 500 lines, excluding generated mocks)
pkg/cli/cmd/cluster/update.gopkg/cli/cmd/cluster/backup.gopkg/cli/setup/post_cni.gopkg/cli/cmd/cluster/restore.gopkg/cli/setup/components.gopkg/cli/cmd/cipher/edit.gopkg/client/flux/reconciler.gopkg/svc/provisioner/registry/mirror_specs.gopkg/cli/cmd/chat/chat.gopkg/cli/cmd/cluster/create.gopkg/cli/ui/chat/streamhandlers.gopkg/cli/ui/chat/keyhandlers.gopkg/fsutil/validator/ksail/validator.gopkg/client/docker/registry_container.gopkg/cli/setup/mirrorregistry/cleanup.gopkg/svc/provider/hetzner/provider.goTop Refactoring Targets
1.
pkg/cli/setup/— Zero test coverage + too many responsibilitiespost_cni.go(723 lines) mixes: cluster name resolution, component requirements, GitOps configuration, OCI artifact management, stability polling. Should be split into:post_cni_gitops.go—configureArgoCD,configureFlux,configureGitOpsResourcespost_cni_oci.go—ensureOCIArtifact,pushInitialOCIArtifactpost_cni_stability.go—waitForClusterStabilitycomponents.go(656 lines) is an installer registry; could break intocomponents_loadbalancer.go,components_cni.go, etc.2.
configureArgoCDvsconfigureFlux— Near-identical GitOps configurationconfigureGitOpsEnginehelper with a strategy/options struct would eliminate ~60 lines of duplication.3. CLI command switch/case sprawl
create.go,delete.go,list.go,update.go. A centralized provisioner-selector helper would reduce duplication.4.
pkg/svc/provisioner/cluster/talos/— Scope creeptalos/docker,talos/hetznerfor better cohesion.5. Long functions to extract
handleUpdateRunE(~72 lines): ExtractvalidateAndLoadConfig,computeUpdateStrategy,orchestrateChangesexecuteRecreateFlow(~60 lines): ExtractgetConfirmation,deleteCluster,recreateClusterpost_cni.go:installComponentsInPhases(~70 lines): Extract phase builders as named helpers6. Inconsistent error wrapping
return errinprovisioner_docker.go(lines 36, 64, 74, 80, 86) without context wrapping. All errors should usefmt.Errorf("operation: %w", err).Performance Landscape
Existing Benchmarks ✓
KSail has a solid benchmarking culture — 17 benchmark files already exist:
update_bench_test.go,configmanager_bench_test.go,registry_bench_test.go,diff_bench_test.go,marshal_bench_test.go, and more.Identified Performance Opportunities
1. Missing slice pre-allocation (low-hanging fruit)
post_cni.go:buildInfrastructureTasks()andbuildGitOpsTasks(): Append to un-sized slices. Switch tomake([]Task, 0, expectedCount).backup.go:filterExcludedTypes(): Result slice not pre-allocated; usemake([]string, 0, len(resourceTypes)).update.go:collectDiffRows(): Three separate appends without pre-allocation of total count.2. Sequential backup resource export (parallelization opportunity)
backup.go:exportResources()iterates resource types and namespaces sequentially. Per-namespace exports for independent resource types could use a bounded worker pool (e.g.,errgroupwith concurrency limit), potentially 2–4× faster for large clusters.3. Context-aware timeouts in blocking loops
vcluster/provisioner.go: D-Bus recovery loop usestime.Sleepwithout respecting context cancellation — if context is cancelled, the sleep still completes.provisioner_docker.go: Usesnetretry.ExponentialDelay()which is correct, but the loop does not checkctx.Done()between attempts.4. Benchmarks to add
backup.gofunctions (exportResources,sanitizeYAMLOutput) — no benchmarks yet.post_cni.goinstallation phase logic — complex conditional task building has no benchmark.restore.goYAML injection/splitting —splitYAMLDocuments,injectRestoreLabels.Test Coverage Landscape
Current Coverage State
Critical Coverage Gaps
🔴
pkg/cli/setup/— 0% test coverage (9 files, ~1,500+ lines)All files untested:
post_cni.go(723 lines) — GitOps configuration, OCI artifact management, stability pollingcomponents.go(656 lines) — installer factories, silent installer wrappersmirrorregistry/cleanup.go(517 lines)localregistry/*.go,mirrorregistry/*.goStrategy: Start with pure-logic functions using dependency injection. Functions like
ShouldPushOCIArtifact,GetComponentRequirements,NeedsMetricsServerInstall,NeedsLoadBalancerInstallare pure and easy to test. Use mocks for Docker/K8s calls.🔴
pkg/cli/cmd/cluster/restore.go— 676 lines, no test fileComplex tar extraction, YAML injection, label injection, and document splitting — all untested despite being critical data-recovery functionality.
splitYAMLDocuments,injectRestoreLabels,validateTarEntryare pure functions that can be unit tested without cluster access.🟡
pkg/svc/provisioner/cluster/talos/— Low test density (19 files, ~4 test files)Files without test coverage:
provisioner_docker.go(708 lines)provisioner_hetzner.go(326 lines)docker_bootstrap.go,hetzner_bootstrap.goscale_docker.go,scale_hetzner.gohetzner_cluster.go,hetzner_nodes.go🟡 Provisioner utility packages — No tests
pkg/svc/provisioner/cluster/clustererr/provider_op.gopkg/svc/provisioner/cluster/kind/factory.gopkg/svc/provisioner/cluster/multi.gopkg/svc/provisioner/registry/containerd.go,naming.go,network.go🟡 Toolgen packages — No tests
pkg/toolgen/consolidate/,constants/,definition/— auto-generates MCP/chat tools, should be testedCoverage priority order
restore.go— immediate value, no mocking neededsetup/post_cni.goandsetup/components.gotoolgen/packages — tool generation correctness is high-value to testHow to Control this Workflow
You can interact with this workflow by:
What Happens Next
.github/actions/daily-code-quality/build-steps/action.ymland.github/actions/daily-code-quality/coverage-steps/action.ymlare correct and up to date, then proceed directly to Phase 3 (since both files already exist in this repo).--repeat N, the workflow will automatically chain phases without requiring manual re-invocation.Beta Was this translation helpful? Give feedback.
All reactions