Skip to content

fix(k8s): handle grace timeout and baseline PSA in volume move #7843

Done

Description

@dan-petty

Problem Description

Moving a claim in an Argo CD-managed restricted namespace with a long-draining workload (deployment/roadmap-service, terminationGracePeriodSeconds: 660) and 0600 files owned by UID 1000 hits two defects in devops k8s volume move:

  1. stop_workloads() wait times out before terminationGracePeriodSeconds finishes: stop_workloads() waits DEFAULT_K8S_VOLUME_MOVE_WAIT_SECONDS (300 seconds) in kubectl wait pod/<pod> --for=delete, ignoring the pod's configured terminationGracePeriodSeconds (660 seconds for roadmap-service while draining rounds in flight).
  2. Argo CD selfHeal reverts an owner-approved baseline PSA window before Step 1 pauses Argo CD: Labeling pod-security.kubernetes.io/enforce=baseline before calling devops k8s volume move is reverted back to restricted by Argo CD (bootstrap / cluster selfHeal: true) while volume move starts up and calls _enforces_restricted() in plan_volume_move() prior to Step 1 (pause()). Under restricted, pv-migrate --non-root runs rsync as UID 10000 and exits 23 (partial transfer due to error) on 0600 (1000:1000) files created by the workload.

Reproduction Steps

  1. Run kubectl label ns devops pod-security.kubernetes.io/enforce=baseline --overwrite
  2. Run uv run devops k8s volume move devops/roadmap-service-home --storage-class longhorn --access-mode ReadWriteMany --size 10Gi

Expected vs Actual Behavior

  • Expected: volume move waits long enough for workloads with terminationGracePeriodSeconds > 270 to terminate gracefully (Step 3), and an opt-in operator --allow-baseline window applies pod-security.kubernetes.io/enforce=baseline only after Step 1 pauses Argo CD and restores restricted before Step 11 resumes Argo CD (and on undo).
  • Actual: Argo CD reverts enforce=baseline back to restricted before Step 1, _enforces_restricted() picks --non-root (rsync exits 23 on 0600 files), and Step 3 times out after 300s (5m 4s) on pod/roadmap-service-* (terminationGracePeriodSeconds: 660).

Environment Diagnostics

  • DevOps CLI Version: v0.257.0
  • Python Version: 3.14.10
  • OS & Architecture: Linux x86_64
  • Execution Environment: DevContainer

Related

Proposed design

Problem statement

devops k8s volume move fails on a long-draining workload in an Argo CD-managed restricted namespace. stop_workloads() waits 300 seconds and times out before a pod with terminationGracePeriodSeconds: 660 ends. Argo CD selfHeal also reverts a hand-set pod-security.kubernetes.io/enforce=baseline label before Step 1 pauses Argo CD. pv-migrate --non-root then runs as UID 10000 and exits 23 on 0600 files owned by UID 1000. The command must derive the wait from the pod grace period. It must also offer an opt-in baseline window that applies after the pause and restores the label before the resume and on undo.

Acceptance criteria

Requirement: grace-aware stop timeout

The stop step MUST wait for pod deletion with a timeout of at least the largest spec.terminationGracePeriodSeconds among the deleted pods plus a fixed margin.

Scenario: a pod with a 660 second grace period

  • WHEN stop_workloads() deletes a pod whose spec.terminationGracePeriodSeconds is 660
  • THEN the recorded kubectl wait pod/<pod> --for=delete request has --timeout of at least 720s

Requirement: default wait floor

The stop step SHALL use DEFAULT_K8S_VOLUME_MOVE_WAIT_SECONDS as the floor of the wait timeout.

Scenario: a pod with no grace period

  • WHEN a deleted pod sets no spec.terminationGracePeriodSeconds
  • THEN the recorded kubectl wait request has --timeout=300s

Requirement: opt-in baseline flag

devops k8s volume move SHALL accept an opt-in --allow-baseline flag and MUST change no pod security label without it.

Scenario: a run without the flag

  • WHEN the operator runs volume move with no --allow-baseline
  • THEN the command sends no kubectl label request for pod-security.kubernetes.io/enforce

Requirement: baseline applied after the Argo CD pause

With --allow-baseline, the command SHALL apply pod-security.kubernetes.io/enforce=baseline only after Step 1 pauses Argo CD.

Scenario: a run with the flag

  • WHEN the operator runs volume move --allow-baseline
  • THEN the recorded request order shows the Argo CD pause before the kubectl label request that sets enforce=baseline

Requirement: plan skips non-root with the flag

plan_volume_move() SHALL not add --non-root to the pv-migrate arguments when the operator sets --allow-baseline.

Scenario: a restricted namespace with the flag

  • WHEN the namespace enforces restricted and the operator sets --allow-baseline
  • THEN the recorded pv-migrate arguments contain no --non-root

Requirement: baseline window restore

The command SHALL restore the recorded pod-security.kubernetes.io/enforce value before Step 11 resumes Argo CD and on undo.

Scenario: the end of a flagged run

  • WHEN a run with --allow-baseline reaches Step 11 or runs undo
  • THEN the recorded request order shows the kubectl label restore before the Argo CD resume

Requirement: help names the flag

The volume move help text SHALL name --allow-baseline and its effect.

Scenario: the rendered help

  • WHEN the test renders the volume move help
  • THEN the help text contains --allow-baseline and baseline

Existing Tool Considered

No alternatives check has run. pv-migrate (open and maintained) covers the data copy, and the command already uses it. It lacks the Argo CD pause, the grace-aware wait and the PSA window, so the change edits src/devops_cli/k8s/volume_move.py instead. The written cost is about 30,000 tokens and 4 hours to build, keep and fix that code.

Key questions

  • Which timeout does stop_workloads() give kubectl wait now?: It gives DEFAULT_K8S_VOLUME_MOVE_WAIT_SECONDS, which is 300 seconds, so a pod with a 660 second grace period outlives the wait. [sources: src/devops_cli/config/defaults.py:1369, src/devops_cli/k8s/volume_move.py]
  • How must the wait timeout follow the pod grace period?: Use the largest spec.terminationGracePeriodSeconds of the deleted pods plus a 60 second margin, with DEFAULT_K8S_VOLUME_MOVE_WAIT_SECONDS as the floor. (best practice) [sources: src/devops_cli/k8s/volume_move.py]
    • Chosen: grace plus margin, floored by the default. The wait follows each pod and keeps the 300 second floor for a pod with no long grace period.
    • Rejected: raise the default constant. A fixed larger wait slows every move and still fails a pod with a longer grace period.
    • Rejected: add a --wait-seconds option. The operator must not compute a value that the pod spec already holds.
  • Why does pv-migrate --non-root exit 23 on the 0600 files?: _enforces_restricted() selects --non-root, so rsync runs as UID 10000 and cannot read files that UID 1000 owns with mode 0600; rsync exits 23 with a partial transfer. [sources: src/devops_cli/k8s/volume_move.py:1583]
  • When must the baseline label apply and be restored?: Only with the opt-in --allow-baseline flag: apply enforce=baseline after Step 1 pauses Argo CD, and restore the recorded value before Step 11 resumes Argo CD and on undo. (best practice) [sources: src/devops_cli/k8s/volume_move.py]
    • Chosen: opt-in flag with a window around the paused steps. Argo CD is paused, so selfHeal cannot revert the label, and the namespace returns to its recorded level.
    • Rejected: always set baseline. It weakens the namespace for every move, with no operator consent.
    • Rejected: require the operator to pause Argo CD by hand. The command already pauses Argo CD at Step 1, so a second manual step adds a failure.
  • How must plan_volume_move() treat --allow-baseline?: It must treat the namespace as non-restricted when the operator sets --allow-baseline, because the window applies baseline before the migration runs. (best practice) [sources: src/devops_cli/k8s/volume_move.py]
    • Chosen: pass the flag into the plan and skip --non-root. The plan matches the PSA level that the migration will run under.
    • Rejected: keep --non-root and let rsync fail. It repeats the 23 exit that the issue reports.
    • Rejected: re-plan after the pause. It runs the plan twice and adds a second code path.
  • Which value does the restore write?: Write the pod-security.kubernetes.io/enforce value read before the window, which is restricted here, and remove the label when it was absent. (best practice) [sources: src/devops_cli/k8s/volume_move.py]
    • Chosen: recorded prior value. A namespace that enforces another level returns to that level, not to a hard-coded one.
    • Rejected: hard-code restricted. It changes a namespace that enforces a different level.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @devops-cli-service
    Contributor

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

  3. added
    status/in-review
    and removed
    status/in-progress
    on Nov 29, 2026
  4. removed
    status/in-review
    on Nov 30, 2026
  5. devops-cli-service commented on Nov 30, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-30 00: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