Skip to content

fix(k8s): wait for running Argo CD syncs in a volume move #7464

Done

Description

@dan-petty

Problem

devops k8s volume move pauses Argo CD by setting spec.syncPolicy.automated.enabled: false on each Application. A sync operation that already runs (for example the retry of an automated sync that failed on the immutable class of the claim, after a merge of the class change) goes on after the pause. When the move deletes the old claim (step 9), that operation can make the claim again from git, with a new empty volume, before the move binds the claim name to the new volume (steps 10-11). The create of step 11 then fails with AlreadyExists, and the same operation can scale the workload up on the empty volume.

Evidence of 2026-11-27 on the homelab (Gitea, dan-petty/homelab#472): Application gitea had a sync operation from 19:47:53 to 19:48:27 UTC (2 retries) that went on after automated.enabled: false; at 19:48:27 it made gitea/gitea-shared-storage from git, bound to a new empty Longhorn volume, and set the Deployment back to 1 replica, so a Gitea pod started its init containers on the empty volume. I scaled it to 0 within 30 s, deleted the claim, bound the name to the volume of the copy, and Gitea came back on its own data. In that case the sync started while my script had resumed Argo CD by mistake after the stranded move; the same race exists whenever an operation of a paused Application still runs.

Change

After the pause, the run waits until no Application that it paused has a running operation (status.operationState.phase Running), with a bound; it refuses to go on, and undoes the pause, when one still runs at the bound. It checks again right before the delete of the old claim.

Acceptance criteria

  • A failing test first: with a running operation on a paused Application, the run waits, and does not send the delete of the old claim while the operation runs.
  • devops ci checks pass.

Related: #7382, #7431, dan-petty/homelab#472.

Proposed design

Problem statement

Wait for each running Argo CD sync before the old claim delete. The volume move pauses Argo CD but does not wait for running sync operations. A running sync can recreate the old claim from git after the delete and before the new volume binds. The change makes the move wait, stop at a bound, and restore the pause.

Acceptance criteria

Requirement: Wait for a running sync after pause

The volume move SHALL wait until each paused Argo CD Application has no running sync operation before it deletes the old claim.

Scenario: Running sync blocks the old claim delete

  • WHEN A paused Application reports status.operationState.phase: Running and the run reaches the delete of the old claim.
  • THEN The fake Kubernetes API shows no delete request for the old claim until the fake changes the phase to Succeeded.

Requirement: Restore pause at the wait bound

The run SHALL restore spec.syncPolicy.automated.enabled: true and exit nonzero when a paused Application still runs a sync operation at the wait bound.

Scenario: Wait bound expires with a running sync

  • WHEN The wait bound expires while a paused Application reports status.operationState.phase: Running.
  • THEN The command sets spec.syncPolicy.automated.enabled to true on each Application it paused and exits with a nonzero status.

Requirement: Recheck before old claim delete

The run MUST check for a running sync operation immediately before it deletes the old claim.

Scenario: Late sync starts before the old claim delete

  • WHEN A paused Application starts a sync operation after the first wait and before the delete of the old claim.
  • THEN The run waits for that operation to end and sends no delete request while status.operationState.phase is Running.

Requirement: Keep the pause until the move ends

The run SHALL keep spec.syncPolicy.automated.enabled: false on each paused Application until the move completes or fails.

Scenario: Clean wait keeps the pause

  • WHEN Every paused Application has no running sync operation and the move continues.
  • THEN The fake Kubernetes API shows spec.syncPolicy.automated.enabled remains false until the move reaches its resume step.

Requirement: Pass repository checks

The change SHALL pass the repository checks.

Scenario: CI check

  • WHEN The implementation is complete.
  • THEN uv run devops ci exits 0 and reports no failed check.

Existing Tool Considered

No alternatives check has run. No open, maintained tool covers the whole need. argocd app wait waits for one Application but needs the Argo CD CLI and does not restore automated.enabled. The change builds the wait in the command at a written cost of about 8,000 tokens and 6 hours to build, keep and fix.

Key questions

  • Which Argo CD Application field shows a running sync operation?: The field status.operationState.phase shows it. The value Running means the operation still runs. [sources: tests/k8s/test_k8s_volume_move.py]
  • How should the run wait for a running sync operation to end?: Poll the Application status at a short interval with the existing Kubernetes client, under a 10-minute bound. Do not add a watch or call the Argo CD CLI. (best practice) [sources: tests/k8s/test_k8s_volume_move.py, src/devops_cli/k8s/informer.py]
    • Chosen: Poll with a bound. The wait is short, the command already reads Applications, and a bound stops a stuck operation.
    • Rejected: Kubernetes watch. A watch adds lifecycle code and no safety for a bounded wait.
    • Rejected: Call argocd app wait. It adds the Argo CD CLI as a dependency and still does not restore the pause.
  • What should the run do when the wait bound expires?: Restore spec.syncPolicy.automated.enabled: true on every Application it paused and exit nonzero. Do not delete the old claim. (best practice) [sources: tests/k8s/test_k8s_volume_move.py]
    • Chosen: Restore the pause and stop. A running sync can recreate the claim, so the move must not continue.
    • Rejected: Continue with a warning. It keeps the race that the issue reports.
    • Rejected: Leave the pause and stop. It leaves Argo CD paused and needs a person to repair it.
  • Should the run check again immediately before the old claim delete?: Yes. Re-read the paused Applications and wait again if any has a running operation. (best practice) [sources: tests/k8s/test_k8s_volume_move.py]
    • Chosen: Recheck before the delete. A sync can start after the first wait, and the delete is the risky step.
    • Rejected: Rely on the first wait. It leaves the race between the wait and the delete.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    scope/k8s
    source/agent
    on Nov 27, 2026
  2. dan-petty commented on Nov 27, 2026

    @dan-petty
    OwnerAuthor
    • Priority: A running sync can recreate the claim on an empty volume and start a workload there, which is a data-loss race that already caused an incident.
  3. added
    status/new
    effort/medium
    value/high
    priority/p1-high
    owner/agent
    status/in-progress
    and removed
    status/new
    on Nov 27, 2026
  4. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

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

    @devops-cli-service
    Contributor

    Live since 2026-11-27 22:58 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/p1-highscope/k8ssource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions