Skip to content

Commit

Permalink
Include vmi removal in arc garbage collector
Browse files Browse the repository at this point in the history
  • Loading branch information
electrocucaracha committed Jan 16, 2025
1 parent 6089d72 commit e2cab98
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions resources/arc-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metadata:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cleaner
name: ephemeralrunners-cleaner
rules:
- apiGroups: ["actions.github.com"]
resources: ["ephemeralrunners"]
Expand All @@ -25,10 +25,32 @@ rules:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cleaner-to-cleaner
name: ephemeralrunners-cleaner
roleRef:
kind: ClusterRole
name: cleaner
name: ephemeralrunners-cleaner
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: cleaner
namespace: arc-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: virtualmachineinstances-cleaner
rules:
- apiGroups: ["kubevirt.io"]
resources: ["virtualmachineinstances"]
verbs: ["delete", "get", "watch", "list"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: virtualmachineinstances-cleaner
roleRef:
kind: ClusterRole
name: virtualmachineinstances-cleaner
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
Expand Down Expand Up @@ -59,3 +81,28 @@ spec:
- -c
- |
kubectl get -A ephemeralrunner -o jsonpath='{range .items[?(@.status.reason=="TooManyPodFailures")]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}{end}'|awk '{ print "kubectl delete ephemeralrunner" " -n " $1 " " $2 }'|xargs -P4 -I{} sh -c "{}"
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: virtualmachineinstances-garbage-collector
namespace: arc-system
spec:
schedule: "*/15 * * * *"
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 1
successfulJobsHistoryLimit: 3
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
serviceAccount: cleaner
containers:
- name: kubectl
image: alpine/k8s:1.32.0
command:
- /bin/bash
- -c
- |
kubectl get -A virtualmachineinstance -o jsonpath='{range .items[?(@.status.phase=="Succeeded")]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}{end}'|awk '{ print "kubectl delete virtualmachineinstance" " -n " $1 " " $2 }'|xargs -P4 -I{} sh -c "{}"

0 comments on commit e2cab98

Please sign in to comment.