Repository navigation
Description
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:
- 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). - 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.
- Set
spec.nodeMaintenanceWindow: {inProgress: true, reusePVC: true}on each (the CloudNativePG supported path; never a change of a PodDisruptionBudget), only at agent accessfulland only when the plan is disruptive on that node. - After the uncordon, set
inProgress: false, and wait until each cluster reportsCluster in healthy statewith its primary Ready, with the boundinfra.node_ready_timeout_seconds. A cluster that does not come back stops the apply. - Argo CD: read the Application that tracks each Cluster (
argocd.argoproj.io/tracking-id). When the field is in git, or the Application hasselfHealand a diff would revert it, refuse with the step (anignoreDifferencesentry for/spec/nodeMaintenanceWindow), and never turn offselfHealfrom the CLI. --dry-runlists 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
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.instances1 whose primary Pod runs on the disruptive node, and the agent access level of the infra repo isfull - THEN the apply patches that Cluster before it runs
kubectl drain --dry-run=serverfor 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
inProgresstofalseon 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 statewith 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.instances2 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
safeand 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
selfHealand noignoreDifferencesentry for/spec/nodeMaintenanceWindow - THEN the apply stops the host before it patches the Cluster and names the missing
ignoreDifferencesentry
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-runand 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 cnpgplugin, a change of the PodDisruptionBudget, orkubectl drain --disable-eviction?: Patchspec.nodeMaintenanceWindowon the Cluster withkubectl 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 patchofspec.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.
- Chosen:
- Which CloudNativePG Clusters of the node get a window?: Only the Clusters with
status.instances1 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.instances1 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.
- Chosen:
- 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 withininfra.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 whenselfHealand a diff would revert it, and name theignoreDifferencesentry for/spec/nodeMaintenanceWindowthat fixes it. Never turn offselfHealfrom the CLI. (best practice) [sources: k8s/argocd/bootstrap/cluster.yaml, src/devops_cli/config/constants.py]- Chosen: Refuse the host and require an
ignoreDifferencesentry. The repository already usesignoreDifferencesink8s/argocd/bootstrap/cluster.yaml, and the guard changes no shared setting. - Rejected: Set
selfHeal: falseon 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.
- Chosen: Refuse the host and require an
- What does
--dry-rundo 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
ignoreDifferencesblock, and where?:k8s/argocd/bootstrap/cluster.yamlholds anignoreDifferencesblock, andsrc/devops_cli/config/constants.pynames 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.pycovers 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?:
AgentAccessindevops_cli.infra.accessholds the levelsnone,plan,safeandfull. The settinginfra.reposnames the level of each repo, and a repo with no level is atnone. [sources: src/devops_cli/config/settings.py, CONTEXT.md]
Fit
Fits in one pull request.
Suspected block
None.
Activity
dan-petty commentedon Nov 12, 2026
Both add node maintenance operations to the infra tool; #5128 adds standalone drain, uncordon, restart and reboot, while this adds a CNPG window step inside the apply flow.devops-cli-service commentedon Nov 17, 2026
Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.
dan-petty commentedon Nov 18, 2026
Evidence 2026-11-18: the same budgets stopped an apply again. Apply
4d0bfc44cd6e49749758147a7e7aad64of plan8eb73261ff21...(playbookansible/playbooks/03_k3s.yaml, classservice-restart:k3s, host<control-plane-node>) stopped at the drain check.kubectl get pdb -Ashows 0 allowed disruptions forllm/llm-gateway-db-primaryandmattermost/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.devops-cli-service commentedon Nov 19, 2026
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:
Sources:
devops-cli-service commentedon Nov 19, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
feat(infra): open a CloudNativePG window to drain a node (#5267)
feat(infra): open a CloudNativePG window to drain a node (#5267)
devops-cli-service commentedon Nov 24, 2026
Released in v0.209.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.209.0
devops-cli-service commentedon Nov 24, 2026
Live since 2026-11-24 13:45 UTC