Skip to content

fix(k8s): delete a move volume bound after the undo #7452

Done

Description

@dan-petty

Problem

The undo of <claim>-move (#7416) reads the volume of the claim when it runs, sets it to Delete, and deletes the claim. A class with Immediate binding, such as longhorn, provisions the volume a moment after the create of the claim. When the move fails within that moment, the undo finds no spec.volumeName, deletes the claim, and the provisioner still makes the volume afterwards. That volume is Released with the class's reclaim policy Retain, so it stays.

Evidence of 2026-11-27 on the homelab: a move of devops/valkey-data-roadmap to longhorn failed at the create of <claim>-dst (Pod Security restricted, #7451), about 1 s after the create of valkey-data-roadmap-move. The undo printed its three steps, and afterwards a Released Longhorn volume with claimRef.name: valkey-data-roadmap-move stayed with Retain. A second attempt of the same move at another time left a second one. I deleted both by hand.

Change

The undo of <claim>-move also finds the volumes that the move claim gets after its delete: it keeps the uid of the claim, and after the delete it sets each PersistentVolume whose spec.claimRef.uid is that uid to Delete, waiting a short bound for a late provisioning. Or make_destination waits until <claim>-move is bound before it creates the pod, and the undo of a claim that never bound waits the same bound.

Acceptance criteria

  • A failing test first: an undo when the claim has no volume yet, and a volume with the claim's uid appears after the delete, sets that volume to Delete.
  • A live move to longhorn that fails at once leaves no Released volume of the move.
  • devops ci checks pass.

Related: #7416, #7382.

Alternatives check of 2026-11-27: in-use.
The repository already uses this tool.
Tool: kyverno/kyverno (https://github.com/kyverno/kyverno), Apache-2.0, last activity 2026-11-27, maintained.
Reason: Searches found only cluster-wide janitors: Kyverno's cleanup and mutate policies can find and patch PersistentVolumes by condition, which covers stray Released volumes, but no tool performs the uid-scoped cleanup inside the move undo.

Covers:

  • ClusterCleanupPolicy deletes resources that match a condition on a schedule
  • Mutate policies patch fields of resources, including reclaim policy
  • Runs in the cluster, with no change to the CLI code

Lacks:

  • No capture of the claim uid before the delete
  • No short wait for a volume provisioned after the delete
  • Cluster-wide and scheduled, not scoped to one move's undo

Proposed design

Problem statement

The undo of <claim>-move reads the volume of the move claim before it deletes the claim. A class with Immediate binding can provision a volume after that delete. The volume then stays Released with reclaim policy Retain.

Acceptance criteria

Requirement: Late volume cleanup

The undo of <claim>-move SHALL set the reclaim policy of each PersistentVolume whose spec.claimRef.uid is the move claim UID to Delete after it deletes the claim.

Scenario: Volume appears after the delete

  • WHEN A test in tests/k8s/test_k8s_volume_move.py runs the undo with a fake client, the move claim has no spec.volumeName, and a PersistentVolume with the move claim UID appears after the delete.
  • THEN The test asserts that the undo patches spec.persistentVolumeReclaimPolicy of that PersistentVolume to Delete.

Requirement: Bounded wait for late volume

The undo SHALL wait for a late PersistentVolume within a bounded time after it deletes the move claim.

Scenario: Late volume within the wait

  • WHEN A test in tests/k8s/test_k8s_volume_move.py runs the undo with a fake client that returns no PersistentVolume for the move claim UID on the first read and one on a later read within the wait.
  • THEN The test asserts that the undo patches that PersistentVolume to Delete before it returns.

Requirement: Bound volume cleanup

The undo SHALL set the reclaim policy of the volume in spec.volumeName to Delete before it deletes the move claim.

Scenario: Move claim has a bound volume

  • WHEN A test in tests/k8s/test_k8s_volume_move.py runs the undo with a move claim whose spec.volumeName names a PersistentVolume.
  • THEN The test asserts that the undo patches that PersistentVolume to Delete and deletes the move claim.

Requirement: CI checks pass

The change SHALL pass the repository CI checks.

Scenario: Repository CI

  • WHEN A person runs uv run devops ci on the branch.
  • THEN The command exits 0.

Requirement: Pending a person after the merge

A live move to longhorn that fails at once MUST leave no Released volume of the move.

Scenario: Live move failure

  • WHEN After the merge, a person runs a move of a claim to longhorn and the move fails at once.
  • THEN The command kubectl get pv -o json shows no PersistentVolume with phase Released and spec.claimRef.name equal to <claim>-move.

Existing Tool Considered

The alternatives check in the issue body records the verdict in-use for kyverno/kyverno (https://github.com/kyverno/kyverno). The repository already uses this tool. The block gives what the tool covers and lacks. This change adds the uid capture, the short wait and the move scope to the existing undo.

Key questions

  • Which cleanup approach should the undo of <claim>-move use?: Capture the move claim UID before the delete. After the delete, wait a bounded time and set each PersistentVolume whose spec.claimRef.uid is that UID to Delete. (best practice) [sources: k8s/README.md:122, src/devops_cli/k8s/volume_move.py:1119, docs/commands/k8s.md:1058, tests/k8s/test_k8s_volume_move.py]
    • Chosen: UID-scoped cleanup after the delete. It covers a volume that the class provisions after the delete. It does not depend on the copy tool.
    • Rejected: Wait for <claim>-move to bind before pod creation. It narrows the window. It still needs a wait in the undo for a claim that never bound.
    • Rejected: Kyverno cluster cleanup policy. It is cluster-wide and scheduled. It does not capture the claim UID or wait inside the undo.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    scope/k8s
    source/agent
    status/new
    value/medium
    priority/p2-medium
    effort/medium
    on Nov 27, 2026
  2. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (10)

    Tools considered:

    Searches run:

    • kubernetes cleanup orphaned released persistent volumes reclaim policy retain tool, results: 5
    • kube-janitor delete persistent volume claimRef uid, results: 5
    • k8s-cleaner delete released persistent volumes unused resources govauxlabs, results: 5
    • Kyverno CleanupPolicy delete PersistentVolume Released claimRef condition, results: 5
    • kubernetes operator removes Released persistent volumes with Retain reclaim policy github, results: 5
    • "persistent volumes" orphaned cleanup tool kubernetes cluster storage operator, results: 5
    • kube-janitor persistent volume ttl, results: 5
    • k8s-cleaner, results: 5
    • kyverno cleanup controller github repository, results: 5
    • longhorn orphaned volume released claimRef retain cleanup, results: 5

    Sources:

  3. dan-petty commented on Nov 28, 2026

    @dan-petty
    OwnerAuthor

    Replacement check for #7498 (PR #7518, which replaces the volume move copy with pv-migrate): not fixed.

    The undo of <claim>-move is the same code (_discard_move_claim): it reads spec.volumeName when it runs, sets that volume to Delete and deletes the claim. The move still creates <claim>-move before the scale to zero and the copy, so a failure a moment after the create, before a class with Immediate binding has provisioned the volume, can still leave a Released volume with Retain. The window is smaller: the first step after the create is now the scale to zero, and pv-migrate starts only after the pods are gone, so the failure of #7451 at the create of <claim>-dst cannot happen. The fix of this issue (the uid of the claim and spec.claimRef.uid of a late volume) does not depend on the copy tool, so the issue stays open.

  4. added
    status/ready
    and removed
    status/new
    on Nov 28, 2026
  5. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  6. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  7. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  8. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 23:51 UTC

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

    effort/mediumpriority/p2-mediumscope/k8ssource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions