Skip to content

fix(infra): restart k3s with a cordon and no drain #6338

Closed

Description

@dan-petty

Problem Description

devops infra apply drains a node before each change of class service-restart:k3s or service-restart:k3s-agent. On the control-plane node of homelab, the drain check of such a change can never pass. Thus the server node cannot get a merged k3s or kubelet change through devops infra.

A restart of k3s does not need a drain. The k3s units use KillMode=process, so a restart stops only the k3s process, and the containers keep running. Only a reboot-class change stops the pods of the node. The k3s system-upgrade-controller server plan does the same: it cordons the server node and does not drain it.

Evidence (2026-11-18)

  • Apply 4d0bfc44cd6e49749758147a7e7aad64 of plan 8eb73261ff21..., playbook ansible/playbooks/03_k3s.yaml, one host <control-plane-node> with the class service-restart:k3s. The apply stopped at the drain check: kubectl drain --dry-run=server reached its timeout.
  • kubectl get pdb -A: llm/llm-gateway-db-primary and mattermost/mattermost-db-primary allow 0 disruptions. Both are CloudNativePG clusters with instances: 1 (k8s/llm/gateway-db.yaml, k8s/mattermost/database.yaml), and their primaries run on that node.
  • Result: the merged kubelet change of dan-petty/homelab is not on the server node.

