Journey: Day 2 — a node through the maintenance runbook
Day 2 under the same gate. The runbook for a sick node is the same everywhere: cordon and drain it, repair or replace it, re-certify it, put it back. Usually it is a shell history. Here every step is a Terraform action, the operator’s decisions are asked for and recorded, and which nodes are mid-runbook is in state — one set, any number of names — so a drain that fails halfway is retried from the cordon, not left for someone to notice.
Example: terraform/kubernetes/node-maintenance in turf-examples, written for the cluster
the Deploy AICR journey leaves behind (kind-aicr-1, two workers). Load skill_deployment:
the beats change only values in terraform.tfvars, which is deployment, not authoring. One
beat at a time; end each on a cue.
What it needs: a cluster with a worker to spare and a kubeconfig context for it
(kind-aicr-1; any two-worker cluster works), and kubectl on the engine’s PATH — the
local_command actions run there, not in your shell. If there is no cluster, offer the
Deploy AICR journey first.
Beat 1 — The runbook as a record (start here, tool-free)
Section titled “Beat 1 — The runbook as a record (start here, tool-free)”Say the runbook in one breath — cordon and drain, repair, re-certify, uncordon — and what is
different here: the set var.maintenance is the record, one terraform_data per name.
Show main.tf, which is plain Terraform; the actions are keyed by the cluster’s node names
and each record picks its own node’s step:
resource "terraform_data" "maintenance" { for_each = var.maintenance input = each.key lifecycle { action_trigger { # cordon → drain → confirm empty, this node's events = [after_create] actions = [action.local_command.cordon[each.key], action.local_command.drain[each.key], action.kubewait_condition.drained[each.key]] on_failure = taint # a failure retries from the cordon next run } action_trigger { # leaving the set uncordons events = [before_destroy] actions = [action.local_command.release] } }}and maintenance.turf.hcl, the two steps that are a person’s or yours — Turf splices its
triggers after the resource’s own, so the whole chain runs window → cordon → drain →
drained → repair → ready:
action "turf_action" "window" { config { prompt = "Ask the user whether the maintenance window for node ${caller.input} is open now…" } }action_trigger "window" { target = terraform_data.maintenance events = [before_create] actions = [action.turf_action.window] on_failure = halt }
action "turf_action" "repair" { config { prompt = "Node ${caller.input} is cordoned and drained. Inspect it… Fail if NotReady or missing." } }action_trigger "repair_and_recertify" { target = terraform_data.maintenance events = [after_create] actions = [action.turf_action.repair, action.kubewait_condition.ready[each.key]] # ready: Node Ready=True, held for 10s on_failure = taint}Two things worth a sentence each: the turf actions read their node from caller, the
record whose step they are, so one declaration serves every name in the set; and in an
overlay’s trigger each.key is the target record’s own, so the Ready wait is keyed like the
steps in main.tf. A name that is not a node has no step and fails the plan before anything
is touched.
Your cue — “set it up.”
Beat 2 — Register and bind
Section titled “Beat 2 — Register and bind”- Write
terraform.tfvarsin the example directory (git-ignored):kubeconfig_context = "kind-aicr-1",maintenance = []. init({ path: "<examples>/terraform/kubernetes/node-maintenance", config_alias: "day2" })—kubernetes,kubewaitandlocalinstall.open({ config_alias: "day2", workspace_alias: "day2" }).up({ workspace_alias: "day2" })→ nothing to do (the set is empty); the data source read the nodes. Showoutput nodesif the user wants.
Your cue — “take the worker out.”
Beat 3 — Into maintenance
Section titled “Beat 3 — Into maintenance”Edit terraform.tfvars: maintenance = ["aicr-1-worker"]. Say so. Then:
up({ workspace_alias: "day2" })→ 1 to add, andplan.invocationslists six invocations onterraform_data.maintenance["aicr-1-worker"], in the order they run:window(before_create, halt), thencordon["aicr-1-worker"],drain[…],drained[…],repair,ready["aicr-1-worker"](after_create, taint). Read that list to the user: that is the runbook, planned, each keyed step resolved to this node.- Get the yes;
apply. The call returnsawaiting_actionsat once — the window: ask the user whether the maintenance window foraicr-1-workeris open. Quote them. Answer (succeeded: truewith their words inprogress; a “no” fails with their reason and nothing is cordoned). - The apply goes on:
kubectl cordon,kubectl drain --ignore-daemonsets --delete-emptydir-data --timeout=10m, thenkubewait_condition.drainedconfirms nothing an eviction can keep off the node remains. One honest line here: the AICR component defaults give its runtime operators a tolerate-everything toleration on every platform (a recipe narrows it with--system-node-toleration), so the scheduler may put an evicted operator straight back on the cordoned node — the wait does not count those, as it does not count DaemonSet pods. The tenant’s workloads are what a drain moves; on this cluster there are none yet. Then it stops again — the repair: runkubectl describe node aicr-1-workerwith the flags ininputs, report the conditions and anything notable asprogresslines, and say the honest thing: in a datacenter this is where the provider’s host playbook runs; here there is nothing to repair. Answer. kubewait_condition.readyholds until the node reportsReady=Truefor ten seconds.converged.output in_maintenance→["aicr-1-worker"].
Your cue — “put it back.”
Beat 4 — Back in service
Section titled “Beat 4 — Back in service”Edit terraform.tfvars: maintenance = []. up → 1 to destroy, one invocation:
release on before_destroy. Approve; apply. release reads the node from caller —
the record being destroyed — and runs kubectl uncordon. kubectl --context kind-aicr-1 get nodes shows it schedulable.
Make the point in a sentence: every step is in the record — what was asked, what was answered, what ran — and the next run starts from a known state. If the user asks about more than one node: name two and the plan is two adds and twelve invocations, each record’s steps its own node’s, and a record already in the set is left alone; a record whose node has since left the cluster plans clean and, taken out of the set, is released with “nothing to uncordon”.
Your cue — “what if the drain fails?” or “wrap it up.”
Beat 5 — A drain that fails
Section titled “Beat 5 — A drain that fails”Triggered by: the user wanting to see the retry.
Create a PodDisruptionBudget on the cluster that allows no evictions for a deployment on
the worker (e.g. minAvailable equal to its replicas), and set
drain_flags = ["--ignore-daemonsets", "--delete-emptydir-data", "--timeout=20s"] in
terraform.tfvars. Put the node back in the set, up, approve, answer the window, and
watch the drain fail: the run ends failed, rounds[].actions names the drain, the record
is tainted, and the node stays cordoned — nothing after the drain ran. Remove the budget;
up → the plan replaces the tainted record (1 to add, 1 to destroy, with release a
no-op on the old one because the node is still in the set); approve; the steps run again
from the cordon. Then empty the set and up to release it.
Close: close({ workspace_alias: "day2" }). If the AICR workspace is still open,
offer its teardown now (Deploy AICR, beat 5), or leave the cluster for another journey.
Turf™ is a trademark of Turf LLC. Terraform® is a trademark of HashiCorp. Ansible® is a trademark of Red Hat, LLC, registered in the United States and other countries. Helm®, Kubernetes®, Prometheus® and OpenTelemetry® are registered trademarks, and Jaeger™ is a trademark, of the Linux Foundation. OpenTofu® and Model Context Protocol® are registered trademarks of LF Projects, LLC. All other trademarks are the property of their respective owners. Turf is not affiliated with, endorsed by, or sponsored by HashiCorp, IBM, Red Hat, the Linux Foundation, LF Projects or the OpenTofu project.
© 2026 Turf LLC. Free for individuals, education and small businesses within the Community limits, under the Turf Community Edition License 1.0. Government and larger organizations need a commerciallicense.turf.build · Discord ·GitHub