Repository navigation
Migrate the namespace-default generation ClusterPolicies to GeneratingPolicy without a gap #4999
Description
🤖 Generated by the Agentic Engineer (interactive Claude Code session)
Evidence and problem
Kyverno 1.20 is planned to remove ClusterPolicy (#4984). These 4 generation policies in k8s/bases/infrastructure/cluster-policies/best-practices/ create per-namespace defaults; each must exist as a GeneratingPolicy (policies.kyverno.io) before 1.20 is installed:
add-default-deny, add-default-limitrange, add-ns-quota, auto-vpa.
All four use synchronize: true, so Kyverno owns the objects they created in every namespace and keeps them in step. add-default-deny, add-default-limitrange and add-ns-quota have no Kyverno CLI test.
What has to be decided before this is Ready
How the objects the old policies generated pass to the new ones without being deleted and recreated. A synchronised downstream object is tied to the policy that generated it; deleting that ClusterPolicy could remove the default-deny network policy, limit range or quota from every namespace before the new policy recreates it, which is a gap in isolation and in resource limits. Read Kyverno 1.19's documented behaviour for deleting a synchronising generate policy and for a GeneratingPolicy adopting existing objects, and record the safe sequence here (for example, turning off synchronisation on the old policy first, in its own deploy). Then list the PRs that sequence needs.
How every migration batch works
- Test first. Of the 49
ClusterPolicymanifests, 28 are named in notests/**/kyverno-test.yaml(counted 2026-10-17 by policy name). Before rewriting a policy, add a Kyverno CLI test that pins its current behaviour — at least one resource it must act on and one it must leave alone — and see it pass against theClusterPolicy. The same test, pointed at the new kind, must pass unchanged in its expected results. - Keep the action. Each rewritten policy keeps its failure action as recorded in
tests/policy-failure-actions.json(Enforce stays Enforce, Audit stays Audit), its match scope and its exclusions. - No gap in enforcement. Add the new policy and delete the
ClusterPolicyin the same PR, so Flux applies the replacement before it prunes the old one. Kinds whose two versions could both act on the same request (mutation or generation) say how double application is avoided. - Confirm the capability first. For each rule, confirm the replacement kind can express it at Kyverno 1.19.1 (the running version). A rule it cannot express is recorded on Migrate Kyverno ClusterPolicy and Policy before Kyverno 1.20 removes them #4984 and blocks only that policy, not the batch.
- Validate with
kyverno test ./testsandscripts/validate-kyverno-fixture-evaluation.sh(CI's⚖️ Validate cluster policiesstep), the layer builds inplatform/AGENTS.md, and after deploy a read-only check that each new policy reports ready and the old one is gone.
Acceptance criteria
- The handover sequence above is recorded, with its source in the Kyverno documentation.
- Every policy has a CLI test that passed against the
ClusterPolicybefore the rewrite. - Each is a
GeneratingPolicywith the same scope and generated objects, and the oldClusterPolicyis gone after deploy. - After every deploy in the sequence, each namespace still has its default-deny network policy, limit range and quota, read from the live cluster; none was deleted and recreated.
Priority High, Effort Medium, Service class Risk reduction. Losing the default-deny policy in every namespace at once is the worst single outcome of the migration; kept in Backlog until the handover is decided. Part of #4984.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Effort
Projects
- StatusShow more project fields📥 Backlog
Activity