Repository navigation
Migrate require-baseline-workers-for-hcloud-volumes to ValidatingPolicy #5150
Description
🤖 Generated by the Agentic Engineer
Evidence and problem
Part of the Kyverno 1.20 migration (#4996): require-baseline-workers-for-hcloud-volumes is still a ClusterPolicy, which Kyverno 1.20 removes. It is one of the last three policies in the epic still on the old kind, and nobody has picked it up yet.
The policy refuses a Pod that mounts an hcloud volume unless the Pod is pinned to the fixed baseline workers. An hcloud volume is not released when its node goes away, so a volume on an autoscaled node gets stuck when that node is reclaimed (this froze the production merge queue for about nine hours on 1 July). It runs in Enforce, with an Audit companion that reports any claim whose storage class could not be read.
It is the only policy in the epic that looks something up in the cluster at admission time (the storage class of each mounted claim). The epic asks to confirm the new kind can express every rule before rewriting it. Checked on 21 October with the Kyverno 1.19.1 CLI: a ValidatingPolicy can read claims through resource.List, and the CLI test can supply those claims from a Context file, so the existing test can keep pinning the same cases.
Smallest useful change
- Rewrite the Enforce rule as one
ValidatingPolicywith the Deny action,failurePolicy: Ignore, Pods on create only, no controller autogen, and with background evaluation on (as the ClusterPolicy has today). It reads the namespace's claims once and keeps the same pinning rules: aprod-worker-*node name, the baseline-worker node selector, or every required node-selector term carrying the baseline-worker label orprod-worker-*hostnames only. - Keep the Audit companion as its own
ValidatingPolicywith the Audit action: it reports a mounted claim that does not exist in the namespace, so a missing lookup stays visible instead of passing silently. - Move the existing CLI tests (hcloud claims and the Longhorn claim fixture) from mocked values to a claim
Contextfile, with the same allow/deny outcome for every pinned case, and add a missing-claim case for the Audit policy. - Delete the
ClusterPolicyin the same change and record both policies by name in the failure-action baseline (Enforce and Audit).
Acceptance criteria
- The CLI tests pass against the new kind with the same outcome for every pinned case, including the Longhorn-claim and no-claim cases.
- The failure-action baseline records the Enforce policy and the Audit companion with their current actions.
-
kyverno test ./testsand the fixture-evaluation check pass in CI. - A read-only evaluation against the Pods running in production shows no Pod newly denied.
- After deploy, both new policies report ready and no
ClusterPolicyof the old name remains.
Priority High, Effort Low (one policy, its tests, one deploy). Service class Risk reduction, inherited from #4996.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fields✅ Done
Activity
chore: agent-claim #5150 nonce=b51adeb2b3edd69a833f4c901b586057