Skip to content

Commit 40815ba

Browse files
Merge pull request #175 from EcovadisCode/aksAdoAgentCleaner
Aks ado agent cleaner
2 parents 55fa5a4 + ab6c940 commit 40815ba

File tree

7 files changed

+103
-0
lines changed

7 files changed

+103
-0
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Select the chart that you are modifying:
1212
- [ ] app-reverse-proxy
1313
- [ ] pact-broker
1414
- [ ] ado-build-agents
15+
- [ ] ado-agent-cleaner
1516
- [ ] event-worker
1617

1718
## Checklist

charts/ado-agent-cleaner/.helmignore

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
description: Helper to clean up stale AKS Azure DevOps agents
3+
name: charts-ado-agent-cleaner
4+
version: 1.0.0
5+
appVersion: "1.0"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: batch/v1
2+
kind: CronJob
3+
metadata:
4+
name: aks-agent-cleaner
5+
namespace: "{{ .Release.Namespace }}"
6+
spec:
7+
schedule: "{{ .Values.cronSettings.schedule }}"
8+
concurrencyPolicy: "{{ .Values.cronSettings.concurrencyPolicy }}"
9+
successfulJobsHistoryLimit: {{ .Values.cronSettings.successfulJobsHistoryLimit }}
10+
failedJobsHistoryLimit: {{ .Values.cronSettings.failedJobsHistoryLimit }}
11+
jobTemplate:
12+
spec:
13+
activeDeadlineSeconds: {{ .Values.cronSettings.activeDeadlineSeconds }}
14+
parallelism: {{ .Values.cronSettings.parallelism }}
15+
template:
16+
metadata:
17+
labels:
18+
azure.workload.identity/use: "true"
19+
spec:
20+
restartPolicy: Never
21+
nodeSelector:
22+
kubernetes.io/os: linux
23+
resources:
24+
{{ toYaml .Values.resources | nindent 14 }}
25+
serviceAccountName: "svc-acc-{{ .Values.podName }}"
26+
containers:
27+
- name: agent-cleaner
28+
image: "{{ .Values.imageName }}"
29+
imagePullPolicy: IfNotPresent
30+
env:
31+
- name: AZP_URL
32+
value: "{{ .Values.devopsOrgUrl }}"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
name: ado-agent-cleaner-role
5+
namespace: "{{ .Release.Namespace }}"
6+
rules:
7+
- apiGroups: [""]
8+
resources: ["pods"]
9+
verbs: ["get", "list", "watch", "delete"]
10+
- apiGroups: [""]
11+
resources: ["pods/log"]
12+
verbs: ["get"]
13+
- apiGroups: [""]
14+
resources: ["secrets"]
15+
verbs: ["get", "watch","list"]
16+
---
17+
apiVersion: rbac.authorization.k8s.io/v1
18+
kind: RoleBinding
19+
metadata:
20+
name: ado-agent-cleaner-binding
21+
namespace: "{{ .Release.Namespace }}"
22+
subjects:
23+
- kind: ServiceAccount
24+
name: "svc-acc-{{ .Values.podName }}"
25+
roleRef:
26+
kind: Role
27+
name: ado-agent-cleaner-role
28+
apiGroup: rbac.authorization.k8s.io
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
annotations:
5+
azure.workload.identity/client-id: "{{ .Values.aadIdentity }}"
6+
meta.helm.sh/release-name: "{{ .Release.Name }}"
7+
meta.helm.sh/release-namespace: "{{ .Release.Namespace }}"
8+
labels:
9+
azure.workload.identity/use: "true"
10+
name: "svc-acc-{{ .Values.podName }}"
11+
namespace: "{{ .Release.Namespace }}"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# User Assigned Azure Identity ID with the permissions on Azure DevOps to read/cleanup agents
2+
aadIdentity: "xxx"
3+
# Azure DevOps Organization URL
4+
devopsOrgUrl: "https://dev.azure.com/org"
5+
# Name of the Pod and Service Account
6+
podName: agent-cleaner
7+
# Container Image Name for the Agent Cleaner
8+
imageName: aksagentcleaner:1.0.0
9+
10+
# Settings specific for the CronJob
11+
cronSettings:
12+
schedule: "*/30 * * * *"
13+
successfulJobsHistoryLimit: 2
14+
failedJobsHistoryLimit: 1
15+
concurrencyPolicy: "Forbid"
16+
parallelism: 1
17+
activeDeadlineSeconds: 1200
18+
19+
# Resource requests and limits for the Agent Cleaner container
20+
resources:
21+
limits:
22+
cpu: 100m
23+
memory: 128Mi
24+
requests:
25+
cpu: 50m
26+
memory: 64Mi

0 commit comments

Comments
 (0)