Options to weigh

  1. Restart with a cordon and no drain. A class for a restart of the node service: cordon, run, wait for Ready, check the health of the nodes, uncordon. The host variable that selects the units can follow devops_infra_nondisruptive_units (src/devops_cli/infra/plan.py:97). This keeps the Ready wait and the health check for the control plane.
  2. The host variable of today. With k3s in devops_infra_nondisruptive_units, the restart runs in the run together. That run has no cordon, no Ready wait and no health check after the restart. Homelab can do this now with no devops-cli change, but it is less safe for the control plane.
  3. The CloudNativePG window around the drain (feat(infra): open a CloudNativePG window to drain a node #5267: spec.nodeMaintenanceWindow with inProgress: true and reusePVC: true). A reboot-class change needs it. A k3s restart does not need the eviction.
  4. A drain check rule for a single-instance CloudNativePG primary, or spec.enablePDB: false on the two clusters. The CRD of the cluster has the field (kubectl explain clusters.spec.enablePDB). It removes the protection of the primary for each drain, also a reboot.

Option 1 alone unblocks the k3s restart. Option 3 (#5267) is still necessary for a reboot of the node.

Acceptance Criteria

  • A plan test: a changed restart of a unit that the host lists for a restart with no drain gets that class.
  • An apply test with a fake cluster: a host of that class is cordoned, not drained, waits for Ready, and is uncordoned only when it was schedulable before.
  • The module text of src/devops_cli/infra/apply.py and the infra documents name the class.

Existing Tool Considered

The k3s system-upgrade-controller plans (cordon: true for the server plan). It upgrades k3s only and does not run the playbooks of the repo, so it does not replace the apply step (as #5120 records).

Alternatives check of 2026-11-22: partly.
Tool: rancher/system-upgrade-controller (https://github.com/rancher/system-upgrade-controller), Apache-2.0, last activity 2026-11-21, maintained.
Reason: Searches found the k3s system-upgrade-controller, which cordons the server node and restarts k3s without a drain, but it upgrades k3s versions only and cannot run the repo's playbooks or join the apply step classes.

Covers:

  • Cordons the node before the k3s restart
  • Restarts the k3s unit with no drain
  • Uncordons after the plan job succeeds

Lacks:

  • Runs the repository's ansible playbooks
  • Fits the plan and apply step classes
  • Ready wait and node health check after restart
  • Per-host selection of the units to restart

Proposed design

Problem statement

Do not drain a k3s restart. Cordon the node, restart the unit, wait for Ready and node health, and uncordon. devops infra apply drains a node before each change of class service-restart:k3s or service-restart:k3s-agent. The control-plane node of homelab cannot pass that drain check. Two CloudNativePG primaries allow zero disruptions, and they run on that node. A k3s restart does not stop the containers, because the k3s units use KillMode=process. This change adds the no-drain restart class.

Acceptance criteria

Requirement: No-drain restart class

The infra plan SHALL give a changed restart of a unit in the host no-drain list the class service-restart-nodrain:<unit>.

Scenario: Listed k3s restart gets the no-drain class

  • WHEN A plan test uses a host that lists k3s in devops_infra_restart_nodrain_units, and the playbook changes the k3s unit.
  • THEN The plan test finds the class service-restart-nodrain:k3s for that host.

Requirement: Cordon without drain

The infra apply SHALL cordon a host with a no-drain restart class, run the playbook, wait for Ready and node health, and uncordon it only when it was schedulable before.

Scenario: No-drain apply skips drain

  • WHEN An apply test uses a fake cluster and one host with the class service-restart-nodrain:k3s.
  • THEN The test shows a cordon step, no drain check, no drain, a Ready wait, a node health check, and an uncordon.

Requirement: Normal restart still drains

The infra apply SHALL keep the drain check and drain for a restart class that the host does not list for no-drain restart.

Scenario: Normal k3s restart drains

  • WHEN An apply test uses a host with service-restart:k3s and no entry in devops_infra_restart_nodrain_units.
  • THEN The test shows the drain check and drain before the restart.

Requirement: Module docstring names the class

The module docstring of src/devops_cli/infra/apply.py SHALL name the no-drain restart class and its skips.

Scenario: Module docstring names the class

  • WHEN A test reads the module docstring of src/devops_cli/infra/apply.py.
  • THEN The docstring contains service-restart-nodrain and states that the drain check and drain are skipped.

Existing Tool Considered

The alternatives check in the issue body gives the verdict partly for rancher/system-upgrade-controller (https://github.com/rancher/system-upgrade-controller). The block lists what the tool covers and lacks. The proposal does what the tool lacks: it runs the repository's Ansible playbooks, adds the plan and apply step classes, waits for Ready and checks node health after the restart, and selects the units per host.

Key questions

  • Which restart method should the apply use for a k3s unit?: Use option 1. Cordon the node, restart the unit, wait for Ready and node health, and uncordon. Do not drain. Do not use the run-together path of option 2. (best practice) [sources: src/devops_cli/infra/apply.py, CONTEXT.md]
    • Chosen: Cordon and no drain. A k3s restart does not stop containers. The control-plane drain check cannot pass. This path keeps the Ready wait and the health check.
    • Rejected: Reuse devops_infra_nondisruptive_units. That path runs the restart in the run together. It has no cordon, no Ready wait and no health check after the restart.
    • Rejected: CloudNativePG maintenance window. It is necessary for a reboot. A k3s restart does not need an eviction.
    • Rejected: Turn off the PDB of the single-instance primaries. It removes the primary protection for each drain, also a reboot.
  • How does the plan select a no-drain restart?: Add devops_infra_restart_nodrain_units to the host vars. A changed restart of a listed unit gets service-restart-nodrain:<unit>. Follow the read of devops_infra_nondisruptive_units. (best practice) [sources: src/devops_cli/infra/plan.py:97, tests/infra/test_plan.py]
    • Chosen: New host variable. It keeps the selection in the inventory and follows the existing nondisruptive list.
    • Rejected: Reuse devops_infra_nondisruptive_units. That list means no disruptive class. It gives no cordon and no Ready wait.
    • Rejected: Hard-code k3s and k3s-agent. It does not let another infra repo choose the units.
  • Which apply steps run for a no-drain restart?: Use the one-host apply path with a step list. A no-drain host runs cordon, fresh check, run, Ready, node health, uncordon and alerts. It skips the drain check and drain. A normal disruptive host keeps the current steps. (best practice) [sources: src/devops_cli/infra/apply.py, src/devops_cli/models/infra.py]
    • Chosen: One path with selected steps. It keeps the fresh check, the Ready wait, the health check and the alert wait in one place.
    • Rejected: A second apply path. It duplicates the settle and report code.
    • Rejected: A flag inside the drain step. The report would still name a drain step for a host that did not drain.
  • Which apply step records the cordon?: Add ApplyStep.CORDON. Do not reuse ApplyStep.DRAIN. (best practice) [sources: src/devops_cli/infra/apply.py, src/devops_cli/models/infra.py]
    • Chosen: Add CORDON. The report and the audit record then name the step that ran.
    • Rejected: Reuse DRAIN. It reports a drain that did not happen.
  • Does a no-drain restart run the drain check?: No. It skips DRAIN_CHECK and DRAIN. The API server check can fail on a PDB, and no eviction happens. (best practice) [sources: src/devops_cli/infra/apply.py, CONTEXT.md]
    • Chosen: Skip both. A restart does not evict a pod. The check can fail on a PDB that does not apply.
    • Rejected: Keep the dry-run check. The check can reach its timeout on the control-plane node, as the evidence shows.
    • Rejected: Keep the drain. The restart does not need an eviction, and the drain cannot pass.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Moved to new items

#6731

Activity

  1. added
    type/bug
    scope/infra
    source/agent
    status/new
    on Nov 18, 2026
  2. dan-petty commented on Nov 18, 2026

    @dan-petty
    OwnerAuthor
    • Priority: P1-High. It blocks a merged kubelet change from reaching the control-plane node through the standard apply path.
    • Related: feat(infra): open a CloudNativePG window to drain a node #5267, which asks for a different change. Both address the drain block on the control-plane node, but #5267 makes drain succeed via a CNPG window while the candidate removes the drain requirement for k3s restarts.
  3. added
    value/medium
    effort/medium
    priority/p1-high
    on Nov 18, 2026
  4. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.

  5. devops-cli-service commented on Nov 22, 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 (6)

    Tools considered:

    Searches run:

    • system-upgrade-controller cordon node upgrade plan k3s, results: 5
    • rancher system-upgrade-controller plan cordon true drain upgrade k3s only, results: 5
    • kubernetes operator cordon node restart systemd service uncordon no drain, results: 5
    • k3s automated upgrades system-upgrade-controller README, results: 5
    • "system-upgrade-controller", results: 5
    • github rancher system-upgrade-controller cordon server plan upgrade, results: 5

    Sources:

  6. added
    status/ready
    and removed
    status/new
    on Nov 22, 2026
  7. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.

  8. added
    owner/service
    on Nov 22, 2026
  9. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    Plan state: branch fix/6338-restart-k3s-with-a-cordon-and, draft pull request #6744. The pull request plans the item and closes no issue. The stage job and the step fix-plan edit this comment, and a comment of each run tells what the run did.

    The task groups, with the tokens of the inputs of each step, for a budget of 64000 tokens:

    1. Give a listed no-drain unit restart its own class: 35182 tokens
    2. Add the cordon step to the cluster: 38068 tokens
    3. Cordon a no-drain host instead of draining it: 30368 tokens
    4. List the cordon in the dry run of a no-drain host: 28143 tokens
    5. Name the class in the apply and plan help and the generated pages: 39030 tokens
    6. Name the class in the apply module text and the infra documents: 42614 tokens

    A model review of the plan found these points. They stop no draft, and a person judges them:

    • major verify_form at tasks (6): Group 6 writes the apply module docstring and the prose of CONTEXT.md and SECURITY.md, but its verify uv run devops ci docs runs devops docs check, which only compares the generated command pages and checks that devops argv references resolve, so it passes whatever the group writes and never checks that the class and its skipped steps are named. Evidence: "uv run devops ci docs"
    • minor other at tasks (3): The apply test asserts the cordon, the absent drain check and drain, and the uncordon, but it never asserts the Ready wait or the node health check that the acceptance criterion and the no-drain scenario name, so a plan that dropped those waits would still pass the test. Evidence: "asserts the steps cordon node-3, check node-3, run node-3 and uncordon node-3 with no drain check and no drain"
    • minor other at tasks (1): Group 1 adds the no-drain class but leaves the module docstring of src/devops_cli/infra/plan.py, which lists the disruptive classes, stale: it still says a restart is service-restart:<unit> unless only the nondisruptive list names the unit, and the plan's what-changes names the docstring of the apply module only. Evidence: "service-restart:<unit>, unless the host variable devops_infra_nondisruptive_units lists the"
  10. 18 remaining items

  11. added
    status/in-review
    and removed
    status/in-progress
    on Nov 22, 2026
  12. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    The draft pull request #6744 holds the final title and body. In mode on of roadmap.fix_checks.mode, the watch row marks it ready when its checks pass, and a fix-checks Job repairs a failed check whose name gives the class test, lint or types. In each other case the watch row stops the item: another failed check, a cancelled check, a conflict, a fix-checks Job that ended with no repair, or another mode.

    Spend: 452 model requests, 33780496 input tokens, 151811 output tokens.

  13. removed
    owner/service
    on Nov 22, 2026
  14. removed
    status/in-review
    on Nov 22, 2026
  15. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-22 16:45 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/infrasource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions