Skip to content

feat(k8s): devops k8s volume move copies a local-path claim to a volume on another node and rebinds it, with argo cd paused and each step checked - #2199

Merged
dan-petty merged 1 commit into
mainfrom
feat/2186-volume-move
Oct 25, 2026
Merged

dan-petty merged 1 commit into
mainfrom
feat/2186-volume-move

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Summary

devops k8s volume move <namespace>/<claim> [--to-node <node>] [--plan] [--dry-run] [--context <ctx>] does the ten hand steps of k8s/README.md (Local-Path Volume Placement) as one command. The hand steps had two surprises in the #1634 moves (a dropped exec stream, and a last-applied annotation that made Argo CD refuse the sync), and the owner's own run failed at the first line because one placeholder broke the shell paste.

What the command does:

  • Plan (reads only). It reads the claim, its volume, the nodes, the pods that mount the claim (from the pod specs, not from labels), their Deployments or StatefulSets (ReplicaSet owner to Deployment), and the Argo CD Applications from the annotation argocd.argoproj.io/tracking-id on the claim and on each workload (the Loki claim comes from a claim template and has no annotation, but its StatefulSet has one). Without --to-node, it picks the worker node with the most node.fs.availableBytes from the kubelet's /stats/summary. It refuses a claim that is missing or not Bound, a claim that no pod mounts, a volume that is not local, a volume on a worker node when --to-node names no node, a target that does not exist or is a control-plane node or the node of the volume, a StatefulSet with whenScaled: Delete, a pod that no Deployment or StatefulSet owns, a tracked Application that does not exist, and the leftovers <claim>-src, <claim>-dst and <claim>-move. A refusal names every problem and changes nothing.
  • Run. Thirteen steps, each printed: pause bootstrap, cluster and the Application; make <claim>-move and <claim>-dst on the target node; scale to zero; start <claim>-src with the old claim read-only; copy with GNU tar over two kubectl exec streams joined by bash -o pipefail (one more time on an empty /dst when the stream stops); compare entries, files, bytes of regular files, a metadata digest and a content digest; set both volumes to Retain; delete the copy pods; save and delete the old claim (the point of no return); delete <claim>-move and reserve its volume for the claim name; make the claim again without the last-applied annotation and the volume controllers' annotations, then put the last-applied value back; scale back and make sure that the pods run on the target node; resume Argo CD in reverse order. The summary prints the new volume, the old volume and the command that deletes it.
  • Undo. Before the delete request of the old claim, a failure (an interrupt included) runs the undo of each change, the last first, and reports each undo that fails. Each undo is added before its request, because a request can fail after the API server made the change. From the delete request on, a failure resumes nothing: Argo CD stays paused, and the command prints the saved claim, the two volumes and the steps that did not run. k8s/README.md has a short "Finish a stopped move".
  • Dry run. --dry-run starts no process and prints the requests of a move, in order, with placeholders.
  • Every kubectl request goes through run_subprocess. The shared ProcessFake now records the input that run_subprocess sends as stdin; before, the body went into **kwargs and was lost.
  • The last-applied annotation name moves to CONST_K8S_LAST_APPLIED_ANNOTATION, which secret_push.py uses too.
  • k8s/README.md replaces the ten hand steps with the command, a list of what it does, the point of no return and the recovery steps. fix(k8s): the volumes of grafana, the prometheus server and loki move off the control-plane node, and their placement exemptions go #2147 runs the three moves with it; this pull request does not move a volume.

Tests: tests/test_k8s_volume_move.py (40 tests) runs on the shared process fake with a scripted cluster: the plan and its target, each refusal, a full move (the exact order of every request that changes the cluster), the claim body without the last-applied annotation and the annotate with the saved value, the copy pods and the copy pipe, a digest difference, an incomplete digest, a dropped copy that is retried once, a second dropped copy, an interrupt, a failed request and a failed undo before the point of no return, a failed create and a pod on the wrong node after it, the dry run, and the command output of each case. No test starts kubectl or bash. They fail on origin/main (the module does not exist; the fake test fails on its assertion), and they pass with env PATH=/usr/bin:/bin .venv/bin/python -m pytest.

Existing tool considered

pv-migrate v3.7.0 (2026-10-23) copies data from one existing claim to another with rsync over SSH. mount needs one pod with the two claims, which two local volumes on different nodes cannot have. clusterip, loadbalancer and nodeport go pod to pod, and since v3.7.0 it makes an allow-all NetworkPolicy for its own pods by default, which opens the perimeter of monitoring and logging during the copy. local tunnels through the workstation, the same path as the tar exec streams, with an sshd and an rsync image and a Helm release for each run, and a new binary on the workstation. It does not make the destination claim on a chosen node, scale the workloads, pause Argo CD, compare the two sides, or bind the original claim name to the new volume. So it would replace the copy step only. The command keeps GNU tar from debian:trixie-slim, as the #1634 moves did. Build cost: about 500,000 tokens and 2.5 hours to build with the tests; about 20,000 tokens a year to keep; about 50,000 tokens to fix when kubectl, local-path or Argo CD changes the behavior that it relies on.

--plan on the live cluster (read-only, 2026-10-24)

Node names are replaced with roles.

$ devops k8s volume move monitoring/grafana --plan
Plan of the move of claim monitoring/grafana. The plan only reads; it changed nothing.
Claim: Bound to volume pvc-c54a286c-66fe-4c27-97b7-c8c142991934 (5Gi, local-path) on node <control-plane-node>, reclaim policy Retain.
Target node: <worker-node-a>, 1.6 TB free.
Workloads that mount the claim: deployment/grafana (replicas: 1). Their pods: grafana-545489db84-ds9s6.
Argo CD Applications that track the claim or its workloads: grafana. The move pauses: bootstrap, cluster, grafana.
Steps:
  1. Pause automated sync of the Argo CD Applications bootstrap, cluster, grafana, from the top down.
  2. Create claim grafana-move (5Gi, local-path) and pod grafana-dst on node <worker-node-a>, and wait until the pod is Ready.
  3. Scale deployment/grafana to 0, and wait until these pods are gone: grafana-545489db84-ds9s6.
  4. Start pod grafana-src with claim grafana read-only on node <control-plane-node>, and wait until it is Ready.
  5. Copy /src of pod grafana-src to /dst of pod grafana-dst with GNU tar through the API server. If the stream stops, empty /dst and copy one more time.
  6. Compare the two sides: the entries, the files, the bytes of regular files, a metadata digest and a content digest. Stop at a difference.
  7. Set the reclaim policy of the new volume of claim grafana-move and of volume pvc-c54a286c-66fe-4c27-97b7-c8c142991934 to Retain.
  8. Delete the pods grafana-src and grafana-dst.
  9. Save claim monitoring/grafana and delete it. This is the point of no return.
 10. Delete claim grafana-move, and reserve its volume for claim monitoring/grafana.
 11. Create claim monitoring/grafana again from the saved claim, bound to the new volume, put back its last-applied configuration if it has one, and wait until it is Bound.
 12. Scale deployment/grafana to 1 again, wait until the pods are ready, and make sure that they run on node <worker-node-a>.
 13. Resume automated sync of the Argo CD Applications grafana, cluster, bootstrap.
Step 9 deletes the old claim. Before that step, a failure undoes the steps that ran. From that step on, a failure leaves Argo CD paused and names the saved claim, because a self-heal would make an empty claim.

$ devops k8s volume move monitoring/prometheus-server --plan
Plan of the move of claim monitoring/prometheus-server. The plan only reads; it changed nothing.
Claim: Bound to volume pvc-57243fd7-2c26-4084-b354-0e19c1865bc2 (20Gi, local-path) on node <control-plane-node>, reclaim policy Retain.
Target node: <worker-node-a>, 1.6 TB free.
Workloads that mount the claim: deployment/prometheus-server (replicas: 1). Their pods: prometheus-server-5c7884899d-488vh.
Argo CD Applications that track the claim or its workloads: prometheus. The move pauses: bootstrap, cluster, prometheus.
Steps:
  1. Pause automated sync of the Argo CD Applications bootstrap, cluster, prometheus, from the top down.
  2. Create claim prometheus-server-move (20Gi, local-path) and pod prometheus-server-dst on node <worker-node-a>, and wait until the pod is Ready.
  3. Scale deployment/prometheus-server to 0, and wait until these pods are gone: prometheus-server-5c7884899d-488vh.
  4. Start pod prometheus-server-src with claim prometheus-server read-only on node <control-plane-node>, and wait until it is Ready.
  5. Copy /src of pod prometheus-server-src to /dst of pod prometheus-server-dst with GNU tar through the API server. If the stream stops, empty /dst and copy one more time.
  6. Compare the two sides: the entries, the files, the bytes of regular files, a metadata digest and a content digest. Stop at a difference.
  7. Set the reclaim policy of the new volume of claim prometheus-server-move and of volume pvc-57243fd7-2c26-4084-b354-0e19c1865bc2 to Retain.
  8. Delete the pods prometheus-server-src and prometheus-server-dst.
  9. Save claim monitoring/prometheus-server and delete it. This is the point of no return.
 10. Delete claim prometheus-server-move, and reserve its volume for claim monitoring/prometheus-server.
 11. Create claim monitoring/prometheus-server again from the saved claim, bound to the new volume, put back its last-applied configuration if it has one, and wait until it is Bound.
 12. Scale deployment/prometheus-server to 1 again, wait until the pods are ready, and make sure that they run on node <worker-node-a>.
 13. Resume automated sync of the Argo CD Applications prometheus, cluster, bootstrap.
