Skip to content

feat(components): kubernetes helm sdk action runner and synchronous release actuation - #806

Merged
VLukiantsev merged 9 commits into
mainfrom
feat/components-helm-sdk-runner-b548435649
Sep 9, 2026
Merged

VLukiantsev merged 9 commits into
mainfrom
feat/components-helm-sdk-runner-b548435649

Conversation

@VLukiantsev

Copy link
Copy Markdown
Collaborator

Summary

Layer 3A of the XMC Components Reconciler stack (base: main).

Implements HelmActionRunner and SDKHelmActionRunner via the Helm Go SDK, enabling xmc_bridge to execute Helm release upgrades directly using in-cluster Kubernetes client credentials. This PR extracts the lower foundational runner layer from the live actuation subsystem to establish a minimal, fully-tested actuation driver.

Motivation & Context

Layer 2 (PR #735) introduced declarative ConfigMap persistence for component values. To translate persisted component configurations into live Kubernetes workloads, the bridge controller requires an execution engine that interfaces with Helm release storage. This PR introduces the Helm Go SDK action runner abstraction, dynamic chart resolution, and synchronous release upgrade execution wired to K8sHelmManager.

Key Changes

  • Helm Go SDK Action Runner (pkg/components/bridge/sdk_helm_action_runner.go):
    • Implements SDKHelmActionRunner wrapping helm.sh/helm/v3/pkg/action.Configuration.
    • Implements Upgrade and resolveChart with dynamic filesystem loading and fallback support.
    • Implements WithKubeconfig, WithChartPath, and WithActionRunner configuration options.
  • Manager Actuation Wiring (pkg/components/bridge/helm_manager.go):
    • Wires K8sHelmManager to execute synchronous release upgrades via HelmActionRunner on Ensure1PComponent.
  • Bridge CLI Integration (cmd/xmc_bridge/main.go):
    • Adds -chart-path flag and HELM_CHART_PATH environment variable support.
    • Initializes K8sHelmManager with the configured action runner and release parameters.
  • RBAC Configuration (deploy/helm/templates/components/rbac.yaml):
    • Adds permissions for Helm release secrets and ConfigMaps in target namespaces.
  • Comprehensive Testing (pkg/components/bridge/sdk_helm_action_runner_test.go, cmd/xmc_bridge/main_test.go):
    • Added unit tests for runner options, dynamic chart loading, and RWMutex concurrency safety.

Assumptions

  • Helm chart files are accessible at the configured chart path or synthesized with in-memory metadata when chart directories are omitted.
  • The controller ServiceAccount is granted RBAC permissions to manage Helm release secrets in the release namespace.

Sizing Exception Justification

  • Production Code: 413 lines (Threshold: 400 lines)
    • 56 lines (50% of the overage) reside in go.mod (external dependency declarations for helm.sh/helm/v3 and transitive dependencies). Pure Go production logic is ~357 lines, well within the 400-line limit.
  • Total Code: 735 lines (Well under the 1,000 lines threshold).

Verification & Testing

  • Bazel Unit Tests:
    bazel test //cmd/xmc_bridge/... //pkg/components/bridge/...
    bazel test --@io_bazel_rules_go//go/config:race //pkg/components/bridge:bridge_test //cmd/xmc_bridge:xmc_bridge_test
    All unit tests pass (2/2 test targets green, 0 race conditions).
  • Linters:
    Pre-commit hooks (buildifier, gofmt, golangci-lint, addlicense) passed cleanly.

Related Issues / Bugs

Part of b/548435797 / b/548435649

TAG=agy
CONV=fa5e1d3a-e399-45eb-a73c-ef8413122857

@VLukiantsev
VLukiantsev changed the base branch from main to feat/components-helm-configmap-persistence-b548435649 September 7, 2026 14:57

@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 integrates the Helm Go SDK into the XMC bridge to enable in-process Helm release upgrades, replacing CLI child processes. It introduces a new HelmActionRunner interface, an SDKHelmActionRunner implementation, and updates K8sHelmManager to trigger synchronous release upgrades serialized by a mutex during component lifecycle operations. Additionally, configuration flags, RBAC permissions, and dependencies are updated to support this integration. The review feedback highlights a documentation mismatch in the README regarding an asynchronous queue versus the synchronous mutex implementation, and points out fragile initialization logic in the functional options pattern of NewK8sHelmManager due to option ordering dependencies.

Comment thread pkg/components/bridge/README.md Resolved
Comment thread pkg/components/bridge/helm_manager.go Resolved
@VLukiantsev
VLukiantsev changed the base branch from feat/components-helm-configmap-persistence-b548435649 to main September 7, 2026 15:03
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

@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 integrates the Helm Go SDK into the XMC bridge component manager to enable in-process Helm release upgrades without relying on external CLI child processes. It introduces the SDKHelmActionRunner and updates K8sHelmManager to trigger synchronous upgrades during component lifecycle operations. The review feedback highlights two critical issues: a race condition in triggerUpgrade due to loading component values outside of the upgradeMu lock, and a declarative state violation caused by setting upgrade.ReuseValues = true in the Helm action runner, which prevents deleted component values from being removed in live deployments.

Comment thread pkg/components/bridge/helm_manager.go Resolved
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

@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 integrates the Helm Go SDK directly into the component controller to perform in-process Helm release upgrades. It introduces the HelmActionRunner interface and its concrete implementation SDKHelmActionRunner, updates K8sHelmManager to trigger synchronous upgrades during component lifecycle operations, and adds comprehensive unit tests. The review feedback highlights two key areas for improvement: first, logging a warning when the HelmActionRunner is uninitialized to prevent silent actuation failures, and second, utilizing a context-aware lock (such as semaphore.Weighted) instead of sync.Mutex to ensure immediate responsiveness to context cancellation during concurrent upgrades.

Comment thread pkg/components/bridge/helm_manager.go Resolved
Comment thread pkg/components/bridge/helm_manager.go Resolved
@VLukiantsev
VLukiantsev marked this pull request as ready for review September 8, 2026 07:18
@VLukiantsev
VLukiantsev force-pushed the feat/components-helm-sdk-runner-b548435649 branch 2 times, most recently from e3d37cd to 1e8454e Compare September 8, 2026 15:04

@andrzejfudro andrzejfudro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I feel like there is a gap with the approach we take with the helm upgrade and chart path. Feel free to push back on my comment if I got something wrong, I lack deep understanding in that area and I only briefly checked the design doc.

Comment thread cmd/xmc_bridge/main.go Resolved
Comment thread pkg/components/bridge/helm_manager.go Resolved
Comment thread pkg/components/bridge/helm_manager.go Resolved
Comment thread pkg/components/bridge/helm_manager.go Resolved
Comment thread pkg/components/bridge/helm_manager.go Resolved
…elease actuation

Implement SDKHelmActionRunner using the Helm Go SDK action engine to actuate
1P component releases synchronously directly from K8sHelmManager.

- Abstract Helm release upgrades behind HelmActionRunner interface.
- Implement SDKHelmActionRunner with action.NewUpgrade, dynamic values loading,
  and chart resolution caching.
- Wire release actuation flags (--release-name, --chart-path) into cmd/xmc_bridge.
- Provide comprehensive unit tests with test doubles for synchronous upgrade flows.

TAG=agy
CONV=fa5e1d3a-e399-45eb-a73c-ef8413122857
Extract SDKHelmActionRunner and its options into dedicated sdk_helm_action_runner.go
and sdk_helm_action_runner_test.go files to improve SRP, modularity, and review
diff discoverability.

TAG=agy
CONV=fa5e1d3a-e399-45eb-a73c-ef8413122857
- Clarify README documentation to specify synchronous upgrade serialization via mutex rather than asynchronous queue in Layer 3A.
- Refactor NewK8sHelmManager functional options to decouple configuration from runner instantiation, guaranteeing option order independence and eliminating post-hoc chartPath mutation.
- Add unit tests verifying option order independence, precedence, and chart path propagation.

Comments:
- #806 (comment)
- #806 (comment)

TAG=agy
CONV=fa5e1d3a-e399-45eb-a73c-ef8413122857
…reuseValues

- Acquire upgradeMu before reading ConfigMap in triggerUpgrade to prevent lost-update race conditions under concurrent reconciliation.
- Omit upgrade.ReuseValues = true in SDKHelmActionRunner to enforce declarative state synchronization on component deletion/purging.

Comments:
- #806 (comment)
- #806 (comment)

TAG=agy
CONV=fa5e1d3a-e399-45eb-a73c-ef8413122857
…aware upgrade lock

- Emit warning log in triggerUpgrade when HelmActionRunner is uninitialized rather than silently skipping actuation.
- Implement context-aware lock acquisition on K8sHelmManager (upgradeSem) to abort immediately upon context cancellation or timeout.
- Add companion unit tests verifying defensive uninitialized runner logging and context-aware lock acquisition behavior.

TAG=agy
CONV=fa5e1d3a-e399-45eb-a73c-ef8413122857
… namespace, releaseName, and runner

- Enforce non-empty ref.Namespace in validateAndResolve and IsComponentActive, eliminating silent resolveNamespace fallback to "xmc".
- Require non-empty releaseName in triggerUpgrade, preventing unconfigured release collisions with cluster-level Helm deployments.
- Return explicit error in triggerUpgrade when HelmActionRunner is uninitialized rather than silently skipping execution.
- Require cms-address, namespace, and release-name flags or environment variables in ParseConfig, preventing unconfigured pod startup loops.

TAG=agy
CONV=fa5e1d3a-e399-45eb-a73c-ef8413122857
… to sdk runner base

Add Uninstall method to HelmActionRunner and SDKHelmActionRunner using action.NewUninstall.
Define ComponentReleaseName (xmc-cmp-<name>) and decouple 1P component releases at the base layer.
Update Delete1PComponent and Purge1PComponent to execute runner.Uninstall with acquireUpgradeLock.
Delete obsolete monolithic loadAllComponentValues logic.

TAG=agy
CONV=fa5e1d3a-e399-45eb-a73c-ef8413122857
@VLukiantsev
VLukiantsev force-pushed the feat/components-helm-sdk-runner-b548435649 branch from 1e8454e to 78e5078 Compare September 8, 2026 17:20
…efer and pass chart path

- Extract uninstallRelease helper in K8sHelmManager to deduplicate release uninstallation logic across Delete1PComponent and Purge1PComponent.
- Guard uninstallRelease with deferred upgrade lock release, preventing deadlocks if Helm runner uninstallation panics.
- Log warning and gracefully return nil when runner is uninitialized during release uninstallation.
- Remove dead-code upgradeErrs map and GetUpgradeError from PR #806, shifting error query tracking down to PR #579 where actuation status is queried.
- Inject HELM_CHART_PATH into deploy/helm/templates/components/configmap.yaml from values.componentsDeployment.chartPath.
- Add unit tests verifying uninitialized runner warning behavior and panic-safe lock deferral.

TAG=agy
CONV=fa5e1d3a-e399-45eb-a73c-ef8413122857
@VLukiantsev VLukiantsev added the priority::2-high top of mind. should not wait. label Sep 9, 2026

@andrzejfudro andrzejfudro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Answered in the threads.

… TODO, and declare chartPath in values

Address reviewer feedback on PR #806:
- Remove unused upgradeMu mutex from K8sHelmManager (superseded by upgradeSem channel semaphore).
- Document dynamic per-component chart path resolution TODO comment in cmd/xmc_bridge/main.go and pkg/components/bridge/helm_manager.go.
- Explicitly declare chartPath in deploy/helm/values.yaml and update README documentation.

TAG=agy
CONV=fa5e1d3a-e399-45eb-a73c-ef8413122857
@VLukiantsev
VLukiantsev added this pull request to the merge queue Sep 9, 2026
Merged via the queue into main with commit 4565dfb Sep 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority::2-high top of mind. should not wait.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants