Skip to content

feat(k8s): k8s cluster read and access commands list their requests in a dry run and make none #2238

Description

@dan-petty

Part of #886. Depends on sub-issue 00 (the dry-run class ratchet test).

Problem or Motivation

The owner's dry-run rule (#412) says that a dry run makes no external request and returns the requests that the real run would make. The #886 inventory (2026-10-25, commit 1bb164b) found 14 k8s cluster read and access commands that do not obey it:

  • 11 commands make an external request, or possibly make one, and have no request plan.
  • 1 commands change local state, make no external request and have no --dry-run.
  • 2 commands make no external request and need only the no-external-request class.
  • Already done, not in scope: k8s doctor.

A command without a request plan either prints the generic Would run delegated command line under devops --dry-run, or fails with No such option: --dry-run, or prints an echo of its arguments. None of these shows the requests.

A command that makes no external request prints the generic Would run delegated command line under devops --dry-run and does not run, although running it is safe. Some of these commands have an echo-only --dry-run that prints only their arguments.

Proposed Solution & Architectural Design

For each command in the table:

  • Request plan: add --dry-run if it is missing. The dry run makes no external request, reads included. It returns the command's real result type, marked as a dry run, with the ordered PlannedRequest items (argv, stdin and env with <placeholders>, plus condition and repeat). Build each PlannedRequest from the same argument builder that the real run uses, so that the plan cannot drift from the run. Print it with render_request_plan. Give the command the request-plan class.
  • Local preview: add --dry-run. The preview prints the change and writes nothing. Give the command the no-external-request class.
  • Mark only: give the command the no-external-request class. devops --dry-run <command> then runs it normally.
  • Remove an echo-only preview (render_dry_run_result or @dry_run_command) when the command gets its new dry run, with no shim.
  • Remove the command's paths from tests/fixtures/dry_run_gaps.json.

Notes from the inventory:

  • Several commands use the Kubernetes Python client (kubernetes.client), not kubectl. A plan names those calls by method and target, as the PlannedRequest docstring allows for a request without argv.
  • k8s pods is a named criterion of feat(cli): commands with no dry-run preview: read-only ones run, mutators gain one #886: devops --dry-run k8s pods returns the request it would make and makes none.
  • k8s port-forward-stop stops local kubectl port-forward processes. It makes no external request, but it changes local state, so it gets a --dry-run preview.
  • The table comes from a static walk of each callback and the functions that it calls. Check each row against the code before you change it. If a row is wrong, change the class to match the code, and record the evidence in the pull request.
Command --dry-run today External request Work Evidence
k8s audit yes (echo only) yes request plan trivy json @ config.commands:build_trivy_scan_cmd:137
k8s contexts yes (echo only) yes request plan minikube @ commands.k8s.cluster_context:contexts:44
k8s gpu-matrix no no mark only -
k8s logs yes (echo only) yes request plan kubectl logs @ k8s.logql:execute_kubectl_logql:321
k8s pods yes (echo only) yes request plan kubernetes-client: kubernetes.load_incluster_config @ k8s.service:KubernetesService.load_config:146
k8s port-forward yes (echo only) yes request plan kubectl get @ commands.k8s.networking:_discover_ingress_hosts:676
k8s port-forward-status no no mark only -
k8s port-forward-stop no no local preview -
k8s rbac-audit yes (echo only) yes request plan kubectl get @ commands.k8s.security_audit:_read_rbac:45
k8s security-stream yes (echo only) yes request plan kubectl logs @ k8s.security_stream:_build_kubectl_command:159
k8s service-url no yes request plan http: httpx2.HTTPTransport @ http.client:egress_transport:106
k8s status yes (echo only) yes request plan manual: kubernetes CoreV1Api.list_node via runtime._k8s_clients() (commands/k8s/cluster_context.py)
k8s stream-logs yes (echo only) yes request plan kubectl @ config.commands:build_kubectl_cmd:95
k8s switch-context yes (echo only) yes request plan minikube start @ commands.k8s.cluster_runtime:_start_minikube:108

Target Subsystem

Kubernetes & Minikube Automation

Existing Tool Considered

The work uses what the repository has: devops_cli.dry_run.requests.PlannedRequest and render_request_plan (#741), the dry-run class decorator and ratchet test from sub-issue 00, and the test guards in tests/conftest.py and tests/test_roadmap_dry_runs.py. No new dependency is necessary.

Acceptance Criteria

  • Each command in the table is out of tests/fixtures/dry_run_gaps.json, and the ratchet test passes.
  • For each request-plan command, devops <command> --dry-run and devops --dry-run <command> make no external request and print the ordered requests. Verified by tests with the process runner, the HTTP clients and the other clients patched to fail.
  • For each request-plan command with --format json or --json, the dry run returns the real result type marked as a dry run, with the planned requests. Verified by tests.
  • For each request-plan command, the plan holds the requests that the real run makes, in the same order. Verified by a test that runs the real command against a fake runner or client that records each call, and compares the calls with the plan (the pattern of tests/test_roadmap_dry_runs.py).
  • For each local-preview command, --dry-run prints the change and writes nothing. Verified by tests with the writer patched to fail.
  • For each mark-only command, devops --dry-run <command> runs the command normally. Verified by tests with the process runner and the HTTP clients patched to fail.
  • Echo-only previews of these commands are gone, with no shim.
  • The new tests start no process and open no socket. The pull request records their time.
  • uv run devops ci passes.

Source: #886

Proposed design

Problem statement

The 14 k8s cluster read and access commands in the #886 inventory do not obey the dry-run rule (#412). Under --dry-run, they print a generic line, fail with a missing option, or echo their arguments. None shows the requests a real run would make. This issue gives each command the correct dry-run behavior: a request plan with PlannedRequest items, a local preview, or the no-external-request class mark.

Acceptance criteria

  • Criterion 1: Each command in the table is out of tests/fixtures/dry_run_gaps.json, and the ratchet test passes.
    Verification: Run the ratchet test from sub-issue 00. Confirm all 14 commands are absent from the fixture file.
  • Criterion 2: For each request-plan command, devops --dry-run and devops --dry-run make no external request and print the ordered requests.
    Verification: Run tests with the process runner, the HTTP clients and the other clients patched to fail. Assert exit code 0 and that the output contains the planned requests.
  • Criterion 3: For each request-plan command with --format json or --json, the dry run returns the real result type marked as a dry run.
    Verification: Run tests that invoke the command with --dry-run --format json. Assert the result type, the dry_run flag, and the presence of PlannedRequest items.
  • Criterion 4: For each request-plan command, the plan holds the requests that the real run makes, in the same order.
    Verification: Run a test that runs the real command against a fake runner or client that records each call. Compare the calls with the plan. Follow the pattern in tests/test_roadmap_dry_runs.py.
  • Criterion 5: For each local-preview command, --dry-run prints the change and writes nothing.
    Verification: Run a test with the writer patched to fail. Assert the output names the change and that no write occurred.
  • Criterion 6: For each mark-only command, devops --dry-run runs the command normally.
    Verification: Run tests with the process runner and the HTTP clients patched to fail. Assert the command completes and returns its normal result.
  • Criterion 7: Echo-only previews of these commands are gone, with no shim.
    Verification: Search the codebase for render_dry_run_result and @dry_run_command in the 14 command modules. Confirm they are absent.
  • Criterion 8: The new tests start no process and open no socket. The pull request records their time.
    Verification: The session guards in tests/conftest.py (refuse_real_programs, prevent_external_network_calls) fail the test on any unguarded reach. The PR description records the test time.
  • Criterion 9: uv run devops ci passes.
    Verification: Run uv run devops ci in the pull request. Confirm all checks pass.

Key questions

  • Must each inventory row be verified against the code before changing it?: Yes. The table comes from a static walk of each callback and the functions it calls. If a row is wrong, change the class to match the code and record the evidence in the pull request. (proposed)
  • What is the correct work for k8s port-forward-stop?: It stops local kubectl port-forward processes. It makes no external request, but it changes local state, so it gets a --dry-run preview. (proposed)
  • Which commands are mark-only and which are request-plan?: Mark-only: k8s gpu-matrix and k8s port-forward-status. Local preview: k8s port-forward-stop. Request plan: the other 11 commands. (proposed)

Open questions

  • How are Kubernetes Python client calls represented in a PlannedRequest when there is no argv? (missing verified source)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/feature
    on Oct 25, 2026
  2. dan-petty commented on Oct 25, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/feature. The candidate adds new functionality to k8s commands to list requests during dry runs.
    • Priority: P1-High. This change is part of a larger initiative (#886) that enforces consistent dry-run behavior across all commands.
    • Value: High. Users will benefit from seeing exactly what requests would be made during a dry run for k8s cluster commands.
    • Effort: Medium. The change requires modifying multiple k8s commands and adding new dry-run logic to each one.
    • Possible duplicate: feat(cli): each command declares its dry-run class, and a ratchet test stops a new command without one #2230, which may ask for the same change. The model names k8s cluster read and access commands list their requests in a dry run and make none as the change that both ask for. The candidate asks for the same change as item 2230 which is about commands declaring their dry-run class. A person closes one of the two if that is so.
  3. dan-petty commented on Oct 25, 2026

    @dan-petty
    OwnerAuthor

    Not a duplicate of #2230. Both are parts of #886. #2230 adds the dry-run class and the ratchet test for every command; this item gives a request plan to the k8s cluster read and access commands, and removes them from the gap list that #2230 adds. The agent that split #886 filed both.

  4. dan-petty commented on Oct 27, 2026

    @dan-petty
    OwnerAuthor

    Refine cannot set this item to Ready at 63be7ed until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • How are Kubernetes Python client calls represented in a PlannedRequest when there is no argv? (missing verified source)
  5. added
    priority/p1-high
    status/new
    effort/medium
    value/high
    scope/k8s
    status/in-progress
    and removed
    status/new
    on Oct 28, 2026
  6. added 2 commits that reference this issue on Oct 31, 2026
    d1080f2
    ccc9411
  7. added
    status/in-review
    and removed
    status/in-progress
    on Oct 31, 2026
  8. removed
    status/in-review
    on Oct 31, 2026
  9. added a commit that references this issue on Oct 31, 2026
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/featurevalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions