Mutate policy adding default labels
Auto-inject labels on admission via strategic merge patch; mutate runs before validate
kubectl apply -f - <<'EOF'
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: add-team-label
spec:
rules:
- name: add-label
match:
any:
- resources:
kinds: [Pod]
mutate:
patchStrategicMerge:
metadata:
labels:
team: "{{request.userInfo.username}}"
EOF
- tool
- kyverno5 commands
More kyverno commands
-
kubectl get cpol,pol -A -o custom-columns='NAME:.metadata.name,ACTION:.spec.validationFailureAction,READY:.status.ready'Show every Kyverno policy with enforce/audit mode and ready state at a glance
-
kyverno apply policy.yaml --resource resource.yaml --policy-reportDry-run a policy on a manifest without a cluster; emits a PolicyReport for CI gating
-
kyverno test ./tests --remove-color -dExecute kyverno-test.yaml suites asserting resource pass/fail/skip; -d for detailed diff
-
kubectl get polr,cpolr -A -o json | jq -r '.items[].results[] | select(.result=="fail") | "\(.policy)/\(.rule)"' | sort | uniq -cAggregate failing PolicyReport results cluster-wide ranked by count