From ace107384de548d060005c5845face670225a06a Mon Sep 17 00:00:00 2001 From: Victor Morales Date: Wed, 8 Jan 2025 20:50:20 -0800 Subject: [PATCH] Enable arc garbage collector --- _chart_installers.sh | 1 + resources/arc-cleanup.yml | 61 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 resources/arc-cleanup.yml diff --git a/_chart_installers.sh b/_chart_installers.sh index de009a29..61c0bb59 100755 --- a/_chart_installers.sh +++ b/_chart_installers.sh @@ -277,6 +277,7 @@ function _install_chart_k8sgpt-operator { function _install_arc_controller { KRD_CHART_VERSION=$(_get_version action_runner_controller) _install_chart arc oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller + kubectl apply -f resources/arc-cleanup.yml } # install_arc() - Install Actions Runner diff --git a/resources/arc-cleanup.yml b/resources/arc-cleanup.yml new file mode 100644 index 00000000..17cda795 --- /dev/null +++ b/resources/arc-cleanup.yml @@ -0,0 +1,61 @@ +--- +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2025 +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +apiVersion: v1 +kind: ServiceAccount +metadata: + name: cleaner + namespace: arc-system +--- +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: cleaner +rules: + - apiGroups: ["actions.github.com"] + resources: ["ephemeralrunners"] + verbs: ["delete", "get", "watch", "list"] +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: cleaner-to-cleaner +roleRef: + kind: ClusterRole + name: cleaner + apiGroup: rbac.authorization.k8s.io +subjects: + - kind: ServiceAccount + name: cleaner + namespace: arc-system +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: cleanup-pipelineruns + 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 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 "{}"