Step 9 deletes the old claim. Before that step, a failure undoes the steps that ran. From that step on, a failure leaves Argo CD paused and names the saved claim, because a self-heal would make an empty claim.

$ devops k8s volume move logging/storage-loki-0 --plan
Plan of the move of claim logging/storage-loki-0. The plan only reads; it changed nothing.
Claim: Bound to volume pvc-c810255f-025e-4e94-91fe-1a1a691bf79e (20Gi, local-path) on node <control-plane-node>, reclaim policy Retain.
Target node: <worker-node-a>, 1.6 TB free.
Workloads that mount the claim: statefulset/loki (replicas: 1). Their pods: loki-0.
Argo CD Applications that track the claim or its workloads: loki. The move pauses: bootstrap, cluster, loki.
Steps:
  1. Pause automated sync of the Argo CD Applications bootstrap, cluster, loki, from the top down.
  2. Create claim storage-loki-0-move (20Gi, local-path) and pod storage-loki-0-dst on node <worker-node-a>, and wait until the pod is Ready.
  3. Scale statefulset/loki to 0, and wait until these pods are gone: loki-0.
  4. Start pod storage-loki-0-src with claim storage-loki-0 read-only on node <control-plane-node>, and wait until it is Ready.
  5. Copy /src of pod storage-loki-0-src to /dst of pod storage-loki-0-dst with GNU tar through the API server. If the stream stops, empty /dst and copy one more time.
  6. Compare the two sides: the entries, the files, the bytes of regular files, a metadata digest and a content digest. Stop at a difference.
  7. Set the reclaim policy of the new volume of claim storage-loki-0-move and of volume pvc-c810255f-025e-4e94-91fe-1a1a691bf79e to Retain.
  8. Delete the pods storage-loki-0-src and storage-loki-0-dst.
  9. Save claim logging/storage-loki-0 and delete it. This is the point of no return.
 10. Delete claim storage-loki-0-move, and reserve its volume for claim logging/storage-loki-0.
 11. Create claim logging/storage-loki-0 again from the saved claim, bound to the new volume, put back its last-applied configuration if it has one, and wait until it is Bound.
 12. Scale statefulset/loki to 1 again, wait until the pods are ready, and make sure that they run on node <worker-node-a>.
 13. Resume automated sync of the Argo CD Applications loki, cluster, bootstrap.
Step 9 deletes the old claim. Before that step, a failure undoes the steps that ran. From that step on, a failure leaves Argo CD paused and names the saved claim, because a self-heal would make an empty claim.

Item

Closes #2186

Change: openspec/changes/archive/2026-10-24-2186-volume-move/

…me on another node and rebinds it, with argo cd paused and each step checked

`devops k8s volume move <namespace>/<claim>` does the ten hand steps of
k8s/README.md (Local-Path Volume Placement) as one command. The plan reads
the claim, its volume, the nodes, the pods that mount the claim, their
workloads and the Argo CD Applications that track them, picks the worker
node with the most free disk, and refuses a move that cannot run safely.

The run pauses Argo CD from the top down, copies with GNU tar over two
kubectl exec streams through the API server (one more time when the stream
stops), compares counts and digests of the two sides, binds the claim to the
new volume without the last-applied annotation and then puts it back, starts
the workloads on the target node and resumes Argo CD. Before the delete of
the old claim, a failure undoes each change. After it, a failure leaves
Argo CD paused and names the saved claim. --plan only reads; --dry-run makes
no request.

The shared process fake records the input that run_subprocess sends.
k8s/README.md replaces the hand steps with the command.
@dan-petty
dan-petty force-pushed the feat/2186-volume-move branch from 58eee91 to 566ebff Compare October 24, 2026 23:17
@dan-petty
dan-petty marked this pull request as ready for review October 24, 2026 23:24
@dan-petty
dan-petty merged commit 8efee07 into main Oct 25, 2026
17 checks passed
@dan-petty
dan-petty deleted the feat/2186-volume-move branch October 25, 2026 00:54
dan-petty pushed a commit that referenced this pull request Oct 25, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.5.0](v0.4.3...v0.5.0)
(2026-10-25)


### Features

* **config:** devops config unset removes a key, and an unknown key's
error names the line and that command
([#2207](#2207))
([217e05b](217e05b)),
closes [#2201](#2201)
* **k8s:** devops k8s volume move copies a local-path claim to a volume
on another node and rebinds it, with argo cd paused and each step
checked ([#2199](#2199))
([8efee07](8efee07)),
closes [#2186](#2186)


### Bug Fixes

* **review:** exclude deleted files and record scanner failures per file
([#1140](#1140))
([#2204](#2204))
([cdc5070](cdc5070))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(k8s): devops k8s volume move copies a local-path claim to a volume on another node and rebinds it, with argo cd paused and each step checked

1 participant