Skip to content

refactor(bridge): move chart resolution and ConfigMap values out of helm_manager.go - #1067

Merged
VLukiantsev merged 4 commits into
mainfrom
refactor/helm-split-chart-values
Oct 6, 2026
Merged

VLukiantsev merged 4 commits into
mainfrom
refactor/helm-split-chart-values

Conversation

@VLukiantsev

@VLukiantsev VLukiantsev commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

First slice of splitting pkg/components/bridge/helm_manager.go (about 1,500 lines, several unrelated jobs) into files with one job each. This PR moves chart path resolution into chart_resolver.go and the per-component values ConfigMap code into component_values.go. It then merges the three copies of the ConfigMap read-modify-write loop into one.

Motivation & Context

K8sHelmManager mixed chart resolution, ConfigMap persistence, Helm execution, health and repair, and actuation state in one file, which made it hard to review and easy to break. The split is a stack of small PRs. The first commit of each PR is a pure move, and the second fixes duplication in the code it just moved.

Part 1 of 6 of the helm_manager.go split stack.

Key Changes

  • Commit 1 (pure move):
    • chart_resolver.go: ChartPathResolver, ResolveComponentChartPath and its path-safety checks, resolveChartPathForComponent, loadComponentChart.
    • component_values.go: the values ConfigMap name, the persist/disable/remove functions, setDisabledValues, extractComponentEnabledFromValuesJSON.
    • Matching tests move to chart_resolver_test.go and component_values_test.go.
    • mockHelmActionRunner moves to test_doubles_test.go, because reconciler_test.go uses it too.
  • Commit 2 (DRY):
    • persistComponentValues, disableComponentValues and removeComponentValues become one-line valuesMutations run by mutateComponentValues. That one function owns the RetryOnConflict Get/Create/Update loop, the no-op detection, and the only ConfigMap constructor.
    • componentValuesKey and componentValuesKeySuffix replace the scattered ".json" literals.
    • Removes nil-receiver guards that can never trigger.
    • Adds direct tests for every mutation path.

Assumptions

  • Behaviour doesn't change. The nil guards removed here can't trigger because every caller already checks the manager first. If that's wrong, a nil manager would panic instead of returning nil.

Verification & Testing

  • bazel test //pkg/components/bridge:bridge_test --test_output=errors --runs_per_test=3: passes.
  • bazel build //pkg/components/... //cmd/xmc_bridge/...: passes.
  • Pre-commit (buildifier, gofmt, golangci-lint including dupl, addlicense): passes.
  • Review commit 1 with git diff --color-moved=dimmed-zebra.

Related Issues / Bugs

N/A

TAG=agy
CONV=25ae2278-aa0f-44db-af8a-4f9deda0d399

@VLukiantsev
VLukiantsev added this pull request to stack #1073 October 5, 2026 10:48
@VLukiantsev VLukiantsev changed the title refactor/helm split chart values refactor(bridge): move chart resolution and ConfigMap values out of helm_manager.go Oct 5, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Helm manager implementation by extracting chart resolution and component values mutation logic into dedicated files (chart_resolver.go and component_values.go), along with their respective tests. It also moves the mock action runner to a shared test doubles file. Feedback on these changes highlights a potential nil pointer dereference panic in mutateComponentValues due to a missing nil receiver check, and a path traversal vulnerability in containsPathTraversal where Windows-style backslashes are not properly handled on Unix-like systems.

Comment thread pkg/components/bridge/chart_resolver.go Resolved
@VLukiantsev
VLukiantsev marked this pull request as ready for review October 6, 2026 09:38
@github-actions
github-actions Bot requested a review from pachopepe October 6, 2026 09:38
@VLukiantsev VLukiantsev added the priority::3-medium needs review. label Oct 6, 2026
pachopepe
pachopepe previously approved these changes Oct 6, 2026
@VLukiantsev
VLukiantsev force-pushed the refactor/helm-split-chart-values branch 2 times, most recently from 37078b0 to db8542e Compare October 6, 2026 15:00
…elm_manager.go

Pure move, no behaviour change. First slice of the helm_manager.go SRP split:

- chart_resolver.go: ChartPathResolver, ResolveComponentChartPath and its
  path-safety helpers, resolveChartPathForComponent, loadComponentChart.
- component_values.go: ComponentValuesConfigMapName, persist/disable/remove
  ComponentValues, setDisabledValues, extractComponentEnabledFromValuesJSON.
- Matching tests move to chart_resolver_test.go and component_values_test.go.
- mockHelmActionRunner moves to test_doubles_test.go (also used by
  reconciler_test.go).

TAG=agy
CONV=25ae2278-aa0f-44db-af8a-4f9deda0d399
persistComponentValues, disableComponentValues and removeComponentValues
each repeated the same RetryOnConflict Get/Create/Update loop and the
ConfigMap label literals. They are now one-line valuesMutation functions
applied by mutateComponentValues, which owns the retry loop, the no-op
detection, and the only ConfigMap constructor.

- componentValuesKey/componentValuesKeySuffix replace the ".json" literals,
  including in hydrateNamespaceFromConfigMap.
- Drops the unreachable nil-receiver guards (all callers check m first).
- Adds direct tests for every mutation path (create, overwrite, no-op,
  parameter-preserving disable, remove, missing ConfigMap, nil client).

No behaviour change.

TAG=agy
CONV=25ae2278-aa0f-44db-af8a-4f9deda0d399
…es creation

Add TestK8sHelmManager_ComponentValues_CreateAlreadyExistsRetriesAsUpdate
to verify that when createComponentValues races with a concurrent writer
and receives AlreadyExists, the error is translated to Conflict so
RetryOnConflict re-reads the existing ConfigMap, preserves other
components' keys, and re-applies the mutation onto the existing entry.

TAG=agy
CONV=25ae2278-aa0f-44db-af8a-4f9deda0d399
…t in chart_resolver

Replace the legacy xmanager_cloud/logging/logging alias with the
canonical xmanager_cloud/internal/logging import path to satisfy the
google3 legacy import ratchet check.

TAG=agy
CONV=25ae2278-aa0f-44db-af8a-4f9deda0d399
@VLukiantsev
VLukiantsev force-pushed the refactor/helm-split-chart-values branch from db8542e to be99c97 Compare October 6, 2026 15:01
@VLukiantsev
VLukiantsev requested a review from pachopepe October 6, 2026 15:06
@VLukiantsev
VLukiantsev added this pull request to the merge queue Oct 6, 2026
Merged via the queue into main with commit 8106a22 Oct 6, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority::3-medium needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants