Skip to content

fix(k8s): deploy-stack decides helm recovery from helm's json status and adopts existing resources with --take-ownership #1438

Closed

Description

@dan-petty

Problem

Lines cited at 05e9388 (release/v0.2.29).

  • Stuck releases are found by stderr text.
    • _recover_stuck_helm_release_if_pending (commands/k8s/stack_lifecycle.py:208-246) runs only when Helm's stderr contains "another operation" (:212).
    • It then deletes the release's storage Secret sh.helm.release.v1.<release>.v<N> with kubectl (:226-242). That assumes Helm's Secret storage driver, and it discards the pending revision rather than rolling back.
  • Resources are adopted by parsing error text.
    • _adopt_helm_resource_if_conflict (:249-300) runs when stderr contains "invalid ownership metadata" or "cannot be imported" (:258-262).
    • It extracts kind, name and namespace with a regex over Helm's message (CONST_HELM_OWNERSHIP_CONFLICT_RE, config/constants.py:2273-2275).
    • It then labels and annotates each resource with kubectl.
  • Both depend on the wording of Helm's human error text, which can change between releases. The code already branches on the Helm major version (_is_helm_v4_or_newer, :489).

Proposed remedy

  • Before helm upgrade --install, read helm status -o json. No stderr is inspected.
    • A pending-install release is uninstalled.
    • A pending-upgrade or pending-rollback release is rolled back with helm rollback <release> to its previous revision.
  • Pass --take-ownership (Helm 3.17 and later, and Helm 4) so Helm adopts existing resources itself. Delete the regex, the constant and the kubectl label/annotate loop.
  • Check the Helm version once: require 3.17 or later, with an error naming the installed version.

Acceptance criteria

  • rg -n 'another operation|invalid ownership metadata|cannot be imported|CONST_HELM_OWNERSHIP_CONFLICT_RE' src prints nothing.
  • When the process fake answers helm status -o json with pending-upgrade, deploy-stack runs helm rollback <release> before the upgrade.
  • When the process fake answers with pending-install, deploy-stack runs helm uninstall.
  • Every helm upgrade --install argv carries --take-ownership.
  • Helm 3.16 fails with the version error.
  • Tests run offline with fakes only at process and HTTP edges; each new test runs under 1 s.
  • uv run devops ci passes.

Related: #775, #1323, #1104.

Found by the 2026-10-08 client-library audit.

Opened as a borrow (#1153, budget/borrowed): the agent filing quota is spent for this cycle, and this is a defect or security finding of the owner-requested 2026-10-08 client-library audit.

Activity

  1. added
    type/bug
    scope/k8s
    source/agent
    on Oct 8, 2026
  2. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Priority: P2-Medium. The code works today but will silently break when Helm changes its human-readable error strings; it is a fragility fix, not an active outage.
    • Value: Medium. Users on any future Helm 3.x or 4.x release that rewords its errors will hit unhandled stuck-release or ownership-conflict failures.
    • Effort: Medium. Requires rewriting two helper functions, adding a version gate, removing a constant and regex, and updating the process-fake test suite, but the scope is well-bounded to one file and its tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope/k8ssource/agenttype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions