Automation rules file
.kube-agents/automation.yaml in your GitOps repository lists the kinds of kube-agents fix your
pipeline may merge without a human review, and in which environments. Nothing is allowed unless an
allow rule names it, a deny rule beats every allow rule, and a file kube-agents cannot read in full
allows nothing.
kube-agents reads the file only when the install’s KUBEAGENTS_AUTOMERGE switch is practice or
on. The switch is an entry in the PlatformAgent’s spec.deployment.env, and it defaults to off
(credential isolation lists where it reaches). On a
chart, install.sh or Terraform install, set it through the chart value
platformAgent.deployment.env. On an install.sh install, that is a line in install.env:
TF_VAR_extra_helm_values='{platformAgent={deployment={env=[{name="KUBEAGENTS_AUTOMERGE",value="practice"}]}}}'There is one such line for every extra chart value, so merge this entry into one already there (Operator settings covers the line and a hand-driven Terraform or Helm install). A hand edit of the CR can be lost at the next chart apply. With it off the file is never opened. Adding the file changes nothing until the switch is turned on. kube-agents never merges a pull request itself: the file is input to your own pipeline’s merge decision.
Format
Section titled “Format”version: 1automerge: allow: - fix: no-pdb environments: [dev] - max_risk: low environments: [test] - max_risk: medium environments: [dev] deny: - fix: "*" environments: [prod]version is required and must be 1. automerge holds two optional lists, allow and deny. A
file with only version: 1 is valid and allows nothing.
Each rule has environments plus one target selector:
fix: the kind of fix, named by the audit check that finds the problem. The one kind today isno-pdb, which adds a missing PodDisruptionBudget. A rule naming any other kind refuses the whole file.max_risk(inallowrules only): the highest deterministic pull request risk level (lowormedium) permitted for unattended auto-merge indevortestenvironments when the change also hasdisruptiveness: non_disruptive,revertability: easy,supported: true, andeffective_changes: true.high,critical,unknown, and*are refused inallowrules. Non-dev environments such asstagingandprodare refused onmax_riskrules and require provenfixrecipes.risk(indenyrules only): denies risk-based auto-merge at or above that risk level (low,medium,high,critical, or*). Adenyrule withfix: "*"denies both recipe fixes and risk-based rules in those environments.environments: a non-empty list of environment names, written as GKE label values (lowercase letters, digits,_and-, at most 63 characters).
* matches every fix, risk level, or environment, in deny rules only. An allow rule must name its
fix or max_risk level and its environments, so a new kind of fix, or a new environment, never
merges unattended because of a rule written before it existed.
Risk-based auto-merge stays off by default even when KUBEAGENTS_AUTOMERGE is on for no-pdb.
An install admin must set KUBEAGENTS_AUTOMERGE_MAX_RISK to low or medium to opt in (off or unset disables it).
max_risk rules obey the Autonomy dial’s top-level Auto-merge ceiling, while sitting outside per-recipe clean-merge counters on the dial panel.
Post-merge health verification and automatic step-down currently cover registered fix recipes (no-pdb) only, not max_risk merges.
Run KUBEAGENTS_AUTOMERGE=practice in dev or test before turning on (reason-code post-merge health tracking is a planned follow-up).
The credential broker computes risk:low, risk:medium, risk:high, risk:critical, or risk:unknown labels on GitHub and Gitea; callers cannot modify any risk:* label.
Unrendered Helm, Kustomize, or Terraform changes record an unsupported kube-agents/risk commit status without adding a risk:unknown label.
The environment of a fix
Section titled “The environment of a fix”For changes under clusters/<cluster>/, kube-agents resolves the cluster across GKE_PROJECT_ID (or comma-separated GKE_PROJECTS) and reads its environment resource label. When that label is not
set, kube-agents reads env, then stage, then tier, the same keys the fleet-drift audit groups
clusters by. The value is compared exactly as written: fleet drift reads production as prod,
this file does not, so a rule names the label value your clusters carry. A cluster with none of
these labels has no environment, and no rule matches it.
For repositories organized by directory or branch rather than clusters/<cluster>/, declare an optional top-level environments mapping:
environments: dev: paths: ["envs/dev/**", "apps/*/envs/dev/**"] branches: [main]Every changed file in the pull request must match at least one glob in paths (and target a branch in branches when set). If zero or multiple declared environments match, evaluation fails closed.
How a fix is decided
Section titled “How a fix is decided”- The switch is
off: not allowed. The file is not read. - The file is absent: not allowed.
- The file is refused: not allowed. See the next section.
- No single environment can be verified from
clusters/<cluster>/resource labels or from a declaredenvironmentsentry: not allowed. - For risk-based rules (
max_risk), the credential broker classifies the pull request from git across four orthogonal axes before consulting allow/deny rules:risk_level:low | medium | high | critical | unknown(onlylowormediumcan qualify, capped byKUBEAGENTS_AUTOMERGE_MAX_RISK, which must belowormedium).blast_radius:low | medium | high | critical | unknown.revertability:easy | moderate | difficult | irreversible | unknown(auto-merge requireseasy).disruptiveness:non_disruptive | disruptive | destructive | unknown(auto-merge requiresnon_disruptive). Auto-merge also requiressupported: true,effective_changes: true, andstale_base: false(if the base branch modified any of the same files since the pull request branched, a rebase is required). Registered fix-recipe pull requests (both added and edited manifests, such asno-pdb) are always evaluated under their recipe rule and live cluster safety checks, never viamax_risk.
- A deny rule matches the fix or risk level and the environment: not allowed.
- An allow rule matches the fix or
max_riskthreshold and the environment: allowed. - Otherwise: not allowed.
When the file is refused
Section titled “When the file is refused”Any one of these refuses the whole file, never just the rule it is in, so a misspelt key or fix kind in a deny rule cannot leave the allow rules beside it in force. A misspelt environment name cannot be caught this way: it is a valid label value that matches no cluster.
- It is not YAML, is larger than 64 KiB, or is not UTF-8.
.kube-agentsor the file is a symbolic link.versionis missing or is not the number1.- A key is unknown or appears twice, at any level. YAML merge keys (
<<) are not supported. - A rule is missing
environments, omits a selector (fixormax_riskinallow;fixorriskindeny), or sets more than one selector on the same rule. - A rule names an unknown fix kind or invalid risk level, has an environment that is not a label
value, sets
max_riskon a non-dev/test environment (such asstagingorprod), or uses*inside anallowrule. - An
environmentsentry omits bothpathsandbranches, or contains an invalid relative glob or branch name.
The auto-merge labels
Section titled “The auto-merge labels”With the switch practice or on, each time the fleet audit opens or refreshes a pull request for a
no-pdb fix, kube-agents’ credential broker judges it. When all of these hold it adds a label,
kube-agents:would-auto-merge under practice and kube-agents:auto-merge under on:
- The pull request is open and was opened by kube-agents.
- It adds one file and changes nothing else, and that file is, byte for byte, the
PodDisruptionBudget the audit generates:
maxUnavailable: 1over the workload’s own selector. The file sits in its cluster’s own directory,clusters/<cluster>/, as in the reference layout. - The pull request targets the repository’s base branch, and this file, read from that branch,
allows
no-pdbin the cluster’s environment. - The cluster, read at that moment, passes three safety checks. The workload has at least two replicas and all of them are Ready. No other PodDisruptionBudget selects its pods or has the new one’s name. The new budget’s selector is the workload’s live selector and selects no other workload’s pods.
For general GitOps pull requests opened by kube-agents (proposal-create) or updated via publish,
the broker also runs deterministic git risk classification (proposal-risk-label):
- The pull request is open, originates from the managed repository (not a fork), was opened by kube-agents, and targets the repository’s base branch at a verified head commit SHA.
- The broker applies the computed
risk:low,risk:medium,risk:high,risk:critical, orrisk:unknownlabel, removes any stalerisk:*label, and posts akube-agents/riskcommit status on the head SHA citing the base SHA and reason codes. - The broker checks
KUBEAGENTS_AUTOMERGE_MAX_RISK(lowormedium) and.kube-agents/automation.yamlon the base branch for a matchingmax_riskrule in the verified cluster environment. It also requiresdisruptiveness: non_disruptive,revertability: easy,supported: true,effective_changes: true, andstale_base: false. When all hold, it records a greenkube-agents/auto-mergecommit status on the head SHA (on) and applieskube-agents:would-auto-merge(practice) orkube-agents:auto-merge(on, when the autonomy dial allows auto-merge).
A pull request that carries a label and no longer qualifies loses it when re-evaluated, which
includes after the switch is turned back to off or if a pull request is retargeted. A change of
switch value swaps one label for the other. While the autonomy dial is below Auto-merge,
kube-agents:auto-merge is held back and a carried one comes off. The broker reads all of this
itself, verifies the head commit SHA before and after applying labels, and refuses any caller request
to add, remove, or create kube-agents:* auto-merge or risk:* labels.
Before pushing a new commit in publish, the broker strips carried risk:* and auto-merge labels,
then re-evaluates the pushed head SHA. Your auto-merge pipeline should require the green
kube-agents/auto-merge commit status on the current head SHA (plus up-to-date base branches or a merge
queue), rather than merging on the kube-agents:auto-merge label alone.
GitHub, GitLab, and Bitbucket branch protection cannot exempt pull requests from required human approvals by path or label. GitHub auto-merge and merge queues also enforce required review counts even for ruleset bypass actors. Unattended max_risk auto-merge therefore requires a dedicated zero-approval dev or test branch or repository gated on CI and the kube-agents/auto-merge commit status.
Commit statuses (kube-agents/risk and kube-agents/auto-merge) are posted on GitHub, Gitea, GitLab, Bitbucket Cloud, and Bitbucket Data Center. Pull request labels are applied only on GitHub and Gitea. Bitbucket has no labels, and on GitLab a /label line in a comment or a description sets a
label, so no label there is kube-agents’ alone. Under practice the label is the whole effect:
compare the pull requests that carry it with the ones your team merged. Under on your pipeline may
merge a pull request that carries kube-agents:auto-merge or a green kube-agents/auto-merge commit status. kube-agents merges nothing in either
mode.
When an auto-merged fix is still broken
Section titled “When an auto-merged fix is still broken”A fix that carries the kube-agents:auto-merge label merged without a human review. When it has
merged and kube-agents’ after-merge check finds the problem still there, it opens pull requests
against the branch the fix merged into, and comments once on the fix to link them:
platform-agent/revert-<number>undoes the fix’s changes, whether it merged as a merge commit, a squash or a rebase. The label decides this, so turning the switch off after a bad auto-merge still gets the revert.- With the switch
on,platform-agent/automerge-step-down-<number>adds a deny rule for that kind of fix in that environment to this file. It edits the file in place and keeps everything else you wrote; in a block-style file a comment above the rule names the fix. Delete the rule later to allow those fixes again. Underofforpracticenothing else merges unattended, so no rule is proposed and the comment says so.
Both go through your normal review; kube-agents merges neither. Until the rules change merges, fixes of that kind can still merge on their own. A fix a person merged gets only the after-merge report.
When one of the two cannot be made, the comment says why and the other still opens. The revert is skipped when the fix’s changes no longer undo cleanly, for example because someone already reverted it. The rules change is skipped when the file is absent or refused on that branch, already denies that kind there, or is laid out in a way kube-agents cannot add a rule to. A failure that persists is tried again on later runs, five attempts in all; then kube-agents comments once on the fix with what did and did not open, and stops.
Check a file or classify a pull request
Section titled “Check a file or classify a pull request”In the install’s shell sandbox (the <name>-shell Pod), where the agent’s checkouts live:
# Check a recipe fix rule:python3 /opt/defaults/scripts/automation_rules.py <checkout> --fix no-pdb --environment dev
# Check a risk-based rule across risk_level, disruptiveness, and revertability:KUBEAGENTS_AUTOMERGE_MAX_RISK=low python3 /opt/defaults/scripts/automation_rules.py <checkout> \ --risk low --disruptiveness non_disruptive --revertability easy --environment test
# Deterministically classify an open or merged pull request via the credential broker (read-only):python3 /opt/defaults/scripts/vcs_client.py proposal-classify-risk <number> --repo <owner/name> --format summaryautomation_rules.py prints the parsed rules, the reason a file was refused, and the decision for
the fix or risk evaluation and environment given, as JSON. It exits 1 when the file is refused. With
the switch off it reports switch-off without reading the file. vcs_client.py proposal-classify-risk
returns the full 4-axis classification (risk_level, blast_radius, revertability,
disruptiveness), risk_label, driving reasons, and automerge eligibility as JSON (default) or
as a concise multi-line summary (--format summary).
The parser is
agents/platform/scripts/automation_rules.py,
and the reference repository layout carries an
example file.
Protect the file the way the reference layout protects all of .kube-agents/: a CODEOWNERS entry
that requires a human review for every change to it (examples/gitops-repo/CODEOWNERS.example).