Forked from tommeramber/CronJob-delete-kyveno-events.yaml
Created
September 20, 2024 23:09
-
-
Save nanox/9eccc0669a22b9d5d80eab08b534f74d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: batch/v1 | |
kind: CronJob | |
metadata: | |
name: kyverno-events-cleanup | |
namespace: openshift-ops # Infra-only-namespace | |
spec: | |
schedule: "*/10 * * * *" | |
concurrencyPolicy: Forbid #do not allow the creation of new job before the previous one had finished | |
jobTemplate: | |
spec: | |
template: | |
spec: | |
serviceAccountName: my-cronjob-service-account # I have elevated privileges | |
containers: | |
- name: kyverno-events-cleanup | |
image: quay.io/tamber/container-tools:latest #Hi that's my utility tool image! | |
imagePullPolicy: IfNotPresent | |
command: | |
- /bin/sh | |
- -c | |
- | | |
for ns in $(oc get ns --no-headers | awk '{print $1}'); do | |
echo Namespace: $ns | |
for name in $(oc get clusterpolicies.kyverno.io --no-headers | awk '{print $1}'); do | |
oc get events -n $ns -o json | jq -r '.items[].metadata.name' | grep "^$name" | xargs -n 1 oc -n $ns delete event ; | |
done ; | |
done | |
exit 0; | |
restartPolicy: OnFailure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment