Skip to content

feat(infra): open a CloudNativePG window to drain a node #5267

Done

Description

@dan-petty

Problem or Motivation

devops infra apply (#5125) drains each disruptive host with no --force, so a PodDisruptionBudget applies. A CloudNativePG cluster with 1 instance has a primary PodDisruptionBudget that allows 0 disruptions. On homelab, the control-plane node runs two of them (llm-gateway-db in llm, mattermost-db in mattermost). The drain check (kubectl drain --dry-run=server) of that node stops the apply with error when evicting pods/"llm-gateway-db-1" -n "llm": global timeout reached. The owner decided on 2026-11-12: "schedule short maintenance window for homelabs when necessary". In the live run of #5125, an agent did the window by hand: spec.nodeMaintenanceWindow: {inProgress: true, reusePVC: true} on each such Cluster, the apply, then inProgress: false, with a check of how Argo CD manages the Cluster objects.

Proposed Solution & Architectural Design

A maintenance-window step of devops infra apply for a disruptive host:

  1. Before the drain check, find the CloudNativePG clusters with 1 instance whose primary runs on the node (kubectl get clusters.postgresql.cnpg.io -A, status.instances, the primary pod and its node).
  2. Name them in the report and the audit record as "down during the window", as the apply names the workloads with node-local volumes now.
  3. Set spec.nodeMaintenanceWindow: {inProgress: true, reusePVC: true} on each (the CloudNativePG supported path; never a change of a PodDisruptionBudget), only at agent access full and only when the plan is disruptive on that node.
  4. After the uncordon, set inProgress: false, and wait until each cluster reports Cluster in healthy state with its primary Ready, with the bound infra.node_ready_timeout_seconds. A cluster that does not come back stops the apply.
  5. Argo CD: read the Application that tracks each Cluster (argocd.argoproj.io/tracking-id). When the field is in git, or the Application has selfHeal and a diff would revert it, refuse with the step (an ignoreDifferences entry for /spec/nodeMaintenanceWindow), and never turn off selfHeal from the CLI.
  6. --dry-run lists the reads and the patches.

Target Subsystem

OpenTofu / Infrastructure as Code

Existing Tool Considered

CloudNativePG spec.nodeMaintenanceWindow (the operator's documented path for a drain of a node with a single-instance cluster) and the kubectl cnpg maintenance set --reusePVC plugin command, which sets the same field. devops calls kubectl patch so that no plugin is a new dependency. Considered and not chosen: a change of the PodDisruptionBudget (the operator owns it), kubectl drain --disable-eviction (bypasses every budget). Cost: about 1.5M tokens to build, 0.2M a quarter to keep, 3 hours.

Acceptance Criteria

  • Tests with a fake kubectl: a node with a single-instance primary gets the window before the drain check and loses it after the uncordon; a cluster with 2 instances gets no window; a cluster that does not come back stops the apply; an Application that would revert the field refuses the apply with the step; the dry run lists the patches and starts no process.
  • The audit record of the host names each cluster of the window.

Dependencies

#5125.

Alternatives check of 2026-11-19: in-use.
The repository already uses this tool.
Tool: cloudnative-pg/cloudnative-pg (https://github.com/cloudnative-pg/cloudnative-pg), Apache-2.0, last activity 2026-11-19, maintained.
Reason: Searches found only the CloudNativePG operator itself: its nodeMaintenanceWindow field is the supported path for draining a node that holds a single-instance cluster, but the drain check, Argo CD guard, health wait and audit stay in devops-cli.

Covers:

  • Supported field to put a single-instance cluster into a node drain window
  • reusePVC keeps the volume while the primary is down
  • Operator reports the healthy state and a Ready primary after the window

Lacks:

  • No integration with the apply's drain check or plan
  • No Argo CD selfHeal or ignoreDifferences guard
  • No dry run, audit record or readiness timeout of the CLI

Proposed design

Problem statement

The apply stops on the homelab control-plane node, because the primary PodDisruptionBudget of two one-instance CloudNativePG Clusters allows zero disruptions. devops infra apply drains each disruptive host with no --force, so each budget applies, and the drain check of that node ends with a global timeout. The change opens a CloudNativePG node maintenance window on each one-instance Cluster of the node before the drain check. It closes the window after the uncordon, waits for the healthy state, and refuses the host when Argo CD would revert the field. The window stays necessary for a reboot-class change of that node, because a k3s restart does not stop the Pods.

Acceptance criteria

Requirement: Window opens before the drain check

devops infra apply SHALL set spec.nodeMaintenanceWindow.inProgress to true and reusePVC to true on each one-instance CloudNativePG Cluster whose primary runs on a disruptive host before the drain check of that host.

Scenario: A one-instance primary on the disruptive node

  • WHEN a fake kubectl reports one Cluster with status.instances 1 whose primary Pod runs on the disruptive node, and the agent access level of the infra repo is full
  • THEN the apply patches that Cluster before it runs kubectl drain --dry-run=server for the node

Requirement: Window closes after the uncordon

devops infra apply MUST set spec.nodeMaintenanceWindow.inProgress to false on each Cluster of the window after the uncordon of the node.

Scenario: A windowed Cluster after the uncordon

  • WHEN the apply uncordons the node of a Cluster that it put in the window
  • THEN the apply patches inProgress to false on that Cluster before it reads the health of the Cluster

Requirement: Health wait of the windowed Clusters

devops infra apply SHALL wait until each windowed Cluster reports Cluster in healthy state with a Ready primary, within the bound of infra.node_ready_timeout_seconds.

Scenario: A windowed Cluster that returns

  • WHEN the fake kubectl reports Cluster in healthy state with a Ready primary for the windowed Cluster
  • THEN the apply continues the host to its critical alerts

Requirement: An unhealthy windowed Cluster stops the host

devops infra apply MUST stop the host when a windowed Cluster does not report the healthy state within the bound.

Scenario: A windowed Cluster that stays unhealthy

  • WHEN the fake kubectl never reports the healthy state for the windowed Cluster within the bound
  • THEN the apply stops the host with a failure that names the Cluster

Requirement: No window for a Cluster with two instances

devops infra apply MUST NOT open a window on a CloudNativePG Cluster with two or more instances.

Scenario: A two-instance Cluster on the node

  • WHEN a fake kubectl reports one Cluster with status.instances 2 on the disruptive node
  • THEN the apply sends no patch to that Cluster

Requirement: No window below full access

devops infra apply MUST NOT open a window when the agent access level of the infra repo is below full.

Scenario: A safe access level

  • WHEN the infra repo is at agent access safe and a one-instance primary runs on the disruptive node
  • THEN the apply sends no patch to the Cluster

Requirement: Argo CD self-heal guard

devops infra apply MUST refuse the host when an Argo CD Application that tracks a windowed Cluster has selfHeal and no ignoreDifferences entry for /spec/nodeMaintenanceWindow.

Scenario: A self-healing Application with no ignoreDifferences entry

  • WHEN the Application that tracks the Cluster has selfHeal and no ignoreDifferences entry for /spec/nodeMaintenanceWindow
  • THEN the apply stops the host before it patches the Cluster and names the missing ignoreDifferences entry

Requirement: Field in git refuses the host

devops infra apply MUST refuse the host when the environment tree holds spec.nodeMaintenanceWindow of a windowed Cluster in git.

Scenario: The field in the environment tree

  • WHEN the Cluster manifest in the environment tree holds spec.nodeMaintenanceWindow
  • THEN the apply stops the host before it patches the Cluster and names the file that holds the field

Requirement: Dry run lists the window

devops infra apply --dry-run SHALL list each read and each patch of the maintenance window and start no process.

Scenario: A dry run on a node with a one-instance primary

  • WHEN the apply runs with --dry-run and a fake kubectl reports a one-instance primary on the disruptive node
  • THEN the report lists the read of the Clusters and the patch of the window, and the fake kubectl records no patch call

Requirement: Audit record names the windowed Clusters

The audit record infra.apply of the host SHALL name each CloudNativePG Cluster of the window.

Scenario: An apply with a window

  • WHEN the apply completes a host with one windowed Cluster
  • THEN the audit record of the host holds the namespace and name of that Cluster in its list of workloads down during the window

Existing Tool Considered

CloudNativePG (cloudnative-pg/cloudnative-pg, Apache-2.0) covers the field: verdict in-use, because the repository already runs the operator. The alternatives check in the issue body gives what the tool covers and lacks. The tool lacks the drain-check integration, the Argo CD guard, the dry run, the audit record and the readiness timeout. devops infra apply builds that code around the field. It sets the field with kubectl patch, so no plugin becomes a new dependency: about 1.5M tokens to build, 0.2M a quarter to keep, and 3 hours.

Key questions

  • Which path opens the maintenance window: a patch of the Cluster, the kubectl cnpg plugin, a change of the PodDisruptionBudget, or kubectl drain --disable-eviction?: Patch spec.nodeMaintenanceWindow on the Cluster with kubectl patch. It is the operator's documented field for a node drain, and it adds no binary to the runner. (best practice) [sources: k8s/llm/gateway-db.yaml]
    • Chosen: kubectl patch of spec.nodeMaintenanceWindow. It uses the operator's documented field for a node drain and adds no binary to the runner.
    • Rejected: kubectl cnpg maintenance set --reusePVC. It needs the plugin on each runner, so it adds a dependency that the patch avoids.
    • Rejected: Change of the PodDisruptionBudget. The operator owns the budget of a Cluster, so a change of it is not the supported path.
    • Rejected: kubectl drain --disable-eviction. It bypasses every budget of the node, not only the budget of the Cluster.
  • Which CloudNativePG Clusters of the node get a window?: Only the Clusters with status.instances 1 whose primary Pod runs on the node. A Cluster with two or more instances drains within its budget, so it gets no window. (best practice) [sources: k8s/llm/gateway-db.yaml, k8s/mattermost/database.yaml]
    • Chosen: status.instances 1 and the primary Pod on the node. A one-instance Cluster has a primary budget that allows zero disruptions, so only it needs the window.
    • Rejected: Every CloudNativePG Cluster on the node. A Cluster with two or more instances drains within its budget, so a window stops a database for no gain.
    • Rejected: No window, and a person drains by hand. It keeps the manual step of the live run of feat(infra): apply a saved plan one node at a time #5125, and the apply still stops.
  • When in the apply does the window open and close, and what bound does the wait use?: Open the window before the drain check of the disruptive host, and only at agent access full. Close it after the uncordon, then wait for the healthy state with a Ready primary within infra.node_ready_timeout_seconds. A Cluster that does not come back stops the apply. (best practice) [sources: CONTEXT.md, src/devops_cli/config/settings.py, tests/commands/test_infra_apply.py]
    • Chosen: Open before the drain check, close after the uncordon. The node stays cordoned through the fresh check, the run and the health of the nodes, so the Cluster must stay down until the uncordon.
    • Rejected: Open only around the drain. The operator starts the primary while the node is still cordoned, and the Pod cannot schedule.
    • Rejected: Close before the uncordon. The primary comes up on a cordoned node, so the wait fails and the apply stops.
  • How does the step treat an Argo CD Application that would revert spec.nodeMaintenanceWindow?: Read the Application that tracks the Cluster. Refuse the host when the field is in git, or when selfHeal and a diff would revert it, and name the ignoreDifferences entry for /spec/nodeMaintenanceWindow that fixes it. Never turn off selfHeal from the CLI. (best practice) [sources: k8s/argocd/bootstrap/cluster.yaml, src/devops_cli/config/constants.py]
    • Chosen: Refuse the host and require an ignoreDifferences entry. The repository already uses ignoreDifferences in k8s/argocd/bootstrap/cluster.yaml, and the guard changes no shared setting.
    • Rejected: Set selfHeal: false on the Application. It changes a shared Application and hides the next drift.
    • Rejected: Pause auto-sync for the window. It needs a second write and leaves the Application paused if the apply stops.
  • What does --dry-run do with the maintenance window?: List the read of the Clusters and each patch of the window, and start no process. A dry run makes no request, and a patch is a request. (best practice) [sources: CONTEXT.md]
    • Chosen: List the reads and the patches, and change nothing. A dry run makes no request, and a patch is a request.
    • Rejected: Run the window in a dry run. A patch is a request, and a dry run makes no request.
    • Rejected: Skip the step in a dry run. The operator cannot see what the apply would do to the Clusters.
  • What does the audit record of an apply hold now?: Each apply writes one audit record, infra.apply. The step adds the namespace and name of each Cluster of the window to the record of the host. [sources: CONTEXT.md]
  • Does the repository already hold an ignoreDifferences block, and where?: k8s/argocd/bootstrap/cluster.yaml holds an ignoreDifferences block, and src/devops_cli/config/constants.py names the same field. [sources: k8s/argocd/bootstrap/cluster.yaml, src/devops_cli/config/constants.py]
  • Which test file covers devops infra apply?: tests/commands/test_infra_apply.py covers the apply with a fake kubectl. The tests of the window go in that file. [sources: tests/commands/test_infra_apply.py]
  • Where does the step read the agent access level of the infra repo?: AgentAccess in devops_cli.infra.access holds the levels none, plan, safe and full. The setting infra.repos names the level of each repo, and a repo with no level is at none. [sources: src/devops_cli/config/settings.py, CONTEXT.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#5125

Activity

  1. added
    source/agent
    type/feature
    scope/infra
    status/new
    value/medium
    effort/medium
    on Nov 12, 2026
  2. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 12, 2026
  4. devops-cli-service commented on Nov 17, 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. dan-petty commented on Nov 18, 2026

    @dan-petty
    OwnerAuthor

    Evidence 2026-11-18: the same budgets stopped an apply again. Apply 4d0bfc44cd6e49749758147a7e7aad64 of plan 8eb73261ff21... (playbook ansible/playbooks/03_k3s.yaml, class service-restart:k3s, host <control-plane-node>) stopped at the drain check. kubectl get pdb -A shows 0 allowed disruptions for llm/llm-gateway-db-primary and mattermost/mattermost-db-primary. The merged kubelet change of dan-petty/homelab is not on the server node.

    A k3s restart does not stop the pods (KillMode=process), so #6338 proposes a cordon with no drain for it. This item stays necessary for a reboot-class change of that node.

  6. devops-cli-service commented on Nov 19, 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:

    • CloudNativePG nodeMaintenanceWindow reusePVC drain node single instance cluster, results: 5
    • kubectl drain blocked PodDisruptionBudget allows 0 disruptions automation tool, results: 5
    • github cloudnativepg plugin kubectl-cnpg, results: 5
    • cnpg kubectl plugin maintenance set reusePVC documentation, results: 5
    • kubernetes node drain tool PodDisruptionBudget, results: 5
    • CloudNativePG node maintenance window, results: 5
    • cloudnative-pg, results: 5
    • kured draino automatic node drain daemon, results: 5
    • kubectl cnpg maintenance set reusePVC, results: 5
    • nodeMaintenanceWindow cloudnative-pg.io documentation, results: 5

    Sources:

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

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

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

    @devops-cli-service
    Contributor

    Live since 2026-11-24 13: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/p2-mediumscope/infrasource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions