Skip to content

fix(k8s): restart the readers on the first push of a Secret #7405

Done

Description

@dan-petty

Problem

devops secrets push restarts the workloads that read a Secret only when the push changes an existing Secret. SecretPlan.changed() returns False when no live Secret exists (src/devops_cli/k8s/secret_push.py:149-155), and _needs_restart (secret_push.py:629-631) requires changed().

A workload that reads the Secret through optional: true starts before the first push, with empty values. The first push creates the Secret and restarts nothing, so the workload keeps the empty values until a person restarts it. Examples: the Grafana GitHub App of dan-petty/homelab#278 (plan PR dan-petty/homelab#511): the data source health check keeps the answer error parsing app id. The runner App step of homelab k8s/README.md:926 has the same gap.

Done when

  • A push that creates a Secret restarts each workload that reads it, as a push that changes it does.
  • --plan and the dry run name that restart.
  • A test proves the restart for a created Secret and for a changed Secret, and proves no restart for an unchanged Secret.

Alternatives check of 2026-11-27: partly.
Tool: stakater/Reloader (https://github.com/stakater/Reloader), Apache-2.0, last activity 2026-11-24, maintained.
Reason: Searches found stakater/Reloader, an open, maintained controller that rolls annotated workloads when a Secret changes, but it works cluster-side and gives no plan output or tests for the push command.

Covers:

  • Rolling restart of annotated Deployments, StatefulSets, DaemonSets and CronJobs on change
  • Cluster-side watch of Secret and ConfigMap changes, outside the push command
  • Restart through the Kubernetes API with no code in the CLI

Lacks:

  • No plan or dry-run output that names the restart
  • Each workload needs an opt-in annotation or label
  • No tests for created, changed and unchanged Secret cases

Proposed design

Problem statement

devops k8s push-secrets restarts the workloads that read a Secret only when the push changes an existing Secret. A workload that reads an optional Secret starts with empty values, and the first push creates the Secret and restarts nothing, so the workload keeps the empty values until a person restarts it. The change treats a created Secret as a restart case, names the restart in --plan and in the dry run, and fixes the guide, the cluster document and the help text that state the changed-only rule.

Acceptance criteria

Requirement: Created Secret restarts its readers

devops k8s push-secrets SHALL restart each existing workload that reads a Secret when the push creates that Secret.

Scenario: First push creates a Secret

  • WHEN The plan holds a Secret with no live object and at least one key to write, a workload in the Secret's restarts exists, and the push applies the Secret.
  • THEN The push runs kubectl rollout restart once for each existing workload in the Secret's restarts, and no workload twice.

Requirement: Changed Secret still restarts its readers

devops k8s push-secrets SHALL restart each existing workload that reads a Secret when the push changes that Secret's data.

Scenario: Push adds a key to a Secret

  • WHEN A live Secret exists, a workload reads it, and the push writes a key that the live Secret does not hold.
  • THEN The push runs kubectl rollout restart once for that workload.

Requirement: Unchanged Secret restarts no reader

devops k8s push-secrets MUST NOT restart a workload when the push writes the same data to an existing Secret.

Scenario: Push leaves a Secret unchanged

  • WHEN A live Secret holds the same values as the keyring, a workload reads it, and the push writes the same data again.
  • THEN The push runs no kubectl rollout restart.

Requirement: Plan names a created Secret restart

devops k8s push-secrets --plan SHALL name each workload that the push would restart for a created Secret.

Scenario: Plan for a created Secret

  • WHEN devops k8s push-secrets --only <ref> --plan runs with no live Secret, a key to write and an existing workload in the Secret's restarts.
  • THEN The line for the Secret says would create and would restart: <workload>, and the run makes only kubectl get calls.

Requirement: Dry run names a created Secret restart

The dry run SHALL list the restart of a created Secret as a request under the condition that creates the Secret.

Scenario: Dry run for a created Secret

  • WHEN devops k8s push-secrets --dry-run runs with restarts on for a Secret with no live object and a workload in its restarts.
  • THEN The request plan holds kubectl rollout restart <workload> under the condition the push creates or changes live <ref>'s data.

Requirement: Help and generated command page name the created restart

The --plan help and the generated page docs/commands/k8s.md SHALL name the workloads that a created or changed Secret restarts.

Scenario: Generated command page is current

  • WHEN The help text of --plan names a created Secret's restart and uv run devops docs check runs.
  • THEN The check passes, because docs/commands/k8s.md is regenerated from the new help text.

Existing Tool Considered

stakater/Reloader (https://github.com/stakater/Reloader), verdict: partly. The alternatives block of the issue body gives what the tool lacks, and the project rejected Reloader for a cluster-side restart before (openspec/changes/archive/2026-10-28-821-gpu-dcgm-panels/design.md:34). The restart stays in devops k8s push-secrets, which already holds the restart targets, the --plan line and the tests. Cost of the CLI change: about 3,000 tokens and under 1 hour; no new controller.

Key questions

  • Which function decides that a Secret push restarts a workload?: _needs_restart at src/devops_cli/k8s/secret_push.py:629 decides it: it returns bool(plan.data()) and plan.changed() at line 631. preview_restarts calls it for --plan at line 637, and _write calls it for the push at line 652. SecretPlan.changed() returns False when no live Secret exists (secret_push.py:149-155), which is the gap. [sources: src/devops_cli/k8s/secret_push.py:149, src/devops_cli/k8s/secret_push.py:629, src/devops_cli/k8s/secret_push.py:631, src/devops_cli/k8s/secret_push.py:637, src/devops_cli/k8s/secret_push.py:652]
  • How should the push treat a Secret that does not exist yet?: Count a plan with no live Secret and at least one key to write as a restart case. Change _needs_restart to bool(plan.data()) and (plan.live is None or plan.changed()), and say in its docstring that the push creates or changes a Secret it writes. plan_push puts only the Secrets of a present namespace in plan.secrets (secret_push.py:472-497), so live is None means the Secret does not exist. Keep changed() as it is: it means a change to an existing Secret's data, and the --plan change note reads it (src/devops_cli/commands/k8s/cluster_secret_push.py:108). (best practice) [sources: src/devops_cli/k8s/secret_push.py:149, src/devops_cli/k8s/secret_push.py:472, src/devops_cli/k8s/secret_push.py:497, src/devops_cli/k8s/secret_push.py:629, src/devops_cli/k8s/secret_push.py:631, src/devops_cli/commands/k8s/cluster_secret_push.py:108]
    • Chosen: Extend _needs_restart. It fixes the push and the --plan path at one place, keeps changed() for an existing Secret and adds no plan-only decision.
    • Rejected: Make changed() true when no live Secret exists. changed() means a change to an existing Secret's data, and the --plan change note reads it, so a create would print a note about a change.
    • Rejected: Restart every workload on every push. It breaks the unchanged Secret case and rolls workloads that already read the same data.
  • Should the plan adopt stakater/Reloader for this restart?: No. Reloader is a cluster-side controller, and the alternatives block of the issue body gives what it lacks. The project rejected it for a cluster-side restart before (openspec/changes/archive/2026-10-28-821-gpu-dcgm-panels/design.md:34), and CONTRIBUTING.md:26 asks a design question to be decided with the best practice or the open tool. The restart stays in devops k8s push-secrets, so --plan and the dry run name it and offline tests prove the created, changed and unchanged cases. (best practice) [sources: openspec/changes/archive/2026-10-28-821-gpu-dcgm-panels/design.md:34, CONTRIBUTING.md:26]
    • Rejected: Adopt stakater/Reloader. It restarts on a cluster-side watch, so the push cannot name the restart in --plan or the dry run, and the three offline cases have no test.
    • Chosen: Keep the restart in devops k8s push-secrets. The command already holds the restart targets and the tests, and the project rejected Reloader before.
  • How should --plan and the dry run name a restart of a created Secret?: --plan already goes through _needs_restart in preview_restarts (secret_push.py:634-638), _restart(preview=True) (secret_push.py:613-626) and secret_line (secret_push.py:680-689), so the fix to _needs_restart makes it print would restart: <workload>. The dry run reads no plan: _plan_writes builds the workload read and the kubectl rollout restart request under the condition the push changes live <ref>'s data (secret_push.py:797-805). Change that condition to the push creates or changes live <ref>'s data, so the dry run lists the restart of a created Secret too. Change the docstrings of _restart and preview_restarts that say changed. (best practice) [sources: src/devops_cli/k8s/secret_push.py:613, src/devops_cli/k8s/secret_push.py:634, src/devops_cli/k8s/secret_push.py:680, src/devops_cli/k8s/secret_push.py:797, src/devops_cli/k8s/secret_push.py:805]
    • Chosen: Extend the existing restart path and the dry-run condition. --plan prints would restart from _needs_restart, and the dry run lists the rollout request from the same rule, so both agree with the push.
    • Rejected: Add a plan-only restart message. It duplicates the decision and can disagree with the restart that the push runs.
    • Rejected: Leave the dry-run condition as a change only. The dry run would list no restart for a created Secret, which contradicts the push and the done-when.
  • Which documents and help text state the changed-only rule?: k8s/README.md:221 heads its restart column Restarted when it changes, k8s/README.md:265 and docs/CLUSTER.md:263 say a push that creates the SearXNG metrics Secret restarts nothing and a person then runs kubectl rollout restart, and k8s/README.md:274-275 and the help at src/devops_cli/lang/en/help.py:394 say --plan names the workloads a change would restart. The generated page docs/commands/k8s.md:298 copies that help. AGENTS.md:14 rule 8 requires the same pull request to fix a document that the change makes wrong, and uv run devops docs check checks the generated page (CONTRIBUTING.md:196). [sources: k8s/README.md:221, k8s/README.md:265, k8s/README.md:274, k8s/README.md:275, docs/CLUSTER.md:263, src/devops_cli/lang/en/help.py:394, docs/commands/k8s.md:298, AGENTS.md:14, CONTRIBUTING.md:196]
  • Which tests hold the created, changed and unchanged cases now?: tests/k8s/test_cluster_secret_push.py:326 (test_keyring_values_without_live_secrets_are_created_and_restart_nothing) pins the old behavior: it creates Secrets while workloads exist and asserts no kubectl rollout, so it changes to expect the restarts. The changed case is at line 367 (test_a_key_added_to_an_existing_secret_restarts_its_workloads_once), the unchanged case at line 352 (test_an_equal_live_value_is_unchanged_and_restarts_nothing), and the plan case at tests/k8s/test_cluster_secret_plan.py:1273 (test_plan_lists_the_workloads_a_changed_secret_would_restart). [sources: tests/k8s/test_cluster_secret_push.py:326, tests/k8s/test_cluster_secret_push.py:335, tests/k8s/test_cluster_secret_push.py:352, tests/k8s/test_cluster_secret_push.py:367, tests/k8s/test_cluster_secret_plan.py:1273]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. dan-petty commented on Nov 27, 2026

    @dan-petty
    OwnerAuthor
  2. added
    type/bug
    scope/k8s
    source/agent
    status/new
    value/medium
    effort/low
    priority/p2-medium
    on Nov 27, 2026
  3. 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 restart deployment when Secret is created or changed controller Reloader, results: 5
    • stakater Reloader open source restart workloads on ConfigMap Secret changes, results: 5
    • stakater reloader github, results: 5
    • reloader kubernetes secret change rolling restart github repository, results: 5
    • Reloader watches newly created secret triggers rolling upgrade annotated deployment, results: 5
    • github.com/stakater/Reloader README auto reload workloads, results: 5
    • wave-k8s wave restart pods on secret change, results: 5
    • kubectl rollout restart deployment secret, results: 5
    • Reloader kubernetes controller, results: 5
    • Reloader documentation reload on create secret annotation reloader.stakater.com/auto, results: 5

    Sources:

  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 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 00:41 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/lowpriority/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