mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-10 11:41:27 +00:00
Compare commits
341 Commits
actions-ru
...
v0.24.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ef9a22cd4 | ||
|
|
933b0c7888 | ||
|
|
1b7ec33135 | ||
|
|
a62882d243 | ||
|
|
0cd13fe51d | ||
|
|
01c8dc237e | ||
|
|
7c4db63718 | ||
|
|
3d88b9630a | ||
|
|
1152e6b31d | ||
|
|
ac27df8301 | ||
|
|
9dd26168d6 | ||
|
|
18bfb28c0b | ||
|
|
84210e900b | ||
|
|
ef3313d147 | ||
|
|
c7eea169ad | ||
|
|
63be0223ad | ||
|
|
5bbea772f7 | ||
|
|
2aa3f1e142 | ||
|
|
3e988afc09 | ||
|
|
84210f3d2b | ||
|
|
536692181b | ||
|
|
23403172cb | ||
|
|
8a8ec43364 | ||
|
|
78c01fd31d | ||
|
|
bf45aa9f6b | ||
|
|
b5aa1750bb | ||
|
|
cdc9d20e7a | ||
|
|
8035d6d9f8 | ||
|
|
65f7ee92a6 | ||
|
|
fca8a538db | ||
|
|
95ddc77245 | ||
|
|
b5194fd75a | ||
|
|
adf69bbea0 | ||
|
|
b43ef70ac6 | ||
|
|
f1caebbaf0 | ||
|
|
ede28f5046 | ||
|
|
f08ab1490d | ||
|
|
772ca57056 | ||
|
|
51b13e3bab | ||
|
|
81017b130f | ||
|
|
bdbcf66569 | ||
|
|
0e15a78541 | ||
|
|
f85c3d06d9 | ||
|
|
51ba7d7160 | ||
|
|
759349de11 | ||
|
|
3014e98681 | ||
|
|
5f4be6a883 | ||
|
|
b98f470a70 | ||
|
|
e46b90f758 | ||
|
|
3a7e8c844b | ||
|
|
65a67ee61c | ||
|
|
215ba36fd1 | ||
|
|
27774b47bd | ||
|
|
fbde2b9a41 | ||
|
|
212098183a | ||
|
|
4a5097d8cf | ||
|
|
9c57d085f8 | ||
|
|
d6622f9369 | ||
|
|
3b67ee727f | ||
|
|
e6bddcd238 | ||
|
|
f60e57d789 | ||
|
|
3ca1152420 | ||
|
|
e94fa19843 | ||
|
|
99832d7104 | ||
|
|
289bcd8b64 | ||
|
|
5e8cba82c2 | ||
|
|
dabbc99c78 | ||
|
|
d01595cfbc | ||
|
|
c1e5829b03 | ||
|
|
800d6bd586 | ||
|
|
d3b7f0bf7d | ||
|
|
dbcb67967f | ||
|
|
55369bf846 | ||
|
|
1f6303daed | ||
|
|
0fd1a681af | ||
|
|
58416db8c8 | ||
|
|
78a0817c2c | ||
|
|
9ed429513d | ||
|
|
46291c1823 | ||
|
|
832e59338e | ||
|
|
70ae5aef1f | ||
|
|
6d10dd8e1d | ||
|
|
61c5a112db | ||
|
|
7bc08fbe7c | ||
|
|
4053ab3e11 | ||
|
|
059481b610 | ||
|
|
9fdb2c009d | ||
|
|
9f7ea0c014 | ||
|
|
0caa0315c6 | ||
|
|
1c726ae20c | ||
|
|
d6cdd5964c | ||
|
|
a622968ff2 | ||
|
|
e8ef84ab76 | ||
|
|
1551f3b5fc | ||
|
|
3ba7179995 | ||
|
|
e7c6c26266 | ||
|
|
ebe7d060cb | ||
|
|
c3e280eadb | ||
|
|
9f254a2393 | ||
|
|
e5cf3b95cf | ||
|
|
24aae58dbc | ||
|
|
13bfa2da4e | ||
|
|
cb4e1fa8f2 | ||
|
|
7a5a6381c3 | ||
|
|
81951780b1 | ||
|
|
3b48db0d26 | ||
|
|
352e206148 | ||
|
|
6288036ed4 | ||
|
|
a37b4dfbe3 | ||
|
|
c4ff1a588f | ||
|
|
4a3b7bc8d5 | ||
|
|
8db071c4ba | ||
|
|
7b8057e417 | ||
|
|
960a704246 | ||
|
|
f907f82275 | ||
|
|
7124451cea | ||
|
|
c8f1acd92c | ||
|
|
b0fd7a75ea | ||
|
|
b09c54045a | ||
|
|
96f2da1c2e | ||
|
|
cac8b76c68 | ||
|
|
e24d942d63 | ||
|
|
b855991373 | ||
|
|
e7e48a77e4 | ||
|
|
85dea9b67c | ||
|
|
1d9347f418 | ||
|
|
631a70a35f | ||
|
|
b614dcf54b | ||
|
|
14f9e7229e | ||
|
|
82770e145b | ||
|
|
971c54bf5c | ||
|
|
b80d9b0cdc | ||
|
|
e46df413a1 | ||
|
|
eb02f6f26e | ||
|
|
7a750b9285 | ||
|
|
d26c8d6529 | ||
|
|
fd0092d13f | ||
|
|
88d17c7988 | ||
|
|
98567dadc9 | ||
|
|
7e8d80689b | ||
|
|
d72c396ff1 | ||
|
|
13e7b440a8 | ||
|
|
a95983fb98 | ||
|
|
ecc8b4472a | ||
|
|
459beeafb9 | ||
|
|
1b327a0721 | ||
|
|
1f8a23c129 | ||
|
|
af8d8f7e1d | ||
|
|
e7ef21fdf9 | ||
|
|
ee7484ac91 | ||
|
|
debf53c640 | ||
|
|
9657d3e5b3 | ||
|
|
2cb04ddde7 | ||
|
|
366f8927d8 | ||
|
|
532a2bb2a9 | ||
|
|
f28cecffe9 | ||
|
|
4cbbcd64ce | ||
|
|
a68eede616 | ||
|
|
c06a806d75 | ||
|
|
857c1700ba | ||
|
|
a40793bb60 | ||
|
|
48a7b78bf3 | ||
|
|
6ff93eae95 | ||
|
|
b25a0fd606 | ||
|
|
3beef84f30 | ||
|
|
76cc758d12 | ||
|
|
c4c6e833a7 | ||
|
|
ecf74e615e | ||
|
|
bb19e85037 | ||
|
|
e7200f274d | ||
|
|
1cc06e7408 | ||
|
|
4551309e30 | ||
|
|
7123b18a47 | ||
|
|
cc55d0bd7d | ||
|
|
c612e87d85 | ||
|
|
326d6a1fe8 | ||
|
|
fa8ff70aa2 | ||
|
|
efb7fca308 | ||
|
|
e4280dcb0d | ||
|
|
f153870f5f | ||
|
|
8ca39caff5 | ||
|
|
791634fb12 | ||
|
|
c4b24f8366 | ||
|
|
a1c6d1d11a | ||
|
|
adc889ce8a | ||
|
|
b83db7be8f | ||
|
|
da2adc0cc5 | ||
|
|
fa287c4395 | ||
|
|
7c0340dea0 | ||
|
|
c3dd1c5c05 | ||
|
|
051089733b | ||
|
|
757e0a82a2 | ||
|
|
83e550cde5 | ||
|
|
22ef7b3a71 | ||
|
|
28fccbcecd | ||
|
|
9628bb2937 | ||
|
|
736a53fed6 | ||
|
|
132faa13a1 | ||
|
|
66e070f798 | ||
|
|
55ff4de79a | ||
|
|
301439b06a | ||
|
|
15ee6d6360 | ||
|
|
5b899f578b | ||
|
|
d8c9eb7ba7 | ||
|
|
cbbc383a80 | ||
|
|
b57e885a73 | ||
|
|
bed927052d | ||
|
|
14a878bfae | ||
|
|
c95e84a528 | ||
|
|
95a5770d55 | ||
|
|
9cc9f8c182 | ||
|
|
b7c5611516 | ||
|
|
138e326705 | ||
|
|
c21fa75afa | ||
|
|
34483e268f | ||
|
|
5f2b5327f7 | ||
|
|
a93b2fdad4 | ||
|
|
25570a0c6d | ||
|
|
d20ad71071 | ||
|
|
8a379ac94b | ||
|
|
27563c4378 | ||
|
|
4a0f68bfe3 | ||
|
|
1917cf90c4 | ||
|
|
0ba3cad6c2 | ||
|
|
7f0e65cb73 | ||
|
|
12a04b7f38 | ||
|
|
a3072c110d | ||
|
|
15b402bb32 | ||
|
|
11be6c1fb6 | ||
|
|
59c3288e87 | ||
|
|
5030e075a9 | ||
|
|
3115d71471 | ||
|
|
c221b6e278 | ||
|
|
a8dbc8a501 | ||
|
|
b1ac63683f | ||
|
|
10bc28af75 | ||
|
|
e23692b3bc | ||
|
|
e7f4a0e200 | ||
|
|
828ddcd44e | ||
|
|
fc821fd473 | ||
|
|
4b0aa92286 | ||
|
|
c69c8dd84d | ||
|
|
e42db00006 | ||
|
|
eff0c7364f | ||
|
|
516695b275 | ||
|
|
686d40c20d | ||
|
|
f0fa99fc53 | ||
|
|
6b12413fdd | ||
|
|
3abecd0f19 | ||
|
|
7156ce040e | ||
|
|
1463d4927f | ||
|
|
5bc16f2619 | ||
|
|
b8e65aa857 | ||
|
|
d4a9750e20 | ||
|
|
a6f0e0008f | ||
|
|
79a31328a5 | ||
|
|
4e6bfd8114 | ||
|
|
3c16188371 | ||
|
|
9e356b419e | ||
|
|
f3ceccd904 | ||
|
|
4b557dc54c | ||
|
|
4c53e3aa75 | ||
|
|
0b9bef2c08 | ||
|
|
a5ed6bd263 | ||
|
|
921f547200 | ||
|
|
9079c5d85f | ||
|
|
a9aea0bd9c | ||
|
|
fcf4778bac | ||
|
|
eb0a4a9603 | ||
|
|
b6151ebb8d | ||
|
|
ba4bd7c0db | ||
|
|
5b92c412a4 | ||
|
|
e22d981d58 | ||
|
|
a7b39cc247 | ||
|
|
1e452358b4 | ||
|
|
92e133e007 | ||
|
|
d0d316252e | ||
|
|
b509eb4388 | ||
|
|
59437ef79f | ||
|
|
a51fb90cd2 | ||
|
|
eb53d238d1 | ||
|
|
7fdf9a6c67 | ||
|
|
6f591ee774 | ||
|
|
cc25dd7926 | ||
|
|
1b911749a6 | ||
|
|
b652a8f9ae | ||
|
|
069bf6a042 | ||
|
|
f09a974ac2 | ||
|
|
1f7e440030 | ||
|
|
9d5a562407 | ||
|
|
715e6a40f1 | ||
|
|
81b2c5ada9 | ||
|
|
9ae83dfff5 | ||
|
|
5e86881c30 | ||
|
|
1c75b20767 | ||
|
|
8a73560dbc | ||
|
|
01301d3ce8 | ||
|
|
02679ac1d8 | ||
|
|
1a6e5719c3 | ||
|
|
f72d871c5b | ||
|
|
ad48851dc9 | ||
|
|
c5950d75fa | ||
|
|
de1f48111a | ||
|
|
8a7720da77 | ||
|
|
608c56936e | ||
|
|
4ebec38208 | ||
|
|
0c34196d87 | ||
|
|
83c8a9809e | ||
|
|
c64000e11c | ||
|
|
9bb21aef1f | ||
|
|
7261d927fb | ||
|
|
91102c8088 | ||
|
|
6f51f560ba | ||
|
|
961f01baed | ||
|
|
d0642eeff1 | ||
|
|
473fe7f736 | ||
|
|
84b0c64d29 | ||
|
|
f0fccc020b | ||
|
|
2bd6d6342e | ||
|
|
ea2dbc2807 | ||
|
|
c718eaae4f | ||
|
|
67e39d719e | ||
|
|
bbd328a7cc | ||
|
|
8eb6c0f3f0 | ||
|
|
231c1f80e7 | ||
|
|
3c073c5e17 | ||
|
|
a1cfe3be36 | ||
|
|
898ad3c355 | ||
|
|
164a91b18f | ||
|
|
acb004f291 | ||
|
|
3de4e7e9c6 | ||
|
|
4a55fe563c | ||
|
|
23841642df | ||
|
|
7c4ac2ef44 | ||
|
|
550717020d | ||
|
|
9a5ae93cb7 | ||
|
|
f5175256c6 | ||
|
|
031b1848e0 | ||
|
|
47a17754fd | ||
|
|
85ddd0d137 | ||
|
|
eefb48ba3f |
@@ -11,3 +11,4 @@ charts
|
|||||||
*.md
|
*.md
|
||||||
*.txt
|
*.txt
|
||||||
*.sh
|
*.sh
|
||||||
|
test/e2e/.docker-build
|
||||||
|
|||||||
36
.github/ISSUE_TEMPLATE/bug_report.md
vendored
36
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,36 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a report to help us improve
|
|
||||||
title: ''
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
**Checks**
|
|
||||||
|
|
||||||
- [ ] My actions-runner-controller version (v0.x.y) does support the feature
|
|
||||||
- [ ] I'm using an unreleased version of the controller I built from HEAD of the default branch
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
1. Go to '...'
|
|
||||||
2. Click on '....'
|
|
||||||
3. Scroll down to '....'
|
|
||||||
4. See error
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**Screenshots**
|
|
||||||
If applicable, add screenshots to help explain your problem.
|
|
||||||
|
|
||||||
**Environment (please complete the following information):**
|
|
||||||
- Controller Version [e.g. 0.18.2]
|
|
||||||
- Deployment Method [e.g. Helm and Kustomize ]
|
|
||||||
- Helm Chart Version [e.g. 0.11.0, if applicable]
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context about the problem here.
|
|
||||||
160
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
160
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
name: Bug Report
|
||||||
|
description: File a bug report
|
||||||
|
title: "Bug"
|
||||||
|
labels: ["bug"]
|
||||||
|
body:
|
||||||
|
- type: input
|
||||||
|
id: controller-version
|
||||||
|
attributes:
|
||||||
|
label: Controller Version
|
||||||
|
description: Refer to semver-like release tags for controller versions. Any release tags prefixed with `actions-runner-controller-` are for chart releases
|
||||||
|
placeholder: ex. 0.18.2 or git commit ID
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: chart-version
|
||||||
|
attributes:
|
||||||
|
label: Helm Chart Version
|
||||||
|
description: Run `helm list` and see what's shown under CHART VERSION. Any release tags prefixed with `actions-runner-controller-` are for chart releases
|
||||||
|
placeholder: ex. 0.11.0
|
||||||
|
- type: dropdown
|
||||||
|
id: deployment-method
|
||||||
|
attributes:
|
||||||
|
label: Deployment Method
|
||||||
|
description: Which deployment method did you use to install ARC?
|
||||||
|
options:
|
||||||
|
- Helm
|
||||||
|
- Kustomize
|
||||||
|
- ArgoCD
|
||||||
|
- Other
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: checkboxes
|
||||||
|
id: checks
|
||||||
|
attributes:
|
||||||
|
label: Checks
|
||||||
|
description: Please check the boxes below before submitting
|
||||||
|
options:
|
||||||
|
- label: This isn't a question or user support case (For Q&A and community support, go to [Discussions](https://github.com/actions-runner-controller/actions-runner-controller/discussions). It might also be a good idea to contract with any of contributors and maintainers if your business is so critical and therefore you need priority support
|
||||||
|
required: true
|
||||||
|
- label: I've read [releasenotes](https://github.com/actions-runner-controller/actions-runner-controller/tree/master/docs/releasenotes) before submitting this issue and I'm sure it's not due to any recently-introduced backward-incompatible changes
|
||||||
|
required: true
|
||||||
|
- label: My actions-runner-controller version (v0.x.y) does support the feature
|
||||||
|
required: true
|
||||||
|
- label: I've already upgraded ARC to the latest and it didn't fix the issue
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: resource-definitions
|
||||||
|
attributes:
|
||||||
|
label: Resource Definitions
|
||||||
|
description: "Add copy(s) of your resource definition(s) (RunnerDeployment or RunnerSet, and HorizontalRunnerAutoscaler. If RunnerSet, also include the StorageClass being used)"
|
||||||
|
render: yaml
|
||||||
|
placeholder: |
|
||||||
|
apiVersion: actions.summerwind.dev/v1alpha1
|
||||||
|
kind: RunnerDeployment
|
||||||
|
metadata:
|
||||||
|
name: example
|
||||||
|
spec:
|
||||||
|
#snip
|
||||||
|
---
|
||||||
|
apiVersion: actions.summerwind.dev/v1alpha1
|
||||||
|
kind: RunnerSet
|
||||||
|
metadata:
|
||||||
|
name: example
|
||||||
|
spec:
|
||||||
|
#snip
|
||||||
|
---
|
||||||
|
apiVersion: storage.k8s.io/v1
|
||||||
|
kind: StorageClass
|
||||||
|
metadata:
|
||||||
|
name: example
|
||||||
|
provisioner: ...
|
||||||
|
reclaimPolicy: ...
|
||||||
|
volumeBindingMode: ...
|
||||||
|
---
|
||||||
|
apiVersion: actions.summerwind.dev/v1alpha1
|
||||||
|
kind: HorizontalRunnerAutoscaler
|
||||||
|
metadata:
|
||||||
|
name:
|
||||||
|
spec:
|
||||||
|
#snip
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: reproduction-steps
|
||||||
|
attributes:
|
||||||
|
label: To Reproduce
|
||||||
|
description: "Steps to reproduce the behavior"
|
||||||
|
render: markdown
|
||||||
|
placeholder: |
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: actual-behavior
|
||||||
|
attributes:
|
||||||
|
label: Describe the bug
|
||||||
|
description: Also tell us, what did happen?
|
||||||
|
placeholder: A clear and concise description of what happened.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: expected-behavior
|
||||||
|
attributes:
|
||||||
|
label: Describe the expected behavior
|
||||||
|
description: Also tell us, what did you expect to happen?
|
||||||
|
placeholder: A clear and concise description of what the expected behavior is.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: controller-logs
|
||||||
|
attributes:
|
||||||
|
label: Controller Logs
|
||||||
|
description: "Include logs from `actions-runner-controller`'s controller-manager pod"
|
||||||
|
render: shell
|
||||||
|
placeholder: |
|
||||||
|
To grab controller logs:
|
||||||
|
|
||||||
|
# Set NS according to your setup
|
||||||
|
NS=actions-runner-system
|
||||||
|
|
||||||
|
# Grab the pod name and set it to $POD_NAME
|
||||||
|
kubectl -n $NS get po
|
||||||
|
|
||||||
|
kubectl -n $NS logs $POD_NAME > arc.log
|
||||||
|
|
||||||
|
Upload it to e.g. https://gist.github.com/ and paste the link to it here.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: runner-pod-logs
|
||||||
|
attributes:
|
||||||
|
label: Runner Pod Logs
|
||||||
|
description: "Include logs from runner pod(s)"
|
||||||
|
render: shell
|
||||||
|
placeholder: |
|
||||||
|
To grab the runner pod logs:
|
||||||
|
|
||||||
|
# Set NS according to your setup. It should match your RunnerDeployment's metadata.namespace.
|
||||||
|
NS=default
|
||||||
|
|
||||||
|
# Grab the name of the problematic runner pod and set it to $POD_NAME
|
||||||
|
kubectl -n $NS get po
|
||||||
|
|
||||||
|
kubectl -n $NS logs $POD_NAME -c runner > runnerpod_runner.log
|
||||||
|
kubectl -n $NS logs $POD_NAME -c docker > runnerpod_docker.log
|
||||||
|
|
||||||
|
Upload it to e.g. https://gist.github.com/ and paste the link to it here.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: additional-context
|
||||||
|
attributes:
|
||||||
|
label: Additional Context
|
||||||
|
description: |
|
||||||
|
Add any other context about the problem here.
|
||||||
|
|
||||||
|
Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
|
||||||
15
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
15
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Blank issues are mainly for maintainers who are known to write complete issue descriptions without need to following a form
|
||||||
|
blank_issues_enabled: true
|
||||||
|
contact_links:
|
||||||
|
- name: Sponsor ARC Maintainers
|
||||||
|
about: If your business relies on the continued maintainance of actions-runner-controller, please consider sponsoring the project and the maintainers.
|
||||||
|
url: https://github.com/actions-runner-controller/actions-runner-controller/tree/master/CODEOWNERS
|
||||||
|
- name: Ideas and Feature Requests
|
||||||
|
about: Wanna request a feature? Create a discussion and collect :+1:s first.
|
||||||
|
url: https://github.com/actions-runner-controller/actions-runner-controller/discussions/new?category=ideas
|
||||||
|
- name: Questions and User Support
|
||||||
|
about: Need support using ARC? We use Discussions as the place to provide community support.
|
||||||
|
url: https://github.com/actions-runner-controller/actions-runner-controller/discussions/new?category=questions
|
||||||
|
- name: Need Paid Support?
|
||||||
|
about: Consider contracting with any of the actions-runner-controller maintainers and contributors.
|
||||||
|
url: https://github.com/actions-runner-controller/actions-runner-controller/tree/master/CODEOWNERS
|
||||||
50
.github/actions/setup-docker-environment/action.yaml
vendored
Normal file
50
.github/actions/setup-docker-environment/action.yaml
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
name: "Setup Docker"
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
username:
|
||||||
|
description: "Username"
|
||||||
|
required: true
|
||||||
|
password:
|
||||||
|
description: "Password"
|
||||||
|
required: true
|
||||||
|
ghcr_username:
|
||||||
|
description: "GHCR username. Usually set from the github.actor variable"
|
||||||
|
required: true
|
||||||
|
ghcr_password:
|
||||||
|
description: "GHCR password. Usually set from the secrets.GITHUB_TOKEN variable"
|
||||||
|
required: true
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
sha_short:
|
||||||
|
description: "The short SHA used for image builds"
|
||||||
|
value: ${{ steps.vars.outputs.sha_short }}
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- name: Get Short SHA
|
||||||
|
id: vars
|
||||||
|
run: |
|
||||||
|
echo ::set-output name=sha_short::${GITHUB_SHA::7}
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ inputs.username }}
|
||||||
|
password: ${{ inputs.password }}
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ inputs.ghcr_username }}
|
||||||
|
password: ${{ inputs.ghcr_password }}
|
||||||
25
.github/lock.yml
vendored
25
.github/lock.yml
vendored
@@ -1,25 +0,0 @@
|
|||||||
# Configuration for Lock Threads
|
|
||||||
# Repo: https://github.com/dessant/lock-threads-app
|
|
||||||
# App: https://github.com/apps/lock
|
|
||||||
|
|
||||||
# Number of days of inactivity before a closed issue or pull request is locked
|
|
||||||
daysUntilLock: 7
|
|
||||||
|
|
||||||
# Skip issues and pull requests created before a given timestamp. Timestamp must
|
|
||||||
# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable
|
|
||||||
skipCreatedBefore: false
|
|
||||||
|
|
||||||
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable
|
|
||||||
exemptLabels: []
|
|
||||||
|
|
||||||
# Label to add before locking, such as `outdated`. Set to `false` to disable
|
|
||||||
lockLabel: false
|
|
||||||
|
|
||||||
# Comment to post before locking. Set to `false` to disable
|
|
||||||
lockComment: >
|
|
||||||
This thread has been automatically locked since there has not been
|
|
||||||
any recent activity after it was closed. Please open a new issue for
|
|
||||||
related bugs.
|
|
||||||
|
|
||||||
# Assign `resolved` as the reason for locking. Set to `false` to disable
|
|
||||||
setLockReason: true
|
|
||||||
22
.github/renovate.json5
vendored
22
.github/renovate.json5
vendored
@@ -12,10 +12,30 @@
|
|||||||
"regexManagers": [
|
"regexManagers": [
|
||||||
{
|
{
|
||||||
// use https://github.com/actions/runner/releases
|
// use https://github.com/actions/runner/releases
|
||||||
"fileMatch": [".github/workflows/build-and-release-runners.yml"],
|
"fileMatch": [
|
||||||
|
".github/workflows/runners.yaml"
|
||||||
|
],
|
||||||
"matchStrings": ["RUNNER_VERSION: +(?<currentValue>.*?)\\n"],
|
"matchStrings": ["RUNNER_VERSION: +(?<currentValue>.*?)\\n"],
|
||||||
"depNameTemplate": "actions/runner",
|
"depNameTemplate": "actions/runner",
|
||||||
"datasourceTemplate": "github-releases"
|
"datasourceTemplate": "github-releases"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"runner/Makefile",
|
||||||
|
"Makefile"
|
||||||
|
],
|
||||||
|
"matchStrings": ["RUNNER_VERSION \\?= +(?<currentValue>.*?)\\n"],
|
||||||
|
"depNameTemplate": "actions/runner",
|
||||||
|
"datasourceTemplate": "github-releases"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"runner/actions-runner.dockerfile",
|
||||||
|
"runner/actions-runner-dind.dockerfile"
|
||||||
|
],
|
||||||
|
"matchStrings": ["RUNNER_VERSION=+(?<currentValue>.*?)\\n"],
|
||||||
|
"depNameTemplate": "actions/runner",
|
||||||
|
"datasourceTemplate": "github-releases"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
67
.github/stale.yml
vendored
67
.github/stale.yml
vendored
@@ -1,67 +0,0 @@
|
|||||||
# Configuration for probot-stale - https://github.com/probot/stale
|
|
||||||
|
|
||||||
# Number of days of inactivity before an Issue or Pull Request becomes stale
|
|
||||||
daysUntilStale: 30
|
|
||||||
|
|
||||||
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
|
|
||||||
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
|
|
||||||
daysUntilClose: 14
|
|
||||||
|
|
||||||
# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
|
|
||||||
onlyLabels: []
|
|
||||||
|
|
||||||
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
|
||||||
exemptLabels:
|
|
||||||
- pinned
|
|
||||||
- security
|
|
||||||
- enhancement
|
|
||||||
- refactor
|
|
||||||
- documentation
|
|
||||||
- chore
|
|
||||||
- bug
|
|
||||||
- dependencies
|
|
||||||
- needs-investigation
|
|
||||||
|
|
||||||
# Set to true to ignore issues in a project (defaults to false)
|
|
||||||
exemptProjects: false
|
|
||||||
|
|
||||||
# Set to true to ignore issues in a milestone (defaults to false)
|
|
||||||
exemptMilestones: false
|
|
||||||
|
|
||||||
# Set to true to ignore issues with an assignee (defaults to false)
|
|
||||||
exemptAssignees: false
|
|
||||||
|
|
||||||
# Label to use when marking as stale
|
|
||||||
staleLabel: stale
|
|
||||||
|
|
||||||
# Comment to post when marking as stale. Set to `false` to disable
|
|
||||||
markComment: >
|
|
||||||
This issue has been automatically marked as stale because it has not had
|
|
||||||
recent activity. It will be closed if no further activity occurs. Thank you
|
|
||||||
for your contributions.
|
|
||||||
|
|
||||||
# Comment to post when removing the stale label.
|
|
||||||
# unmarkComment: >
|
|
||||||
# Your comment here.
|
|
||||||
|
|
||||||
# Comment to post when closing a stale Issue or Pull Request.
|
|
||||||
# closeComment: >
|
|
||||||
# Your comment here.
|
|
||||||
|
|
||||||
# Limit the number of actions per hour, from 1-30. Default is 30
|
|
||||||
limitPerRun: 30
|
|
||||||
|
|
||||||
# Limit to only `issues` or `pulls`
|
|
||||||
# only: issues
|
|
||||||
|
|
||||||
# Optionally, specify configuration settings that are specific to just 'issues' or 'pulls':
|
|
||||||
# pulls:
|
|
||||||
# daysUntilStale: 30
|
|
||||||
# markComment: >
|
|
||||||
# This pull request has been automatically marked as stale because it has not had
|
|
||||||
# recent activity. It will be closed if no further activity occurs. Thank you
|
|
||||||
# for your contributions.
|
|
||||||
|
|
||||||
# issues:
|
|
||||||
# exemptLabels:
|
|
||||||
# - confirmed
|
|
||||||
123
.github/workflows/build-and-release-runners.yml
vendored
123
.github/workflows/build-and-release-runners.yml
vendored
@@ -1,123 +0,0 @@
|
|||||||
name: Build and Release Runners
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- '**'
|
|
||||||
paths:
|
|
||||||
- 'runner/**'
|
|
||||||
- .github/workflows/build-and-release-runners.yml
|
|
||||||
- '!**.md'
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
paths:
|
|
||||||
- runner/patched/*
|
|
||||||
- runner/Dockerfile
|
|
||||||
- runner/Dockerfile.ubuntu.1804
|
|
||||||
- runner/Dockerfile.dindrunner
|
|
||||||
- runner/entrypoint.sh
|
|
||||||
- .github/workflows/build-and-release-runners.yml
|
|
||||||
- '!**.md'
|
|
||||||
|
|
||||||
env:
|
|
||||||
RUNNER_VERSION: 2.284.0
|
|
||||||
DOCKER_VERSION: 20.10.8
|
|
||||||
DOCKERHUB_USERNAME: summerwind
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Build ${{ matrix.name }}-ubuntu-${{ matrix.os-version }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- name: actions-runner
|
|
||||||
os-version: 20.04
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
- name: actions-runner
|
|
||||||
os-version: 18.04
|
|
||||||
dockerfile: Dockerfile.ubuntu.1804
|
|
||||||
- name: actions-runner-dind
|
|
||||||
os-version: 20.04
|
|
||||||
dockerfile: Dockerfile.dindrunner
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Set outputs
|
|
||||||
id: vars
|
|
||||||
run: echo ::set-output name=sha_short::${GITHUB_SHA::7}
|
|
||||||
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
with:
|
|
||||||
version: latest
|
|
||||||
|
|
||||||
- name: Login to DockerHub
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
if: ${{ github.event_name == 'push' || github.event_name == 'release' }}
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKER_USER }}
|
|
||||||
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build and Push Versioned Tags
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
with:
|
|
||||||
context: ./runner
|
|
||||||
file: ./runner/${{ matrix.dockerfile }}
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
|
||||||
build-args: |
|
|
||||||
RUNNER_VERSION=${{ env.RUNNER_VERSION }}
|
|
||||||
DOCKER_VERSION=${{ env.DOCKER_VERSION }}
|
|
||||||
tags: |
|
|
||||||
${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-ubuntu-${{ matrix.os-version }}
|
|
||||||
${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-ubuntu-${{ matrix.os-version }}-${{ steps.vars.outputs.sha_short }}
|
|
||||||
|
|
||||||
latest-tags:
|
|
||||||
if: ${{ github.event_name == 'push' || github.event_name == 'release' }}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Build ${{ matrix.name }}-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- name: actions-runner
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
- name: actions-runner-dind
|
|
||||||
dockerfile: Dockerfile.dindrunner
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
with:
|
|
||||||
version: latest
|
|
||||||
|
|
||||||
- name: Login to DockerHub
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKER_USER }}
|
|
||||||
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build and Push Latest Tag
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
with:
|
|
||||||
context: ./runner
|
|
||||||
file: ./runner/${{ matrix.dockerfile }}
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
push: true
|
|
||||||
build-args: |
|
|
||||||
RUNNER_VERSION=${{ env.RUNNER_VERSION }}
|
|
||||||
DOCKER_VERSION=${{ env.DOCKER_VERSION }}
|
|
||||||
tags: |
|
|
||||||
${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:latest
|
|
||||||
@@ -1,22 +1,23 @@
|
|||||||
name: Publish Controller Image
|
name: Publish ARC
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types:
|
||||||
|
- published
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
release-controller:
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Release
|
name: Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USER }}
|
DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USER }}
|
||||||
steps:
|
steps:
|
||||||
- name: Set outputs
|
|
||||||
id: vars
|
|
||||||
run: echo ::set-output name=sha_short::${GITHUB_SHA::7}
|
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.18.2'
|
||||||
|
|
||||||
- name: Install tools
|
- name: Install tools
|
||||||
run: |
|
run: |
|
||||||
@@ -35,25 +36,20 @@ jobs:
|
|||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: make github-release
|
run: |
|
||||||
|
make github-release
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Setup Docker Environment
|
||||||
uses: docker/setup-qemu-action@v1
|
id: vars
|
||||||
|
uses: ./.github/actions/setup-docker-environment
|
||||||
- name: Set up Docker Buildx
|
|
||||||
id: buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
with:
|
with:
|
||||||
version: latest
|
username: ${{ env.DOCKERHUB_USERNAME }}
|
||||||
|
|
||||||
- name: Login to DockerHub
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKER_USER }}
|
|
||||||
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
||||||
|
ghcr_username: ${{ github.actor }}
|
||||||
|
ghcr_password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build and Push
|
- name: Build and Push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
file: Dockerfile
|
file: Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
@@ -62,4 +58,6 @@ jobs:
|
|||||||
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:latest
|
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:latest
|
||||||
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:${{ env.VERSION }}
|
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:${{ env.VERSION }}
|
||||||
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:${{ env.VERSION }}-${{ steps.vars.outputs.sha_short }}
|
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:${{ env.VERSION }}-${{ steps.vars.outputs.sha_short }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
57
.github/workflows/publish-canary.yaml
vendored
Normal file
57
.github/workflows/publish-canary.yaml
vendored
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
name: Publish Canary Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
- '.github/ISSUE_TEMPLATE/**'
|
||||||
|
- '.github/workflows/validate-chart.yaml'
|
||||||
|
- '.github/workflows/publish-chart.yaml'
|
||||||
|
- '.github/workflows/publish-arc.yaml'
|
||||||
|
- '.github/workflows/runners.yaml'
|
||||||
|
- '.github/workflows/validate-entrypoint.yaml'
|
||||||
|
- '.github/renovate.*'
|
||||||
|
- 'runner/**'
|
||||||
|
- '.gitignore'
|
||||||
|
- 'PROJECT'
|
||||||
|
- 'LICENSE'
|
||||||
|
- 'Makefile'
|
||||||
|
|
||||||
|
# https://docs.github.com/en/rest/overview/permissions-required-for-github-apps
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
canary-build:
|
||||||
|
name: Build and Publish Canary Image
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USER }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Setup Docker Environment
|
||||||
|
id: vars
|
||||||
|
uses: ./.github/actions/setup-docker-environment
|
||||||
|
with:
|
||||||
|
username: ${{ env.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
||||||
|
ghcr_username: ${{ github.actor }}
|
||||||
|
ghcr_password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
# Considered unstable builds
|
||||||
|
# See Issue #285, PR #286, and PR #323 for more information
|
||||||
|
- name: Build and Push
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
file: Dockerfile
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:canary
|
||||||
|
cache-from: type=gha,scope=arc-canary
|
||||||
|
cache-to: type=gha,mode=max,scope=arc-canary
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Publish helm chart
|
name: Publish Helm Chart
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -6,29 +6,32 @@ on:
|
|||||||
- master
|
- master
|
||||||
paths:
|
paths:
|
||||||
- 'charts/**'
|
- 'charts/**'
|
||||||
- '.github/workflows/on-push-master-publish-chart.yml'
|
- '.github/workflows/publish-chart.yaml'
|
||||||
- '!charts/actions-runner-controller/docs/**'
|
- '!charts/actions-runner-controller/docs/**'
|
||||||
- '!**.md'
|
- '!**.md'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
KUBE_SCORE_VERSION: 1.10.0
|
KUBE_SCORE_VERSION: 1.10.0
|
||||||
HELM_VERSION: v3.4.1
|
HELM_VERSION: v3.8.0
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint-chart:
|
lint-chart:
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Lint Chart
|
name: Lint Chart
|
||||||
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
publish-chart: ${{ steps.publish-chart-step.outputs.publish }}
|
publish-chart: ${{ steps.publish-chart-step.outputs.publish }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Set up Helm
|
- name: Set up Helm
|
||||||
uses: azure/setup-helm@v1
|
uses: azure/setup-helm@v2.1
|
||||||
with:
|
with:
|
||||||
version: ${{ env.HELM_VERSION }}
|
version: ${{ env.HELM_VERSION }}
|
||||||
|
|
||||||
@@ -49,12 +52,12 @@ jobs:
|
|||||||
--enable-optional-test container-security-context-readonlyrootfilesystem
|
--enable-optional-test container-security-context-readonlyrootfilesystem
|
||||||
|
|
||||||
# python is a requirement for the chart-testing action below (supports yamllint among other tests)
|
# python is a requirement for the chart-testing action below (supports yamllint among other tests)
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: 3.7
|
python-version: '3.7'
|
||||||
|
|
||||||
- name: Set up chart-testing
|
- name: Set up chart-testing
|
||||||
uses: helm/chart-testing-action@v2.1.0
|
uses: helm/chart-testing-action@v2.2.1
|
||||||
|
|
||||||
- name: Run chart-testing (list-changed)
|
- name: Run chart-testing (list-changed)
|
||||||
id: list-changed
|
id: list-changed
|
||||||
@@ -65,22 +68,23 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Run chart-testing (lint)
|
- name: Run chart-testing (lint)
|
||||||
run: ct lint --config charts/.ci/ct-config.yaml
|
run: |
|
||||||
|
ct lint --config charts/.ci/ct-config.yaml
|
||||||
|
|
||||||
- name: Create kind cluster
|
- name: Create kind cluster
|
||||||
uses: helm/kind-action@v1.2.0
|
|
||||||
if: steps.list-changed.outputs.changed == 'true'
|
if: steps.list-changed.outputs.changed == 'true'
|
||||||
|
uses: helm/kind-action@v1.2.0
|
||||||
|
|
||||||
# We need cert-manager already installed in the cluster because we assume the CRDs exist
|
# We need cert-manager already installed in the cluster because we assume the CRDs exist
|
||||||
- name: Install cert-manager
|
- name: Install cert-manager
|
||||||
|
if: steps.list-changed.outputs.changed == 'true'
|
||||||
run: |
|
run: |
|
||||||
helm repo add jetstack https://charts.jetstack.io --force-update
|
helm repo add jetstack https://charts.jetstack.io --force-update
|
||||||
helm install cert-manager jetstack/cert-manager --set installCRDs=true --wait
|
helm install cert-manager jetstack/cert-manager --set installCRDs=true --wait
|
||||||
if: steps.list-changed.outputs.changed == 'true'
|
|
||||||
|
|
||||||
- name: Run chart-testing (install)
|
- name: Run chart-testing (install)
|
||||||
run: ct install --config charts/.ci/ct-config.yaml
|
|
||||||
if: steps.list-changed.outputs.changed == 'true'
|
if: steps.list-changed.outputs.changed == 'true'
|
||||||
|
run: ct install --config charts/.ci/ct-config.yaml
|
||||||
|
|
||||||
# WARNING: This relies on the latest release being inat the top of the JSON from GitHub and a clean chart.yaml
|
# WARNING: This relies on the latest release being inat the top of the JSON from GitHub and a clean chart.yaml
|
||||||
- name: Check if Chart Publish is Needed
|
- name: Check if Chart Publish is Needed
|
||||||
@@ -99,12 +103,15 @@ jobs:
|
|||||||
publish-chart:
|
publish-chart:
|
||||||
if: needs.lint-chart.outputs.publish-chart == 'true'
|
if: needs.lint-chart.outputs.publish-chart == 'true'
|
||||||
needs: lint-chart
|
needs: lint-chart
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Publish Chart
|
name: Publish Chart
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write # for helm/chart-releaser-action to push chart release and create a release
|
||||||
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
@@ -114,7 +121,7 @@ jobs:
|
|||||||
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
|
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
|
||||||
|
|
||||||
- name: Run chart-releaser
|
- name: Run chart-releaser
|
||||||
uses: helm/chart-releaser-action@v1.2.1
|
uses: helm/chart-releaser-action@v1.4.0
|
||||||
env:
|
env:
|
||||||
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
|
||||||
32
.github/workflows/run-codeql.yaml
vendored
Normal file
32
.github/workflows/run-codeql.yaml
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
name: Run CodeQL
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
schedule:
|
||||||
|
- cron: '30 1 * * 0'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
security-events: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v2
|
||||||
|
with:
|
||||||
|
languages: go
|
||||||
|
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v2
|
||||||
25
.github/workflows/run-stale.yaml
vendored
Normal file
25
.github/workflows/run-stale.yaml
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: Run Stale Bot
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '30 1 * * *'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
stale:
|
||||||
|
name: Run Stale
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
issues: write # for actions/stale to close stale issues
|
||||||
|
pull-requests: write # for actions/stale to close stale PRs
|
||||||
|
steps:
|
||||||
|
- uses: actions/stale@v5
|
||||||
|
with:
|
||||||
|
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
|
||||||
|
# turn off stale for both issues and PRs
|
||||||
|
days-before-stale: -1
|
||||||
|
# turn stale back on for issues only
|
||||||
|
days-before-issue-stale: 30
|
||||||
|
days-before-issue-close: 14
|
||||||
|
exempt-issue-labels: 'pinned,security,enhancement,refactor,documentation,chore,bug,dependencies,needs-investigation'
|
||||||
72
.github/workflows/runners.yaml
vendored
Normal file
72
.github/workflows/runners.yaml
vendored
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
name: Runners
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- synchronize
|
||||||
|
- reopened
|
||||||
|
- closed
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
paths:
|
||||||
|
- 'runner/**'
|
||||||
|
- '!runner/Makefile'
|
||||||
|
- '.github/workflows/runners.yaml'
|
||||||
|
- '!**.md'
|
||||||
|
|
||||||
|
env:
|
||||||
|
RUNNER_VERSION: 2.293.0
|
||||||
|
DOCKER_VERSION: 20.10.12
|
||||||
|
DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USER }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-runners:
|
||||||
|
name: Build ${{ matrix.name }}-${{ matrix.os-name }}-${{ matrix.os-version }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
packages: write
|
||||||
|
contents: read
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- name: actions-runner
|
||||||
|
os-name: ubuntu
|
||||||
|
os-version: 20.04
|
||||||
|
- name: actions-runner-dind
|
||||||
|
os-name: ubuntu
|
||||||
|
os-version: 20.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Setup Docker Environment
|
||||||
|
id: vars
|
||||||
|
uses: ./.github/actions/setup-docker-environment
|
||||||
|
with:
|
||||||
|
username: ${{ env.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
||||||
|
ghcr_username: ${{ github.actor }}
|
||||||
|
ghcr_password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and Push Versioned Tags
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: ./runner
|
||||||
|
file: ./runner/${{ matrix.name }}.dockerfile
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: ${{ github.ref == 'master' && github.event.pull_request.merged == true }}
|
||||||
|
build-args: |
|
||||||
|
RUNNER_VERSION=${{ env.RUNNER_VERSION }}
|
||||||
|
DOCKER_VERSION=${{ env.DOCKER_VERSION }}
|
||||||
|
tags: |
|
||||||
|
${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }}
|
||||||
|
${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }}-${{ steps.vars.outputs.sha_short }}
|
||||||
|
${{ env.DOCKERHUB_USERNAME }}/${{ matrix.name }}:latest
|
||||||
|
ghcr.io/${{ github.repository }}/${{ matrix.name }}:latest
|
||||||
|
ghcr.io/${{ github.repository }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }}
|
||||||
|
ghcr.io/${{ github.repository }}/${{ matrix.name }}:v${{ env.RUNNER_VERSION }}-${{ matrix.os-name }}-${{ matrix.os-version }}-${{ steps.vars.outputs.sha_short }}
|
||||||
|
cache-from: type=gha,scope=build-${{ matrix.name }}
|
||||||
|
cache-to: type=gha,mode=max,scope=build-${{ matrix.name }}
|
||||||
39
.github/workflows/test.yaml
vendored
39
.github/workflows/test.yaml
vendored
@@ -1,39 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
paths-ignore:
|
|
||||||
- .github/workflows/build-and-release-runners.yml
|
|
||||||
- .github/workflows/on-push-lint-charts.yml
|
|
||||||
- .github/workflows/on-push-master-publish-chart.yml
|
|
||||||
- .github/workflows/release.yml
|
|
||||||
- .github/workflows/test-entrypoint.yml
|
|
||||||
- .github/workflows/wip.yml
|
|
||||||
- 'runner/**'
|
|
||||||
- '**.md'
|
|
||||||
- '.gitignore'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Test
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: '^1.16.5'
|
|
||||||
- run: go version
|
|
||||||
- name: Install kubebuilder
|
|
||||||
run: |
|
|
||||||
curl -L -O https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.2/kubebuilder_2.3.2_linux_amd64.tar.gz
|
|
||||||
tar zxvf kubebuilder_2.3.2_linux_amd64.tar.gz
|
|
||||||
sudo mv kubebuilder_2.3.2_linux_amd64 /usr/local/kubebuilder
|
|
||||||
- name: Run tests
|
|
||||||
run: make test
|
|
||||||
- name: Verify manifests are up-to-date
|
|
||||||
run: |
|
|
||||||
make manifests
|
|
||||||
git diff --exit-code
|
|
||||||
60
.github/workflows/validate-arc.yaml
vendored
Normal file
60
.github/workflows/validate-arc.yaml
vendored
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
name: Validate ARC
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
- '.github/ISSUE_TEMPLATE/**'
|
||||||
|
- '.github/workflows/publish-canary.yaml'
|
||||||
|
- '.github/workflows/validate-chart.yaml'
|
||||||
|
- '.github/workflows/publish-chart.yaml'
|
||||||
|
- '.github/workflows/runners.yaml'
|
||||||
|
- '.github/workflows/publish-arc.yaml'
|
||||||
|
- '.github/workflows/validate-entrypoint.yaml'
|
||||||
|
- '.github/renovate.*'
|
||||||
|
- 'runner/**'
|
||||||
|
- '.gitignore'
|
||||||
|
- 'PROJECT'
|
||||||
|
- 'LICENSE'
|
||||||
|
- 'Makefile'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test-controller:
|
||||||
|
name: Test ARC
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set-up Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.18.2'
|
||||||
|
check-latest: false
|
||||||
|
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
|
- name: Install kubebuilder
|
||||||
|
run: |
|
||||||
|
curl -L -O https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.2/kubebuilder_2.3.2_linux_amd64.tar.gz
|
||||||
|
tar zxvf kubebuilder_2.3.2_linux_amd64.tar.gz
|
||||||
|
sudo mv kubebuilder_2.3.2_linux_amd64 /usr/local/kubebuilder
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
make test
|
||||||
|
|
||||||
|
- name: Verify manifests are up-to-date
|
||||||
|
run: |
|
||||||
|
make manifests
|
||||||
|
git diff --exit-code
|
||||||
@@ -1,29 +1,32 @@
|
|||||||
name: Lint and Test Charts
|
name: Validate Helm Chart
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- 'charts/**'
|
- 'charts/**'
|
||||||
- '.github/workflows/on-push-lint-charts.yml'
|
- '.github/workflows/validate-chart.yaml'
|
||||||
- '!charts/actions-runner-controller/docs/**'
|
- '!charts/actions-runner-controller/docs/**'
|
||||||
- '!**.md'
|
- '!**.md'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
env:
|
env:
|
||||||
KUBE_SCORE_VERSION: 1.10.0
|
KUBE_SCORE_VERSION: 1.10.0
|
||||||
HELM_VERSION: v3.4.1
|
HELM_VERSION: v3.8.0
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint-test:
|
validate-chart:
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Lint Chart
|
name: Lint Chart
|
||||||
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Set up Helm
|
- name: Set up Helm
|
||||||
uses: azure/setup-helm@v1
|
uses: azure/setup-helm@v2.1
|
||||||
with:
|
with:
|
||||||
version: ${{ env.HELM_VERSION }}
|
version: ${{ env.HELM_VERSION }}
|
||||||
|
|
||||||
@@ -44,12 +47,12 @@ jobs:
|
|||||||
--enable-optional-test container-security-context-readonlyrootfilesystem
|
--enable-optional-test container-security-context-readonlyrootfilesystem
|
||||||
|
|
||||||
# python is a requirement for the chart-testing action below (supports yamllint among other tests)
|
# python is a requirement for the chart-testing action below (supports yamllint among other tests)
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: 3.7
|
python-version: '3.7'
|
||||||
|
|
||||||
- name: Set up chart-testing
|
- name: Set up chart-testing
|
||||||
uses: helm/chart-testing-action@v2.1.0
|
uses: helm/chart-testing-action@v2.2.1
|
||||||
|
|
||||||
- name: Run chart-testing (list-changed)
|
- name: Run chart-testing (list-changed)
|
||||||
id: list-changed
|
id: list-changed
|
||||||
@@ -60,7 +63,8 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Run chart-testing (lint)
|
- name: Run chart-testing (lint)
|
||||||
run: ct lint --config charts/.ci/ct-config.yaml
|
run: |
|
||||||
|
ct lint --config charts/.ci/ct-config.yaml
|
||||||
|
|
||||||
- name: Create kind cluster
|
- name: Create kind cluster
|
||||||
uses: helm/kind-action@v1.2.0
|
uses: helm/kind-action@v1.2.0
|
||||||
@@ -68,10 +72,11 @@ jobs:
|
|||||||
|
|
||||||
# We need cert-manager already installed in the cluster because we assume the CRDs exist
|
# We need cert-manager already installed in the cluster because we assume the CRDs exist
|
||||||
- name: Install cert-manager
|
- name: Install cert-manager
|
||||||
|
if: steps.list-changed.outputs.changed == 'true'
|
||||||
run: |
|
run: |
|
||||||
helm repo add jetstack https://charts.jetstack.io --force-update
|
helm repo add jetstack https://charts.jetstack.io --force-update
|
||||||
helm install cert-manager jetstack/cert-manager --set installCRDs=true --wait
|
helm install cert-manager jetstack/cert-manager --set installCRDs=true --wait
|
||||||
if: steps.list-changed.outputs.changed == 'true'
|
|
||||||
|
|
||||||
- name: Run chart-testing (install)
|
- name: Run chart-testing (install)
|
||||||
run: ct install --config charts/.ci/ct-config.yaml
|
run: |
|
||||||
|
ct install --config charts/.ci/ct-config.yaml
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Unit tests for entrypoint
|
name: Validate Runners
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
@@ -9,14 +9,17 @@ on:
|
|||||||
- 'test/entrypoint/**'
|
- 'test/entrypoint/**'
|
||||||
- '!**.md'
|
- '!**.md'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test-runner-entrypoint:
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Test entrypoint
|
name: Test entrypoint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Run unit tests for entrypoint.sh
|
|
||||||
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
cd test/entrypoint
|
make acceptance/runner/entrypoint
|
||||||
bash entrypoint_unittest.sh
|
|
||||||
51
.github/workflows/wip.yml
vendored
51
.github/workflows/wip.yml
vendored
@@ -1,51 +0,0 @@
|
|||||||
name: Publish Canary Image
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
paths-ignore:
|
|
||||||
- .github/workflows/build-and-release-runners.yml
|
|
||||||
- .github/workflows/on-push-lint-charts.yml
|
|
||||||
- .github/workflows/on-push-master-publish-chart.yml
|
|
||||||
- .github/workflows/release.yml
|
|
||||||
- .github/workflows/test-entrypoint.yml
|
|
||||||
- "runner/**"
|
|
||||||
- "**.md"
|
|
||||||
- ".gitignore"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Build and Publish Canary Image
|
|
||||||
env:
|
|
||||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USER }}
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
id: buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
with:
|
|
||||||
version: latest
|
|
||||||
|
|
||||||
- name: Login to DockerHub
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKER_USER }}
|
|
||||||
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
|
||||||
|
|
||||||
# Considered unstable builds
|
|
||||||
# See Issue #285, PR #286, and PR #323 for more information
|
|
||||||
- name: Build and Push
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
with:
|
|
||||||
file: Dockerfile
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
push: true
|
|
||||||
tags: |
|
|
||||||
${{ env.DOCKERHUB_USERNAME }}/actions-runner-controller:canary
|
|
||||||
2
CODEOWNERS
Normal file
2
CODEOWNERS
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# actions-runner-controller maintainers
|
||||||
|
* @mumoshu @toast-gear
|
||||||
@@ -95,6 +95,7 @@ To make your development cycle faster, use the below command to update deploy an
|
|||||||
# you either need to bump VERSION and RUNNER_TAG on each run,
|
# you either need to bump VERSION and RUNNER_TAG on each run,
|
||||||
# or manually run `kubectl delete pod $POD` on respective pods for changes to actually take effect.
|
# or manually run `kubectl delete pod $POD` on respective pods for changes to actually take effect.
|
||||||
|
|
||||||
|
# Makefile
|
||||||
VERSION=controller1 \
|
VERSION=controller1 \
|
||||||
RUNNER_TAG=runner1 \
|
RUNNER_TAG=runner1 \
|
||||||
make acceptance/pull acceptance/kind docker-build acceptance/load acceptance/deploy
|
make acceptance/pull acceptance/kind docker-build acceptance/load acceptance/deploy
|
||||||
@@ -103,14 +104,16 @@ VERSION=controller1 \
|
|||||||
If you've already deployed actions-runner-controller and only want to recreate pods to use the newer image, you can run:
|
If you've already deployed actions-runner-controller and only want to recreate pods to use the newer image, you can run:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
# Makefile
|
||||||
NAME=$DOCKER_USER/actions-runner-controller \
|
NAME=$DOCKER_USER/actions-runner-controller \
|
||||||
make docker-build acceptance/load && \
|
make docker-build acceptance/load && \
|
||||||
kubectl -n actions-runner-system delete po $(kubectl -n actions-runner-system get po -ojsonpath={.items[*].metadata.name})
|
kubectl -n actions-runner-system delete po $(kubectl -n actions-runner-system get po -ojsonpath={.items[*].metadata.name})
|
||||||
```
|
```
|
||||||
|
|
||||||
Similarly, if you'd like to recreate runner pods with the newer runner image,
|
Similarly, if you'd like to recreate runner pods with the newer runner image you can use the runner specific [Makefile](runner/Makefile) to build and / or push new runner images
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
# runner/Makefile
|
||||||
NAME=$DOCKER_USER/actions-runner make \
|
NAME=$DOCKER_USER/actions-runner make \
|
||||||
-C runner docker-{build,push}-ubuntu && \
|
-C runner docker-{build,push}-ubuntu && \
|
||||||
(kubectl get po -ojsonpath={.items[*].metadata.name} | xargs -n1 kubectl delete po)
|
(kubectl get po -ojsonpath={.items[*].metadata.name} | xargs -n1 kubectl delete po)
|
||||||
|
|||||||
43
Dockerfile
43
Dockerfile
@@ -1,29 +1,44 @@
|
|||||||
# Build the manager binary
|
# Build the manager binary
|
||||||
FROM golang:1.17 as builder
|
FROM --platform=$BUILDPLATFORM golang:1.18.2 as builder
|
||||||
|
|
||||||
ARG TARGETPLATFORM
|
|
||||||
|
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
|
|
||||||
ENV GO111MODULE=on \
|
# Make it runnable on a distroless image/without libc
|
||||||
CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
|
|
||||||
# Copy the Go Modules manifests
|
# Copy the Go Modules manifests
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
|
|
||||||
# cache deps before building and copying source so that we don't need to re-download as much
|
# cache deps before building and copying source so that we don't need to re-download as much
|
||||||
# and so that source changes don't invalidate our downloaded layer
|
# and so that source changes don't invalidate our downloaded layer.
|
||||||
|
#
|
||||||
|
# Also, we need to do this before setting TARGETPLATFORM/TARGETOS/TARGETARCH/TARGETVARIANT
|
||||||
|
# so that go mod cache is shared across platforms.
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
# Copy the go source
|
# Copy the go source
|
||||||
COPY . .
|
# COPY . .
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# docker buildx build --tag repo/img:tag -f ./Dockerfile . --platform linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
#
|
||||||
|
# With the above commmand,
|
||||||
|
# TARGETOS can be "linux", TARGETARCH can be "amd64", "arm64", and "arm", TARGETVARIANT can be "v7".
|
||||||
|
|
||||||
|
ARG TARGETPLATFORM TARGETOS TARGETARCH TARGETVARIANT
|
||||||
|
|
||||||
|
# We intentionally avoid `--mount=type=cache,mode=0777,target=/go/pkg/mod` in the `go mod download` and the `go build` runs
|
||||||
|
# to avoid https://github.com/moby/buildkit/issues/2334
|
||||||
|
# We can use docker layer cache so the build is fast enogh anyway
|
||||||
|
# We also use per-platform GOCACHE for the same reason.
|
||||||
|
env GOCACHE /build/${TARGETPLATFORM}/root/.cache/go-build
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
RUN export GOOS=$(echo ${TARGETPLATFORM} | cut -d / -f1) && \
|
RUN --mount=target=. \
|
||||||
export GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) && \
|
--mount=type=cache,mode=0777,target=${GOCACHE} \
|
||||||
GOARM=$(echo ${TARGETPLATFORM} | cut -d / -f3 | cut -c2-) && \
|
export GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} && \
|
||||||
go build -a -o manager main.go && \
|
go build -o /out/manager main.go && \
|
||||||
go build -a -o github-webhook-server ./cmd/githubwebhookserver
|
go build -o /out/github-webhook-server ./cmd/githubwebhookserver
|
||||||
|
|
||||||
# Use distroless as minimal base image to package the manager binary
|
# Use distroless as minimal base image to package the manager binary
|
||||||
# Refer to https://github.com/GoogleContainerTools/distroless for more details
|
# Refer to https://github.com/GoogleContainerTools/distroless for more details
|
||||||
@@ -31,8 +46,8 @@ FROM gcr.io/distroless/static:nonroot
|
|||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
|
|
||||||
COPY --from=builder /workspace/manager .
|
COPY --from=builder /out/manager .
|
||||||
COPY --from=builder /workspace/github-webhook-server .
|
COPY --from=builder /out/github-webhook-server .
|
||||||
|
|
||||||
USER nonroot:nonroot
|
USER nonroot:nonroot
|
||||||
|
|
||||||
|
|||||||
29
Makefile
29
Makefile
@@ -5,21 +5,23 @@ else
|
|||||||
endif
|
endif
|
||||||
DOCKER_USER ?= $(shell echo ${NAME} | cut -d / -f1)
|
DOCKER_USER ?= $(shell echo ${NAME} | cut -d / -f1)
|
||||||
VERSION ?= latest
|
VERSION ?= latest
|
||||||
|
RUNNER_VERSION ?= 2.293.0
|
||||||
|
TARGETPLATFORM ?= $(shell arch)
|
||||||
RUNNER_NAME ?= ${DOCKER_USER}/actions-runner
|
RUNNER_NAME ?= ${DOCKER_USER}/actions-runner
|
||||||
RUNNER_TAG ?= ${VERSION}
|
RUNNER_TAG ?= ${VERSION}
|
||||||
TEST_REPO ?= ${DOCKER_USER}/actions-runner-controller
|
TEST_REPO ?= ${DOCKER_USER}/actions-runner-controller
|
||||||
TEST_ORG ?=
|
TEST_ORG ?=
|
||||||
TEST_ORG_REPO ?=
|
TEST_ORG_REPO ?=
|
||||||
TEST_EPHEMERAL ?= false
|
TEST_EPHEMERAL ?= false
|
||||||
SYNC_PERIOD ?= 5m
|
SYNC_PERIOD ?= 1m
|
||||||
USE_RUNNERSET ?=
|
USE_RUNNERSET ?=
|
||||||
RUNNER_FEATURE_FLAG_EPHEMERAL ?=
|
|
||||||
KUBECONTEXT ?= kind-acceptance
|
KUBECONTEXT ?= kind-acceptance
|
||||||
CLUSTER ?= acceptance
|
CLUSTER ?= acceptance
|
||||||
CERT_MANAGER_VERSION ?= v1.1.1
|
CERT_MANAGER_VERSION ?= v1.1.1
|
||||||
|
KUBE_RBAC_PROXY_VERSION ?= v0.11.0
|
||||||
|
|
||||||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
|
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
|
||||||
CRD_OPTIONS ?= "crd:trivialVersions=true,generateEmbeddedObjectMeta=true"
|
CRD_OPTIONS ?= "crd:generateEmbeddedObjectMeta=true"
|
||||||
|
|
||||||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
||||||
ifeq (,$(shell go env GOBIN))
|
ifeq (,$(shell go env GOBIN))
|
||||||
@@ -54,6 +56,7 @@ GO_TEST_ARGS ?= -short
|
|||||||
# Run tests
|
# Run tests
|
||||||
test: generate fmt vet manifests
|
test: generate fmt vet manifests
|
||||||
go test $(GO_TEST_ARGS) ./... -coverprofile cover.out
|
go test $(GO_TEST_ARGS) ./... -coverprofile cover.out
|
||||||
|
go test -fuzz=Fuzz -fuzztime=10s -run=Fuzz* ./controllers
|
||||||
|
|
||||||
test-with-deps: kube-apiserver etcd kubectl
|
test-with-deps: kube-apiserver etcd kubectl
|
||||||
# See https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/envtest#pkg-constants
|
# See https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/envtest#pkg-constants
|
||||||
@@ -107,13 +110,9 @@ vet:
|
|||||||
generate: controller-gen
|
generate: controller-gen
|
||||||
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."
|
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."
|
||||||
|
|
||||||
# Build the docker image
|
|
||||||
docker-build:
|
|
||||||
docker build -t ${NAME}:${VERSION} .
|
|
||||||
docker build -t ${RUNNER_NAME}:${RUNNER_TAG} --build-arg TARGETPLATFORM=$(shell arch) runner
|
|
||||||
|
|
||||||
docker-buildx:
|
docker-buildx:
|
||||||
export DOCKER_CLI_EXPERIMENTAL=enabled
|
export DOCKER_CLI_EXPERIMENTAL=enabled ;\
|
||||||
|
export DOCKER_BUILDKIT=1
|
||||||
@if ! docker buildx ls | grep -q container-builder; then\
|
@if ! docker buildx ls | grep -q container-builder; then\
|
||||||
docker buildx create --platform ${PLATFORMS} --name container-builder --use;\
|
docker buildx create --platform ${PLATFORMS} --name container-builder --use;\
|
||||||
fi
|
fi
|
||||||
@@ -156,7 +155,7 @@ acceptance/kind:
|
|||||||
# See https://kind.sigs.k8s.io/docs/user/known-issues/#docker-installed-with-snap
|
# See https://kind.sigs.k8s.io/docs/user/known-issues/#docker-installed-with-snap
|
||||||
acceptance/load:
|
acceptance/load:
|
||||||
kind load docker-image ${NAME}:${VERSION} --name ${CLUSTER}
|
kind load docker-image ${NAME}:${VERSION} --name ${CLUSTER}
|
||||||
kind load docker-image quay.io/brancz/kube-rbac-proxy:v0.10.0 --name ${CLUSTER}
|
kind load docker-image quay.io/brancz/kube-rbac-proxy:$(KUBE_RBAC_PROXY_VERSION) --name ${CLUSTER}
|
||||||
kind load docker-image ${RUNNER_NAME}:${RUNNER_TAG} --name ${CLUSTER}
|
kind load docker-image ${RUNNER_NAME}:${RUNNER_TAG} --name ${CLUSTER}
|
||||||
kind load docker-image docker:dind --name ${CLUSTER}
|
kind load docker-image docker:dind --name ${CLUSTER}
|
||||||
kind load docker-image quay.io/jetstack/cert-manager-controller:$(CERT_MANAGER_VERSION) --name ${CLUSTER}
|
kind load docker-image quay.io/jetstack/cert-manager-controller:$(CERT_MANAGER_VERSION) --name ${CLUSTER}
|
||||||
@@ -166,7 +165,7 @@ acceptance/load:
|
|||||||
|
|
||||||
# Pull the docker images for acceptance
|
# Pull the docker images for acceptance
|
||||||
acceptance/pull:
|
acceptance/pull:
|
||||||
docker pull quay.io/brancz/kube-rbac-proxy:v0.10.0
|
docker pull quay.io/brancz/kube-rbac-proxy:$(KUBE_RBAC_PROXY_VERSION)
|
||||||
docker pull docker:dind
|
docker pull docker:dind
|
||||||
docker pull quay.io/jetstack/cert-manager-controller:$(CERT_MANAGER_VERSION)
|
docker pull quay.io/jetstack/cert-manager-controller:$(CERT_MANAGER_VERSION)
|
||||||
docker pull quay.io/jetstack/cert-manager-cainjector:$(CERT_MANAGER_VERSION)
|
docker pull quay.io/jetstack/cert-manager-cainjector:$(CERT_MANAGER_VERSION)
|
||||||
@@ -189,12 +188,14 @@ acceptance/deploy:
|
|||||||
TEST_ORG=${TEST_ORG} TEST_ORG_REPO=${TEST_ORG_REPO} SYNC_PERIOD=${SYNC_PERIOD} \
|
TEST_ORG=${TEST_ORG} TEST_ORG_REPO=${TEST_ORG_REPO} SYNC_PERIOD=${SYNC_PERIOD} \
|
||||||
USE_RUNNERSET=${USE_RUNNERSET} \
|
USE_RUNNERSET=${USE_RUNNERSET} \
|
||||||
TEST_EPHEMERAL=${TEST_EPHEMERAL} \
|
TEST_EPHEMERAL=${TEST_EPHEMERAL} \
|
||||||
RUNNER_FEATURE_FLAG_EPHEMERAL=${RUNNER_FEATURE_FLAG_EPHEMERAL} \
|
|
||||||
acceptance/deploy.sh
|
acceptance/deploy.sh
|
||||||
|
|
||||||
acceptance/tests:
|
acceptance/tests:
|
||||||
acceptance/checks.sh
|
acceptance/checks.sh
|
||||||
|
|
||||||
|
acceptance/runner/entrypoint:
|
||||||
|
cd test/entrypoint/ && bash test.sh
|
||||||
|
|
||||||
# We use -count=1 instead of `go clean -testcache`
|
# We use -count=1 instead of `go clean -testcache`
|
||||||
# See https://terratest.gruntwork.io/docs/testing-best-practices/avoid-test-caching/
|
# See https://terratest.gruntwork.io/docs/testing-best-practices/avoid-test-caching/
|
||||||
.PHONY: e2e
|
.PHONY: e2e
|
||||||
@@ -221,7 +222,7 @@ ifeq (, $(wildcard $(GOBIN)/controller-gen))
|
|||||||
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
|
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
|
||||||
cd $$CONTROLLER_GEN_TMP_DIR ;\
|
cd $$CONTROLLER_GEN_TMP_DIR ;\
|
||||||
go mod init tmp ;\
|
go mod init tmp ;\
|
||||||
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.0 ;\
|
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0 ;\
|
||||||
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
|
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
|
||||||
}
|
}
|
||||||
endif
|
endif
|
||||||
@@ -241,7 +242,7 @@ ifeq (, $(wildcard $(GOBIN)/yq))
|
|||||||
YQ_TMP_DIR=$$(mktemp -d) ;\
|
YQ_TMP_DIR=$$(mktemp -d) ;\
|
||||||
cd $$YQ_TMP_DIR ;\
|
cd $$YQ_TMP_DIR ;\
|
||||||
go mod init tmp ;\
|
go mod init tmp ;\
|
||||||
go get github.com/mikefarah/yq/v3@3.4.0 ;\
|
go install github.com/mikefarah/yq/v3@3.4.0 ;\
|
||||||
rm -rf $$YQ_TMP_DIR ;\
|
rm -rf $$YQ_TMP_DIR ;\
|
||||||
}
|
}
|
||||||
endif
|
endif
|
||||||
|
|||||||
22
SECURITY.md
Normal file
22
SECURITY.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Sponsoring the project
|
||||||
|
|
||||||
|
This project is maintained by a small team of two and therefore lacks the resource to provide security fixes in a timely manner.
|
||||||
|
|
||||||
|
If you have important business(es) that relies on this project, please consider sponsoring the project so that the maintainer(s) can commit to providing such service.
|
||||||
|
|
||||||
|
Please refer to https://github.com/sponsors/actions-runner-controller for available tiers.
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| ------- | ------------------ |
|
||||||
|
| 0.23.0 | :white_check_mark: |
|
||||||
|
| < 0.23.0| :x: |
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
To report a security issue, please email ykuoka+arcsecurity(at)gmail.com with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue.
|
||||||
|
|
||||||
|
A maintainer will try to respond within 5 working days. If the issue is confirmed as a vulnerability, a Security Advisory will be opened. This project tries to follow a 90 day disclosure timeline.
|
||||||
222
TROUBLESHOOTING.md
Normal file
222
TROUBLESHOOTING.md
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
# Troubleshooting
|
||||||
|
|
||||||
|
* [Tools](#tools)
|
||||||
|
* [Installation](#installation)
|
||||||
|
* [Invalid header field value](#invalid-header-field-value)
|
||||||
|
* [Deployment fails on GKE due to webhooks](#deployment-fails-on-gke-due-to-webhooks)
|
||||||
|
* [Operations](#operations)
|
||||||
|
* [Stuck runner kind or backing pod](#stuck-runner-kind-or-backing-pod)
|
||||||
|
* [Delay in jobs being allocated to runners](#delay-in-jobs-being-allocated-to-runners)
|
||||||
|
* [Runner coming up before network available](#runner-coming-up-before-network-available)
|
||||||
|
* [Outgoing network action hangs indefinitely](#outgoing-network-action-hangs-indefinitely)
|
||||||
|
* [Unable to scale to zero with TotalNumberOfQueuedAndInProgressWorkflowRuns](#unable-to-scale-to-zero-with-totalnumberofqueuedandinprogressworkflowruns)
|
||||||
|
|
||||||
|
## Tools
|
||||||
|
|
||||||
|
A list of tools which are helpful for troubleshooting
|
||||||
|
|
||||||
|
* https://github.com/rewanthtammana/kubectl-fields Kubernetes resources hierarchy parsing tool
|
||||||
|
* https://github.com/stern/stern Multi pod and container log tailing for Kubernetes
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Troubeshooting runbooks that relate to ARC installation problems
|
||||||
|
|
||||||
|
### Invalid header field value
|
||||||
|
|
||||||
|
**Problem**
|
||||||
|
|
||||||
|
```json
|
||||||
|
2020-11-12T22:17:30.693Z ERROR controller-runtime.controller Reconciler error
|
||||||
|
{
|
||||||
|
"controller": "runner",
|
||||||
|
"request": "actions-runner-system/runner-deployment-dk7q8-dk5c9",
|
||||||
|
"error": "failed to create registration token: Post \"https://api.github.com/orgs/$YOUR_ORG_HERE/actions/runners/registration-token\": net/http: invalid header field value \"Bearer $YOUR_TOKEN_HERE\\n\" for key Authorization"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Solution**
|
||||||
|
|
||||||
|
Your base64'ed PAT token has a new line at the end, it needs to be created without a `\n` added, either:
|
||||||
|
* `echo -n $TOKEN | base64`
|
||||||
|
* Create the secret as described in the docs using the shell and documented flags
|
||||||
|
|
||||||
|
|
||||||
|
### Deployment fails on GKE due to webhooks
|
||||||
|
|
||||||
|
**Problem**
|
||||||
|
|
||||||
|
Due to GKEs firewall settings you may run into the following errors when trying to deploy runners on a private GKE cluster:
|
||||||
|
|
||||||
|
```
|
||||||
|
Internal error occurred: failed calling webhook "mutate.runner.actions.summerwind.dev":
|
||||||
|
Post https://webhook-service.actions-runner-system.svc:443/mutate-actions-summerwind-dev-v1alpha1-runner?timeout=10s:
|
||||||
|
context deadline exceeded
|
||||||
|
```
|
||||||
|
|
||||||
|
**Solution**<br />
|
||||||
|
|
||||||
|
To fix this, you may either:
|
||||||
|
|
||||||
|
1. Configure the webhook to use another port, such as 443 or 10250, [each of
|
||||||
|
which allow traffic by default](https://cloud.google.com/kubernetes-engine/docs/how-to/private-clusters#add_firewall_rules).
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# With helm, you'd set `webhookPort` to the port number of your choice
|
||||||
|
# See https://github.com/actions-runner-controller/actions-runner-controller/pull/1410/files for more information
|
||||||
|
helm upgrade --install --namespace actions-runner-system --create-namespace \
|
||||||
|
--wait actions-runner-controller actions-runner-controller/actions-runner-controller \
|
||||||
|
--set webhookPort=10250
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Set up a firewall rule to allow the master node to connect to the default
|
||||||
|
webhook port. The exact way to do this may vary, but the following script
|
||||||
|
should point you in the right direction:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# 1) Retrieve the network tag automatically given to the worker nodes
|
||||||
|
# NOTE: this only works if you have only one cluster in your GCP project. You will have to manually inspect the result of this command to find the tag for the cluster you want to target
|
||||||
|
WORKER_NODES_TAG=$(gcloud compute instances list --format='text(tags.items[0])' --filter='metadata.kubelet-config:*' | grep tags | awk '{print $2}' | sort | uniq)
|
||||||
|
|
||||||
|
# 2) Take note of the VPC network in which you deployed your cluster
|
||||||
|
# NOTE this only works if you have only one network in which you deploy your clusters
|
||||||
|
NETWORK=$(gcloud compute instances list --format='text(networkInterfaces[0].network)' --filter='metadata.kubelet-config:*' | grep networks | awk -F'/' '{print $NF}' | sort | uniq)
|
||||||
|
|
||||||
|
# 3) Get the master source ip block
|
||||||
|
SOURCE=$(gcloud container clusters describe <cluster-name> --region <region> | grep masterIpv4CidrBlock| cut -d ':' -f 2 | tr -d ' ')
|
||||||
|
|
||||||
|
gcloud compute firewall-rules create k8s-cert-manager --source-ranges $SOURCE --target-tags $WORKER_NODES_TAG --allow TCP:9443 --network $NETWORK
|
||||||
|
```
|
||||||
|
|
||||||
|
## Operations
|
||||||
|
|
||||||
|
Troubeshooting runbooks that relate to ARC operational problems
|
||||||
|
|
||||||
|
### Stuck runner kind or backing pod
|
||||||
|
|
||||||
|
**Problem**
|
||||||
|
|
||||||
|
Sometimes either the runner kind (`kubectl get runners`) or it's underlying pod can get stuck in a terminating state for various reasons. You can get the kind unstuck by removing its finaliser using something like this:
|
||||||
|
|
||||||
|
**Solution**
|
||||||
|
|
||||||
|
Remove the finaliser from the relevent runner kind or pod
|
||||||
|
|
||||||
|
```
|
||||||
|
# Get all kind runners and remove the finalizer
|
||||||
|
$ kubectl get runners --no-headers | awk {'print $1'} | xargs kubectl patch runner --type merge -p '{"metadata":{"finalizers":null}}'
|
||||||
|
|
||||||
|
# Get all pods that are stuck terminating and remove the finalizer
|
||||||
|
$ kubectl -n get pods | grep Terminating | awk {'print $1'} | xargs kubectl patch pod -p '{"metadata":{"finalizers":null}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
_Note the code assumes you have already selected the namespace your runners are in and that they
|
||||||
|
are in a namespace not shared with anything else_
|
||||||
|
|
||||||
|
### Delay in jobs being allocated to runners
|
||||||
|
|
||||||
|
**Problem**
|
||||||
|
|
||||||
|
ARC isn't involved in jobs actually getting allocated to a runner. ARC is responsible for orchestrating runners and the runner lifecycle. Why some people see large delays in job allocation is not clear however it has been https://github.com/actions-runner-controller/actions-runner-controller/issues/1387#issuecomment-1122593984 that this is caused from the self-update process somehow.
|
||||||
|
|
||||||
|
**Solution**
|
||||||
|
|
||||||
|
Disable the self-update process in your runner manifests
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: actions.summerwind.dev/v1alpha1
|
||||||
|
kind: RunnerDeployment
|
||||||
|
metadata:
|
||||||
|
name: example-runnerdeployment-with-sleep
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
...
|
||||||
|
env:
|
||||||
|
- name: DISABLE_RUNNER_UPDATE
|
||||||
|
value: "true"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Runner coming up before network available
|
||||||
|
|
||||||
|
**Problem**
|
||||||
|
|
||||||
|
If you're running your action runners on a service mesh like Istio, you might
|
||||||
|
have problems with runner configuration accompanied by logs like:
|
||||||
|
|
||||||
|
```
|
||||||
|
....
|
||||||
|
runner Starting Runner listener with startup type: service
|
||||||
|
runner Started listener process
|
||||||
|
runner An error occurred: Not configured
|
||||||
|
runner Runner listener exited with error code 2
|
||||||
|
runner Runner listener exit with retryable error, re-launch runner in 5 seconds.
|
||||||
|
....
|
||||||
|
```
|
||||||
|
|
||||||
|
This is because the `istio-proxy` has not completed configuring itself when the
|
||||||
|
configuration script tries to communicate with the network.
|
||||||
|
|
||||||
|
More broadly, there are many other circumstances where the runner pod coming up first can cause issues.
|
||||||
|
|
||||||
|
**Solution**<br />
|
||||||
|
|
||||||
|
> Added originally to help users with older istio instances.
|
||||||
|
> Newer Istio instances can use Istio's `holdApplicationUntilProxyStarts` attribute ([istio/istio#11130](https://github.com/istio/istio/issues/11130)) to avoid having to delay starting up the runner.
|
||||||
|
> Please read the discussion in [#592](https://github.com/actions-runner-controller/actions-runner-controller/pull/592) for more information.
|
||||||
|
|
||||||
|
You can add a delay to the runner's entrypoint script by setting the `STARTUP_DELAY_IN_SECONDS` environment variable for the runner pod. This will cause the script to sleep X seconds, this works with any runner kind.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: actions.summerwind.dev/v1alpha1
|
||||||
|
kind: RunnerDeployment
|
||||||
|
metadata:
|
||||||
|
name: example-runnerdeployment-with-sleep
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
...
|
||||||
|
env:
|
||||||
|
- name: STARTUP_DELAY_IN_SECONDS
|
||||||
|
value: "5"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Outgoing network action hangs indefinitely
|
||||||
|
|
||||||
|
**Problem**
|
||||||
|
|
||||||
|
Some random outgoing network actions hangs indefinitely. This could be because your cluster does not give Docker the standard MTU of 1500, you can check this out by running `ip link` in a pod that encounters the problem and reading the outgoing interface's MTU value. If it is smaller than 1500, then try the following.
|
||||||
|
|
||||||
|
**Solution**
|
||||||
|
|
||||||
|
Add a `dockerMTU` key in your runner's spec with the value you read on the outgoing interface. For instance:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: actions.summerwind.dev/v1alpha1
|
||||||
|
kind: RunnerDeployment
|
||||||
|
metadata:
|
||||||
|
name: github-runner
|
||||||
|
namespace: github-system
|
||||||
|
spec:
|
||||||
|
replicas: 6
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
dockerMTU: 1400
|
||||||
|
repository: $username/$repo
|
||||||
|
env: []
|
||||||
|
```
|
||||||
|
|
||||||
|
There may be more places you need to tweak for MTU.
|
||||||
|
Please consult issues like #651 for more information.
|
||||||
|
|
||||||
|
## Unable to scale to zero with TotalNumberOfQueuedAndInProgressWorkflowRuns
|
||||||
|
|
||||||
|
**Problem**
|
||||||
|
|
||||||
|
HRA doesn't scale the RunnerDeployment to zero, even though you did configure HRA correctly, to have a pull-based scaling metric `TotalNumberOfQueuedAndInProgressWorkflowRuns`, and set `minReplicas: 0`.
|
||||||
|
|
||||||
|
**Solution**
|
||||||
|
|
||||||
|
You very likely have some dangling workflow jobs stuck in `queued` or `in_progress` as seen in [#1057](https://github.com/actions-runner-controller/actions-runner-controller/issues/1057#issuecomment-1133439061).
|
||||||
|
|
||||||
|
Manually call [the "list workflow runs" API](https://docs.github.com/en/rest/actions/workflow-runs#list-workflow-runs-for-a-repository), and [remove the dangling workflow job(s)](https://docs.github.com/en/rest/actions/workflow-runs#delete-a-workflow-run).
|
||||||
@@ -6,6 +6,8 @@ tpe=${ACCEPTANCE_TEST_SECRET_TYPE}
|
|||||||
|
|
||||||
VALUES_FILE=${VALUES_FILE:-$(dirname $0)/values.yaml}
|
VALUES_FILE=${VALUES_FILE:-$(dirname $0)/values.yaml}
|
||||||
|
|
||||||
|
kubectl delete secret -n actions-runner-system controller-manager || :
|
||||||
|
|
||||||
if [ "${tpe}" == "token" ]; then
|
if [ "${tpe}" == "token" ]; then
|
||||||
if ! kubectl get secret controller-manager -n actions-runner-system >/dev/null; then
|
if ! kubectl get secret controller-manager -n actions-runner-system >/dev/null; then
|
||||||
kubectl create secret generic controller-manager \
|
kubectl create secret generic controller-manager \
|
||||||
@@ -16,16 +18,29 @@ elif [ "${tpe}" == "app" ]; then
|
|||||||
kubectl create secret generic controller-manager \
|
kubectl create secret generic controller-manager \
|
||||||
-n actions-runner-system \
|
-n actions-runner-system \
|
||||||
--from-literal=github_app_id=${APP_ID:?must not be empty} \
|
--from-literal=github_app_id=${APP_ID:?must not be empty} \
|
||||||
--from-literal=github_app_installation_id=${INSTALLATION_ID:?must not be empty} \
|
--from-literal=github_app_installation_id=${APP_INSTALLATION_ID:?must not be empty} \
|
||||||
--from-file=github_app_private_key=${PRIVATE_KEY_FILE_PATH:?must not be empty}
|
--from-file=github_app_private_key=${APP_PRIVATE_KEY_FILE:?must not be empty}
|
||||||
else
|
else
|
||||||
echo "ACCEPTANCE_TEST_SECRET_TYPE must be set to either \"token\" or \"app\"" 1>&2
|
echo "ACCEPTANCE_TEST_SECRET_TYPE must be set to either \"token\" or \"app\"" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "${WEBHOOK_GITHUB_TOKEN}" ]; then
|
||||||
|
kubectl -n actions-runner-system delete secret \
|
||||||
|
github-webhook-server || :
|
||||||
|
kubectl -n actions-runner-system create secret generic \
|
||||||
|
github-webhook-server \
|
||||||
|
--from-literal=github_token=${WEBHOOK_GITHUB_TOKEN:?WEBHOOK_GITHUB_TOKEN must not be empty}
|
||||||
|
else
|
||||||
|
echo 'Skipped deploying secret "github-webhook-server". Set WEBHOOK_GITHUB_TOKEN to deploy.' 1>&2
|
||||||
|
fi
|
||||||
|
|
||||||
tool=${ACCEPTANCE_TEST_DEPLOYMENT_TOOL}
|
tool=${ACCEPTANCE_TEST_DEPLOYMENT_TOOL}
|
||||||
|
|
||||||
|
TEST_ID=${TEST_ID:-default}
|
||||||
|
|
||||||
if [ "${tool}" == "helm" ]; then
|
if [ "${tool}" == "helm" ]; then
|
||||||
|
set -v
|
||||||
helm upgrade --install actions-runner-controller \
|
helm upgrade --install actions-runner-controller \
|
||||||
charts/actions-runner-controller \
|
charts/actions-runner-controller \
|
||||||
-n actions-runner-system \
|
-n actions-runner-system \
|
||||||
@@ -34,42 +49,83 @@ if [ "${tool}" == "helm" ]; then
|
|||||||
--set authSecret.create=false \
|
--set authSecret.create=false \
|
||||||
--set image.repository=${NAME} \
|
--set image.repository=${NAME} \
|
||||||
--set image.tag=${VERSION} \
|
--set image.tag=${VERSION} \
|
||||||
|
--set podAnnotations.test-id=${TEST_ID} \
|
||||||
|
--set githubWebhookServer.podAnnotations.test-id=${TEST_ID} \
|
||||||
-f ${VALUES_FILE}
|
-f ${VALUES_FILE}
|
||||||
kubectl apply -f charts/actions-runner-controller/crds
|
set +v
|
||||||
kubectl -n actions-runner-system wait deploy/actions-runner-controller --for condition=available --timeout 60s
|
# To prevent `CustomResourceDefinition.apiextensions.k8s.io "runners.actions.summerwind.dev" is invalid: metadata.annotations: Too long: must have at most 262144 bytes`
|
||||||
|
# errors
|
||||||
|
kubectl create -f charts/actions-runner-controller/crds || kubectl replace -f charts/actions-runner-controller/crds
|
||||||
|
# This wait fails due to timeout when it's already in crashloopback and this update doesn't change the image tag.
|
||||||
|
# That's why we add `|| :`. With that we prevent stopping the script in case of timeout and
|
||||||
|
# proceed to delete (possibly in crashloopback and/or running with outdated image) pods so that they are recreated by K8s.
|
||||||
|
kubectl -n actions-runner-system wait deploy/actions-runner-controller --for condition=available --timeout 60s || :
|
||||||
else
|
else
|
||||||
kubectl apply \
|
kubectl apply \
|
||||||
-n actions-runner-system \
|
-n actions-runner-system \
|
||||||
-f release/actions-runner-controller.yaml
|
-f release/actions-runner-controller.yaml
|
||||||
kubectl -n actions-runner-system wait deploy/controller-manager --for condition=available --timeout 120s
|
kubectl -n actions-runner-system wait deploy/controller-manager --for condition=available --timeout 120s || :
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Restart all ARC pods
|
||||||
|
kubectl -n actions-runner-system delete po -l app.kubernetes.io/name=actions-runner-controller
|
||||||
|
|
||||||
|
echo Waiting for all ARC pods to be up and running after restart
|
||||||
|
|
||||||
|
kubectl -n actions-runner-system wait deploy/actions-runner-controller --for condition=available --timeout 120s
|
||||||
|
|
||||||
# Adhocly wait for some time until actions-runner-controller's admission webhook gets ready
|
# Adhocly wait for some time until actions-runner-controller's admission webhook gets ready
|
||||||
sleep 20
|
sleep 20
|
||||||
|
|
||||||
RUNNER_LABEL=${RUNNER_LABEL:-self-hosted}
|
RUNNER_LABEL=${RUNNER_LABEL:-self-hosted}
|
||||||
|
|
||||||
if [ -n "${TEST_REPO}" ]; then
|
if [ -n "${TEST_REPO}" ]; then
|
||||||
if [ -n "USE_RUNNERSET" ]; then
|
if [ "${USE_RUNNERSET}" != "false" ]; then
|
||||||
cat acceptance/testdata/repo.runnerset.yaml | envsubst | kubectl apply -f -
|
cat acceptance/testdata/runnerset.envsubst.yaml | TEST_ENTERPRISE= TEST_ORG= RUNNER_MIN_REPLICAS=${REPO_RUNNER_MIN_REPLICAS} NAME=repo-runnerset envsubst | kubectl apply -f -
|
||||||
cat acceptance/testdata/repo.runnerset.hra.yaml | envsubst | kubectl apply -f -
|
|
||||||
else
|
else
|
||||||
echo 'Deploying runnerdeployment and hra. Set USE_RUNNERSET if you want to deploy runnerset instead.'
|
echo 'Deploying runnerdeployment and hra. Set USE_RUNNERSET if you want to deploy runnerset instead.'
|
||||||
cat acceptance/testdata/repo.runnerdeploy.yaml | envsubst | kubectl apply -f -
|
cat acceptance/testdata/runnerdeploy.envsubst.yaml | TEST_ENTERPRISE= TEST_ORG= RUNNER_MIN_REPLICAS=${REPO_RUNNER_MIN_REPLICAS} NAME=repo-runnerdeploy envsubst | kubectl apply -f -
|
||||||
cat acceptance/testdata/repo.hra.yaml | envsubst | kubectl apply -f -
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo 'Skipped deploying runnerdeployment and hra. Set TEST_REPO to "yourorg/yourrepo" to deploy.'
|
echo 'Skipped deploying runnerdeployment and hra. Set TEST_REPO to "yourorg/yourrepo" to deploy.'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${TEST_ORG}" ]; then
|
if [ -n "${TEST_ORG}" ]; then
|
||||||
cat acceptance/testdata/org.runnerdeploy.yaml | envsubst | kubectl apply -f -
|
if [ "${USE_RUNNERSET}" != "false" ]; then
|
||||||
|
cat acceptance/testdata/runnerset.envsubst.yaml | TEST_ENTERPRISE= TEST_REPO= RUNNER_MIN_REPLICAS=${ORG_RUNNER_MIN_REPLICAS} NAME=org-runnerset envsubst | kubectl apply -f -
|
||||||
if [ -n "${TEST_ORG_REPO}" ]; then
|
|
||||||
cat acceptance/testdata/org.hra.yaml | envsubst | kubectl apply -f -
|
|
||||||
else
|
else
|
||||||
echo 'Skipped deploying organizational hra. Set TEST_ORG_REPO to "yourorg/yourrepo" to deploy.'
|
cat acceptance/testdata/runnerdeploy.envsubst.yaml | TEST_ENTERPRISE= TEST_REPO= RUNNER_MIN_REPLICAS=${ORG_RUNNER_MIN_REPLICAS} NAME=org-runnerdeploy envsubst | kubectl apply -f -
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "${TEST_ORG_GROUP}" ]; then
|
||||||
|
if [ "${USE_RUNNERSET}" != "false" ]; then
|
||||||
|
cat acceptance/testdata/runnerset.envsubst.yaml | TEST_ENTERPRISE= TEST_REPO= RUNNER_MIN_REPLICAS=${ORG_RUNNER_MIN_REPLICAS} TEST_GROUP=${TEST_ORG_GROUP} NAME=orggroup-runnerset envsubst | kubectl apply -f -
|
||||||
|
else
|
||||||
|
cat acceptance/testdata/runnerdeploy.envsubst.yaml | TEST_ENTERPRISE= TEST_REPO= RUNNER_MIN_REPLICAS=${ORG_RUNNER_MIN_REPLICAS} TEST_GROUP=${TEST_ORG_GROUP} NAME=orggroup-runnerdeploy envsubst | kubectl apply -f -
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo 'Skipped deploying enterprise runnerdeployment. Set TEST_ORG_GROUP to deploy.'
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo 'Skipped deploying organizational runnerdeployment. Set TEST_ORG to deploy.'
|
echo 'Skipped deploying organizational runnerdeployment. Set TEST_ORG to deploy.'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "${TEST_ENTERPRISE}" ]; then
|
||||||
|
if [ "${USE_RUNNERSET}" != "false" ]; then
|
||||||
|
cat acceptance/testdata/runnerset.envsubst.yaml | TEST_ORG= TEST_REPO= RUNNER_MIN_REPLICAS=${ENTERPRISE_RUNNER_MIN_REPLICAS} NAME=enterprise-runnerset envsubst | kubectl apply -f -
|
||||||
|
else
|
||||||
|
cat acceptance/testdata/runnerdeploy.envsubst.yaml | TEST_ORG= TEST_REPO= RUNNER_MIN_REPLICAS=${ENTERPRISE_RUNNER_MIN_REPLICAS} NAME=enterprise-runnerdeploy envsubst | kubectl apply -f -
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "${TEST_ENTERPRISE_GROUP}" ]; then
|
||||||
|
if [ "${USE_RUNNERSET}" != "false" ]; then
|
||||||
|
cat acceptance/testdata/runnerset.envsubst.yaml | TEST_ORG= TEST_REPO= RUNNER_MIN_REPLICAS=${ENTERPRISE_RUNNER_MIN_REPLICAS} TEST_GROUP=${TEST_ENTERPRISE_GROUP} NAME=enterprisegroup-runnerset envsubst | kubectl apply -f -
|
||||||
|
else
|
||||||
|
cat acceptance/testdata/runnerdeploy.envsubst.yaml | TEST_ORG= TEST_REPO= RUNNER_MIN_REPLICAS=${ENTERPRISE_RUNNER_MIN_REPLICAS} TEST_GROUP=${TEST_ENTERPRISE_GROUP} NAME=enterprisegroup-runnerdeploy envsubst | kubectl apply -f -
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo 'Skipped deploying enterprise runnerdeployment. Set TEST_ENTERPRISE_GROUP to deploy.'
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo 'Skipped deploying enterprise runnerdeployment. Set TEST_ENTERPRISE to deploy.'
|
||||||
|
fi
|
||||||
|
|||||||
36
acceptance/testdata/org.hra.yaml
vendored
36
acceptance/testdata/org.hra.yaml
vendored
@@ -1,36 +0,0 @@
|
|||||||
apiVersion: actions.summerwind.dev/v1alpha1
|
|
||||||
kind: HorizontalRunnerAutoscaler
|
|
||||||
metadata:
|
|
||||||
name: org
|
|
||||||
spec:
|
|
||||||
scaleTargetRef:
|
|
||||||
name: org-runnerdeploy
|
|
||||||
scaleUpTriggers:
|
|
||||||
- githubEvent:
|
|
||||||
checkRun:
|
|
||||||
types: ["created"]
|
|
||||||
status: "queued"
|
|
||||||
amount: 1
|
|
||||||
duration: "1m"
|
|
||||||
scheduledOverrides:
|
|
||||||
- startTime: "2021-05-11T16:05:00+09:00"
|
|
||||||
endTime: "2021-05-11T16:40:00+09:00"
|
|
||||||
minReplicas: 2
|
|
||||||
- startTime: "2021-05-01T00:00:00+09:00"
|
|
||||||
endTime: "2021-05-03T00:00:00+09:00"
|
|
||||||
recurrenceRule:
|
|
||||||
frequency: Weekly
|
|
||||||
untilTime: "2022-05-01T00:00:00+09:00"
|
|
||||||
minReplicas: 0
|
|
||||||
minReplicas: 0
|
|
||||||
maxReplicas: 5
|
|
||||||
# Used to test that HRA is working for org runners
|
|
||||||
metrics:
|
|
||||||
- type: PercentageRunnersBusy
|
|
||||||
scaleUpThreshold: '0.75'
|
|
||||||
scaleDownThreshold: '0.3'
|
|
||||||
scaleUpFactor: '2'
|
|
||||||
scaleDownFactor: '0.5'
|
|
||||||
- type: TotalNumberOfQueuedAndInProgressWorkflowRuns
|
|
||||||
repositoryNames:
|
|
||||||
- ${TEST_ORG_REPO}
|
|
||||||
25
acceptance/testdata/repo.hra.yaml
vendored
25
acceptance/testdata/repo.hra.yaml
vendored
@@ -1,25 +0,0 @@
|
|||||||
apiVersion: actions.summerwind.dev/v1alpha1
|
|
||||||
kind: HorizontalRunnerAutoscaler
|
|
||||||
metadata:
|
|
||||||
name: actions-runner-aos-autoscaler
|
|
||||||
spec:
|
|
||||||
scaleTargetRef:
|
|
||||||
name: example-runnerdeploy
|
|
||||||
scaleUpTriggers:
|
|
||||||
- githubEvent:
|
|
||||||
checkRun:
|
|
||||||
types: ["created"]
|
|
||||||
status: "queued"
|
|
||||||
amount: 1
|
|
||||||
duration: "1m"
|
|
||||||
minReplicas: 0
|
|
||||||
maxReplicas: 5
|
|
||||||
metrics:
|
|
||||||
- type: PercentageRunnersBusy
|
|
||||||
scaleUpThreshold: '0.75'
|
|
||||||
scaleDownThreshold: '0.3'
|
|
||||||
scaleUpFactor: '2'
|
|
||||||
scaleDownFactor: '0.5'
|
|
||||||
- type: TotalNumberOfQueuedAndInProgressWorkflowRuns
|
|
||||||
repositoryNames:
|
|
||||||
- ${TEST_REPO}
|
|
||||||
37
acceptance/testdata/repo.runnerdeploy.yaml
vendored
37
acceptance/testdata/repo.runnerdeploy.yaml
vendored
@@ -1,37 +0,0 @@
|
|||||||
apiVersion: actions.summerwind.dev/v1alpha1
|
|
||||||
kind: RunnerDeployment
|
|
||||||
metadata:
|
|
||||||
name: example-runnerdeploy
|
|
||||||
spec:
|
|
||||||
# replicas: 1
|
|
||||||
template:
|
|
||||||
spec:
|
|
||||||
repository: ${TEST_REPO}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Custom runner image
|
|
||||||
#
|
|
||||||
image: ${RUNNER_NAME}:${RUNNER_TAG}
|
|
||||||
imagePullPolicy: IfNotPresent
|
|
||||||
|
|
||||||
#
|
|
||||||
# dockerd within runner container
|
|
||||||
#
|
|
||||||
## Replace `mumoshu/actions-runner-dind:dev` with your dind image
|
|
||||||
#dockerdWithinRunnerContainer: true
|
|
||||||
#image: mumoshu/actions-runner-dind:dev
|
|
||||||
|
|
||||||
#
|
|
||||||
# Set the MTU used by dockerd-managed network interfaces (including docker-build-ubuntu)
|
|
||||||
#
|
|
||||||
#dockerMTU: 1450
|
|
||||||
|
|
||||||
#Runner group
|
|
||||||
# labels:
|
|
||||||
# - "mylabel 1"
|
|
||||||
# - "mylabel 2"
|
|
||||||
|
|
||||||
#
|
|
||||||
# Non-standard working directory
|
|
||||||
#
|
|
||||||
# workDir: "/"
|
|
||||||
29
acceptance/testdata/repo.runnerset.hra.yaml
vendored
29
acceptance/testdata/repo.runnerset.hra.yaml
vendored
@@ -1,29 +0,0 @@
|
|||||||
apiVersion: actions.summerwind.dev/v1alpha1
|
|
||||||
kind: HorizontalRunnerAutoscaler
|
|
||||||
metadata:
|
|
||||||
name: example-runnerset
|
|
||||||
spec:
|
|
||||||
scaleTargetRef:
|
|
||||||
kind: RunnerSet
|
|
||||||
name: example-runnerset
|
|
||||||
scaleUpTriggers:
|
|
||||||
- githubEvent:
|
|
||||||
checkRun:
|
|
||||||
types: ["created"]
|
|
||||||
status: "queued"
|
|
||||||
amount: 1
|
|
||||||
duration: "1m"
|
|
||||||
# RunnerSet doesn't support scale from/to zero yet
|
|
||||||
minReplicas: 1
|
|
||||||
maxReplicas: 5
|
|
||||||
# This should be less than 600(seconds, the default) for faster testing
|
|
||||||
scaleDownDelaySecondsAfterScaleOut: 60
|
|
||||||
metrics:
|
|
||||||
- type: PercentageRunnersBusy
|
|
||||||
scaleUpThreshold: '0.75'
|
|
||||||
scaleDownThreshold: '0.3'
|
|
||||||
scaleUpFactor: '2'
|
|
||||||
scaleDownFactor: '0.5'
|
|
||||||
- type: TotalNumberOfQueuedAndInProgressWorkflowRuns
|
|
||||||
repositoryNames:
|
|
||||||
- ${TEST_REPO}
|
|
||||||
59
acceptance/testdata/repo.runnerset.yaml
vendored
59
acceptance/testdata/repo.runnerset.yaml
vendored
@@ -1,59 +0,0 @@
|
|||||||
apiVersion: actions.summerwind.dev/v1alpha1
|
|
||||||
kind: RunnerSet
|
|
||||||
metadata:
|
|
||||||
name: example-runnerset
|
|
||||||
spec:
|
|
||||||
# MANDATORY because it is based on StatefulSet: Results in a below error when omitted:
|
|
||||||
# missing required field "selector" in dev.summerwind.actions.v1alpha1.RunnerSet.spec
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: example-runnerset
|
|
||||||
|
|
||||||
# MANDATORY because it is based on StatefulSet: Results in a below error when omitted:
|
|
||||||
# missing required field "serviceName" in dev.summerwind.actions.v1alpha1.RunnerSet.spec]
|
|
||||||
serviceName: example-runnerset
|
|
||||||
|
|
||||||
#replicas: 1
|
|
||||||
|
|
||||||
# From my limited testing, `ephemeral: true` is more reliable.
|
|
||||||
# Seomtimes, updating already deployed runners from `ephemeral: false` to `ephemeral: true` seems to
|
|
||||||
# result in queued jobs hanging forever.
|
|
||||||
ephemeral: ${TEST_EPHEMERAL}
|
|
||||||
|
|
||||||
repository: ${TEST_REPO}
|
|
||||||
#
|
|
||||||
# Custom runner image
|
|
||||||
#
|
|
||||||
image: ${RUNNER_NAME}:${RUNNER_TAG}
|
|
||||||
#
|
|
||||||
# dockerd within runner container
|
|
||||||
#
|
|
||||||
## Replace `mumoshu/actions-runner-dind:dev` with your dind image
|
|
||||||
#dockerdWithinRunnerContainer: true
|
|
||||||
#
|
|
||||||
# Set the MTU used by dockerd-managed network interfaces (including docker-build-ubuntu)
|
|
||||||
#
|
|
||||||
#dockerMTU: 1450
|
|
||||||
#Runner group
|
|
||||||
# labels:
|
|
||||||
# - "mylabel 1"
|
|
||||||
# - "mylabel 2"
|
|
||||||
labels:
|
|
||||||
- "${RUNNER_LABEL}"
|
|
||||||
#
|
|
||||||
# Non-standard working directory
|
|
||||||
#
|
|
||||||
# workDir: "/"
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: example-runnerset
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: runner
|
|
||||||
imagePullPolicy: IfNotPresent
|
|
||||||
env:
|
|
||||||
- name: RUNNER_FEATURE_FLAG_EPHEMERAL
|
|
||||||
value: "${RUNNER_FEATURE_FLAG_EPHEMERAL}"
|
|
||||||
#- name: docker
|
|
||||||
# #image: mumoshu/actions-runner-dind:dev
|
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
apiVersion: actions.summerwind.dev/v1alpha1
|
apiVersion: actions.summerwind.dev/v1alpha1
|
||||||
kind: RunnerDeployment
|
kind: RunnerDeployment
|
||||||
metadata:
|
metadata:
|
||||||
name: org-runnerdeploy
|
name: ${NAME}
|
||||||
spec:
|
spec:
|
||||||
# replicas: 1
|
# replicas: 1
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
|
enterprise: ${TEST_ENTERPRISE}
|
||||||
|
group: ${TEST_GROUP}
|
||||||
organization: ${TEST_ORG}
|
organization: ${TEST_ORG}
|
||||||
|
repository: ${TEST_REPO}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Custom runner image
|
# Custom runner image
|
||||||
@@ -14,12 +17,15 @@ spec:
|
|||||||
image: ${RUNNER_NAME}:${RUNNER_TAG}
|
image: ${RUNNER_NAME}:${RUNNER_TAG}
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
|
|
||||||
|
ephemeral: ${TEST_EPHEMERAL}
|
||||||
|
|
||||||
#
|
#
|
||||||
# dockerd within runner container
|
# dockerd within runner container
|
||||||
#
|
#
|
||||||
## Replace `mumoshu/actions-runner-dind:dev` with your dind image
|
## Replace `mumoshu/actions-runner-dind:dev` with your dind image
|
||||||
#dockerdWithinRunnerContainer: true
|
#dockerdWithinRunnerContainer: true
|
||||||
#image: mumoshu/actions-runner-dind:dev
|
#image: mumoshu/actions-runner-dind:dev
|
||||||
|
dockerdWithinRunnerContainer: ${RUNNER_DOCKERD_WITHIN_RUNNER_CONTAINER}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set the MTU used by dockerd-managed network interfaces (including docker-build-ubuntu)
|
# Set the MTU used by dockerd-managed network interfaces (including docker-build-ubuntu)
|
||||||
@@ -30,8 +36,26 @@ spec:
|
|||||||
# labels:
|
# labels:
|
||||||
# - "mylabel 1"
|
# - "mylabel 1"
|
||||||
# - "mylabel 2"
|
# - "mylabel 2"
|
||||||
|
labels:
|
||||||
|
- "${RUNNER_LABEL}"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Non-standard working directory
|
# Non-standard working directory
|
||||||
#
|
#
|
||||||
# workDir: "/"
|
# workDir: "/"
|
||||||
|
---
|
||||||
|
apiVersion: actions.summerwind.dev/v1alpha1
|
||||||
|
kind: HorizontalRunnerAutoscaler
|
||||||
|
metadata:
|
||||||
|
name: ${NAME}
|
||||||
|
spec:
|
||||||
|
scaleTargetRef:
|
||||||
|
name: ${NAME}
|
||||||
|
scaleUpTriggers:
|
||||||
|
- githubEvent:
|
||||||
|
workflowJob: {}
|
||||||
|
amount: 1
|
||||||
|
duration: "10m"
|
||||||
|
minReplicas: ${RUNNER_MIN_REPLICAS}
|
||||||
|
maxReplicas: 10
|
||||||
|
scaleDownDelaySecondsAfterScaleOut: ${RUNNER_SCALE_DOWN_DELAY_SECONDS_AFTER_SCALE_OUT}
|
||||||
253
acceptance/testdata/runnerset.envsubst.yaml
vendored
Normal file
253
acceptance/testdata/runnerset.envsubst.yaml
vendored
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
---
|
||||||
|
apiVersion: storage.k8s.io/v1
|
||||||
|
kind: StorageClass
|
||||||
|
metadata:
|
||||||
|
name: ${NAME}-runner-work-dir
|
||||||
|
labels:
|
||||||
|
content: ${NAME}-runner-work-dir
|
||||||
|
provisioner: rancher.io/local-path
|
||||||
|
reclaimPolicy: Delete
|
||||||
|
volumeBindingMode: WaitForFirstConsumer
|
||||||
|
---
|
||||||
|
apiVersion: storage.k8s.io/v1
|
||||||
|
kind: StorageClass
|
||||||
|
metadata:
|
||||||
|
name: ${NAME}
|
||||||
|
# In kind environments, the provider writes:
|
||||||
|
# /var/lib/docker/volumes/KIND_NODE_CONTAINER_VOL_ID/_data/local-path-provisioner/PV_NAME
|
||||||
|
# It can be hundreds of gigabytes depending on what you cache in the test workflow. Beware to not encounter `no space left on device` errors!
|
||||||
|
# If you did encounter no space errorrs try:
|
||||||
|
# docker system prune
|
||||||
|
# docker buildx prune #=> frees up /var/lib/docker/volumes/buildx_buildkit_container-builder0_state
|
||||||
|
# sudo rm -rf /var/lib/docker/volumes/KIND_NODE_CONTAINER_VOL_ID/_data/local-path-provisioner #=> frees up local-path-provisioner's data
|
||||||
|
provisioner: rancher.io/local-path
|
||||||
|
reclaimPolicy: Retain
|
||||||
|
volumeBindingMode: WaitForFirstConsumer
|
||||||
|
---
|
||||||
|
apiVersion: storage.k8s.io/v1
|
||||||
|
kind: StorageClass
|
||||||
|
metadata:
|
||||||
|
name: ${NAME}-var-lib-docker
|
||||||
|
labels:
|
||||||
|
content: ${NAME}-var-lib-docker
|
||||||
|
provisioner: rancher.io/local-path
|
||||||
|
reclaimPolicy: Retain
|
||||||
|
volumeBindingMode: WaitForFirstConsumer
|
||||||
|
---
|
||||||
|
apiVersion: storage.k8s.io/v1
|
||||||
|
kind: StorageClass
|
||||||
|
metadata:
|
||||||
|
name: ${NAME}-cache
|
||||||
|
labels:
|
||||||
|
content: ${NAME}-cache
|
||||||
|
provisioner: rancher.io/local-path
|
||||||
|
reclaimPolicy: Retain
|
||||||
|
volumeBindingMode: WaitForFirstConsumer
|
||||||
|
---
|
||||||
|
apiVersion: storage.k8s.io/v1
|
||||||
|
kind: StorageClass
|
||||||
|
metadata:
|
||||||
|
name: ${NAME}-runner-tool-cache
|
||||||
|
labels:
|
||||||
|
content: ${NAME}-runner-tool-cache
|
||||||
|
provisioner: rancher.io/local-path
|
||||||
|
reclaimPolicy: Retain
|
||||||
|
volumeBindingMode: WaitForFirstConsumer
|
||||||
|
---
|
||||||
|
apiVersion: actions.summerwind.dev/v1alpha1
|
||||||
|
kind: RunnerSet
|
||||||
|
metadata:
|
||||||
|
name: ${NAME}
|
||||||
|
spec:
|
||||||
|
# MANDATORY because it is based on StatefulSet: Results in a below error when omitted:
|
||||||
|
# missing required field "selector" in dev.summerwind.actions.v1alpha1.RunnerSet.spec
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: ${NAME}
|
||||||
|
|
||||||
|
# MANDATORY because it is based on StatefulSet: Results in a below error when omitted:
|
||||||
|
# missing required field "serviceName" in dev.summerwind.actions.v1alpha1.RunnerSet.spec]
|
||||||
|
serviceName: ${NAME}
|
||||||
|
|
||||||
|
#replicas: 1
|
||||||
|
|
||||||
|
# From my limited testing, `ephemeral: true` is more reliable.
|
||||||
|
# Seomtimes, updating already deployed runners from `ephemeral: false` to `ephemeral: true` seems to
|
||||||
|
# result in queued jobs hanging forever.
|
||||||
|
ephemeral: ${TEST_EPHEMERAL}
|
||||||
|
|
||||||
|
enterprise: ${TEST_ENTERPRISE}
|
||||||
|
group: ${TEST_GROUP}
|
||||||
|
organization: ${TEST_ORG}
|
||||||
|
repository: ${TEST_REPO}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Custom runner image
|
||||||
|
#
|
||||||
|
image: ${RUNNER_NAME}:${RUNNER_TAG}
|
||||||
|
|
||||||
|
#
|
||||||
|
# dockerd within runner container
|
||||||
|
#
|
||||||
|
## Replace `mumoshu/actions-runner-dind:dev` with your dind image
|
||||||
|
#dockerdWithinRunnerContainer: true
|
||||||
|
dockerdWithinRunnerContainer: ${RUNNER_DOCKERD_WITHIN_RUNNER_CONTAINER}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Set the MTU used by dockerd-managed network interfaces (including docker-build-ubuntu)
|
||||||
|
#
|
||||||
|
#dockerMTU: 1450
|
||||||
|
#Runner group
|
||||||
|
# labels:
|
||||||
|
# - "mylabel 1"
|
||||||
|
# - "mylabel 2"
|
||||||
|
labels:
|
||||||
|
- "${RUNNER_LABEL}"
|
||||||
|
#
|
||||||
|
# Non-standard working directory
|
||||||
|
#
|
||||||
|
# workDir: "/"
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: ${NAME}
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: runner
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
env:
|
||||||
|
- name: RUNNER_FEATURE_FLAG_EPHEMERAL
|
||||||
|
value: "${RUNNER_FEATURE_FLAG_EPHEMERAL}"
|
||||||
|
- name: GOMODCACHE
|
||||||
|
value: "/home/runner/.cache/go-mod"
|
||||||
|
# PV-backed runner work dir
|
||||||
|
volumeMounts:
|
||||||
|
- name: work
|
||||||
|
mountPath: /runner/_work
|
||||||
|
# Cache docker image layers, in case dockerdWithinRunnerContainer=true
|
||||||
|
- name: var-lib-docker
|
||||||
|
mountPath: /var/lib/docker
|
||||||
|
# Cache go modules and builds
|
||||||
|
# - name: gocache
|
||||||
|
# # Run `goenv | grep GOCACHE` to verify the path is correct for your env
|
||||||
|
# mountPath: /home/runner/.cache/go-build
|
||||||
|
# - name: gomodcache
|
||||||
|
# # Run `goenv | grep GOMODCACHE` to verify the path is correct for your env
|
||||||
|
# # mountPath: /home/runner/go/pkg/mod
|
||||||
|
- name: cache
|
||||||
|
# go: could not create module cache: stat /home/runner/.cache/go-mod: permission denied
|
||||||
|
mountPath: "/home/runner/.cache"
|
||||||
|
- name: runner-tool-cache
|
||||||
|
# This corresponds to our runner image's default setting of RUNNER_TOOL_CACHE=/opt/hostedtoolcache.
|
||||||
|
#
|
||||||
|
# In case you customize the envvar in both runner and docker containers of the runner pod spec,
|
||||||
|
# You'd need to change this mountPath accordingly.
|
||||||
|
#
|
||||||
|
# The tool cache directory is defined in actions/toolkit's tool-cache module:
|
||||||
|
# https://github.com/actions/toolkit/blob/2f164000dcd42fb08287824a3bc3030dbed33687/packages/tool-cache/src/tool-cache.ts#L621-L638
|
||||||
|
#
|
||||||
|
# Many setup-* actions like setup-go utilizes the tool-cache module to download and cache installed binaries:
|
||||||
|
# https://github.com/actions/setup-go/blob/56a61c9834b4a4950dbbf4740af0b8a98c73b768/src/installer.ts#L144
|
||||||
|
mountPath: "/opt/hostedtoolcache"
|
||||||
|
# Valid only when dockerdWithinRunnerContainer=false
|
||||||
|
- name: docker
|
||||||
|
# PV-backed runner work dir
|
||||||
|
volumeMounts:
|
||||||
|
- name: work
|
||||||
|
mountPath: /runner/_work
|
||||||
|
# Cache docker image layers, in case dockerdWithinRunnerContainer=false
|
||||||
|
- name: var-lib-docker
|
||||||
|
mountPath: /var/lib/docker
|
||||||
|
# image: mumoshu/actions-runner-dind:dev
|
||||||
|
|
||||||
|
# For buildx cache
|
||||||
|
- name: cache
|
||||||
|
mountPath: "/home/runner/.cache"
|
||||||
|
volumes:
|
||||||
|
- name: work
|
||||||
|
ephemeral:
|
||||||
|
volumeClaimTemplate:
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
storageClassName: "${NAME}-runner-work-dir"
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Gi
|
||||||
|
volumeClaimTemplates:
|
||||||
|
- metadata:
|
||||||
|
name: vol1
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Mi
|
||||||
|
storageClassName: ${NAME}
|
||||||
|
## Dunno which provider supports auto-provisioning with selector.
|
||||||
|
## At least the rancher local path provider stopped with:
|
||||||
|
## waiting for a volume to be created, either by external provisioner "rancher.io/local-path" or manually created by system administrator
|
||||||
|
# selector:
|
||||||
|
# matchLabels:
|
||||||
|
# runnerset-volume-id: ${NAME}-vol1
|
||||||
|
- metadata:
|
||||||
|
name: vol2
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Mi
|
||||||
|
storageClassName: ${NAME}
|
||||||
|
# selector:
|
||||||
|
# matchLabels:
|
||||||
|
# runnerset-volume-id: ${NAME}-vol2
|
||||||
|
- metadata:
|
||||||
|
name: var-lib-docker
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Mi
|
||||||
|
storageClassName: ${NAME}-var-lib-docker
|
||||||
|
- metadata:
|
||||||
|
name: cache
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Mi
|
||||||
|
storageClassName: ${NAME}-cache
|
||||||
|
- metadata:
|
||||||
|
name: runner-tool-cache
|
||||||
|
# It turns out labels doesn't distinguish PVs across PVCs and the
|
||||||
|
# end result is PVs are reused by wrong PVCs.
|
||||||
|
# The correct way seems to be to differentiate storage class per pvc template.
|
||||||
|
# labels:
|
||||||
|
# id: runner-tool-cache
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Mi
|
||||||
|
storageClassName: ${NAME}-runner-tool-cache
|
||||||
|
---
|
||||||
|
apiVersion: actions.summerwind.dev/v1alpha1
|
||||||
|
kind: HorizontalRunnerAutoscaler
|
||||||
|
metadata:
|
||||||
|
name: ${NAME}
|
||||||
|
spec:
|
||||||
|
scaleTargetRef:
|
||||||
|
kind: RunnerSet
|
||||||
|
name: ${NAME}
|
||||||
|
scaleUpTriggers:
|
||||||
|
- githubEvent:
|
||||||
|
workflowJob: {}
|
||||||
|
amount: 1
|
||||||
|
duration: "10m"
|
||||||
|
minReplicas: ${RUNNER_MIN_REPLICAS}
|
||||||
|
maxReplicas: 10
|
||||||
|
scaleDownDelaySecondsAfterScaleOut: ${RUNNER_SCALE_DOWN_DELAY_SECONDS_AFTER_SCALE_OUT}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
# Set actions-runner-controller settings for testing
|
# Set actions-runner-controller settings for testing
|
||||||
githubAPICacheDuration: 10s
|
logLevel: "-4"
|
||||||
githubWebhookServer:
|
githubWebhookServer:
|
||||||
|
logLevel: "-4"
|
||||||
enabled: true
|
enabled: true
|
||||||
labels: {}
|
labels: {}
|
||||||
replicaCount: 1
|
replicaCount: 1
|
||||||
syncPeriod: 10m
|
syncPeriod: 10m
|
||||||
|
useRunnerGroupsVisibility: true
|
||||||
secret:
|
secret:
|
||||||
create: true
|
enabled: true
|
||||||
|
# create: true
|
||||||
name: "github-webhook-server"
|
name: "github-webhook-server"
|
||||||
### GitHub Webhook Configuration
|
### GitHub Webhook Configuration
|
||||||
#github_webhook_secret_token: ""
|
#github_webhook_secret_token: ""
|
||||||
|
|||||||
@@ -72,10 +72,12 @@ type GitHubEventScaleUpTriggerSpec struct {
|
|||||||
CheckRun *CheckRunSpec `json:"checkRun,omitempty"`
|
CheckRun *CheckRunSpec `json:"checkRun,omitempty"`
|
||||||
PullRequest *PullRequestSpec `json:"pullRequest,omitempty"`
|
PullRequest *PullRequestSpec `json:"pullRequest,omitempty"`
|
||||||
Push *PushSpec `json:"push,omitempty"`
|
Push *PushSpec `json:"push,omitempty"`
|
||||||
|
WorkflowJob *WorkflowJobSpec `json:"workflowJob,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://docs.github.com/en/actions/reference/events-that-trigger-workflows#check_run
|
// https://docs.github.com/en/actions/reference/events-that-trigger-workflows#check_run
|
||||||
type CheckRunSpec struct {
|
type CheckRunSpec struct {
|
||||||
|
// One of: created, rerequested, or completed
|
||||||
Types []string `json:"types,omitempty"`
|
Types []string `json:"types,omitempty"`
|
||||||
Status string `json:"status,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
|
|
||||||
@@ -90,6 +92,10 @@ type CheckRunSpec struct {
|
|||||||
Repositories []string `json:"repositories,omitempty"`
|
Repositories []string `json:"repositories,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_job
|
||||||
|
type WorkflowJobSpec struct {
|
||||||
|
}
|
||||||
|
|
||||||
// https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request
|
// https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request
|
||||||
type PullRequestSpec struct {
|
type PullRequestSpec struct {
|
||||||
Types []string `json:"types,omitempty"`
|
Types []string `json:"types,omitempty"`
|
||||||
@@ -107,6 +113,9 @@ type CapacityReservation struct {
|
|||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
ExpirationTime metav1.Time `json:"expirationTime,omitempty"`
|
ExpirationTime metav1.Time `json:"expirationTime,omitempty"`
|
||||||
Replicas int `json:"replicas,omitempty"`
|
Replicas int `json:"replicas,omitempty"`
|
||||||
|
|
||||||
|
// +optional
|
||||||
|
EffectiveTime metav1.Time `json:"effectiveTime,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ScaleTargetRef struct {
|
type ScaleTargetRef struct {
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ type RunnerPodSpec struct {
|
|||||||
// +optional
|
// +optional
|
||||||
DockerVolumeMounts []corev1.VolumeMount `json:"dockerVolumeMounts,omitempty"`
|
DockerVolumeMounts []corev1.VolumeMount `json:"dockerVolumeMounts,omitempty"`
|
||||||
|
|
||||||
|
// +optional
|
||||||
|
DockerEnv []corev1.EnvVar `json:"dockerEnv,omitempty"`
|
||||||
|
|
||||||
// +optional
|
// +optional
|
||||||
Containers []corev1.Container `json:"containers,omitempty"`
|
Containers []corev1.Container `json:"containers,omitempty"`
|
||||||
|
|
||||||
@@ -142,7 +145,7 @@ type RunnerPodSpec struct {
|
|||||||
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
|
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
|
||||||
|
|
||||||
// +optional
|
// +optional
|
||||||
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraint,omitempty"`
|
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
|
||||||
|
|
||||||
// RuntimeClassName is the container runtime configuration that containers should run under.
|
// RuntimeClassName is the container runtime configuration that containers should run under.
|
||||||
// More info: https://kubernetes.io/docs/concepts/containers/runtime-class
|
// More info: https://kubernetes.io/docs/concepts/containers/runtime-class
|
||||||
@@ -150,7 +153,7 @@ type RunnerPodSpec struct {
|
|||||||
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
|
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
|
||||||
|
|
||||||
// +optional
|
// +optional
|
||||||
DnsConfig []corev1.PodDNSConfig `json:"dnsConfig,omitempty"`
|
DnsConfig *corev1.PodDNSConfig `json:"dnsConfig,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateRepository validates repository field.
|
// ValidateRepository validates repository field.
|
||||||
@@ -178,6 +181,9 @@ func (rs *RunnerSpec) ValidateRepository() error {
|
|||||||
|
|
||||||
// RunnerStatus defines the observed state of Runner
|
// RunnerStatus defines the observed state of Runner
|
||||||
type RunnerStatus struct {
|
type RunnerStatus struct {
|
||||||
|
// Turns true only if the runner pod is ready.
|
||||||
|
// +optional
|
||||||
|
Ready bool `json:"ready"`
|
||||||
// +optional
|
// +optional
|
||||||
Registration RunnerStatusRegistration `json:"registration"`
|
Registration RunnerStatusRegistration `json:"registration"`
|
||||||
// +optional
|
// +optional
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ type RunnerDeploymentSpec struct {
|
|||||||
// +nullable
|
// +nullable
|
||||||
Replicas *int `json:"replicas,omitempty"`
|
Replicas *int `json:"replicas,omitempty"`
|
||||||
|
|
||||||
|
// EffectiveTime is the time the upstream controller requested to sync Replicas.
|
||||||
|
// It is usually populated by the webhook-based autoscaler via HRA.
|
||||||
|
// The value is inherited to RunnerRepicaSet(s) and used to prevent ephemeral runners from unnecessarily recreated.
|
||||||
|
//
|
||||||
|
// +optional
|
||||||
|
// +nullable
|
||||||
|
EffectiveTime *metav1.Time `json:"effectiveTime"`
|
||||||
|
|
||||||
// +optional
|
// +optional
|
||||||
// +nullable
|
// +nullable
|
||||||
Selector *metav1.LabelSelector `json:"selector"`
|
Selector *metav1.LabelSelector `json:"selector"`
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// log is for logging in this package.
|
// log is for logging in this package.
|
||||||
var runenrDeploymentLog = logf.Log.WithName("runnerdeployment-resource")
|
var runnerDeploymentLog = logf.Log.WithName("runnerdeployment-resource")
|
||||||
|
|
||||||
func (r *RunnerDeployment) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
func (r *RunnerDeployment) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
||||||
return ctrl.NewWebhookManagedBy(mgr).
|
return ctrl.NewWebhookManagedBy(mgr).
|
||||||
@@ -49,13 +49,13 @@ var _ webhook.Validator = &RunnerDeployment{}
|
|||||||
|
|
||||||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
||||||
func (r *RunnerDeployment) ValidateCreate() error {
|
func (r *RunnerDeployment) ValidateCreate() error {
|
||||||
runenrDeploymentLog.Info("validate resource to be created", "name", r.Name)
|
runnerDeploymentLog.Info("validate resource to be created", "name", r.Name)
|
||||||
return r.Validate()
|
return r.Validate()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
||||||
func (r *RunnerDeployment) ValidateUpdate(old runtime.Object) error {
|
func (r *RunnerDeployment) ValidateUpdate(old runtime.Object) error {
|
||||||
runenrDeploymentLog.Info("validate resource to be updated", "name", r.Name)
|
runnerDeploymentLog.Info("validate resource to be updated", "name", r.Name)
|
||||||
return r.Validate()
|
return r.Validate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,15 @@ type RunnerReplicaSetSpec struct {
|
|||||||
// +nullable
|
// +nullable
|
||||||
Replicas *int `json:"replicas,omitempty"`
|
Replicas *int `json:"replicas,omitempty"`
|
||||||
|
|
||||||
|
// EffectiveTime is the time the upstream controller requested to sync Replicas.
|
||||||
|
// It is usually populated by the webhook-based autoscaler via HRA and RunnerDeployment.
|
||||||
|
// The value is used to prevent runnerreplicaset controller from unnecessarily recreating ephemeral runners
|
||||||
|
// based on potentially outdated Replicas value.
|
||||||
|
//
|
||||||
|
// +optional
|
||||||
|
// +nullable
|
||||||
|
EffectiveTime *metav1.Time `json:"effectiveTime"`
|
||||||
|
|
||||||
// +optional
|
// +optional
|
||||||
// +nullable
|
// +nullable
|
||||||
Selector *metav1.LabelSelector `json:"selector"`
|
Selector *metav1.LabelSelector `json:"selector"`
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ import (
|
|||||||
type RunnerSetSpec struct {
|
type RunnerSetSpec struct {
|
||||||
RunnerConfig `json:",inline"`
|
RunnerConfig `json:",inline"`
|
||||||
|
|
||||||
|
// EffectiveTime is the time the upstream controller requested to sync Replicas.
|
||||||
|
// It is usually populated by the webhook-based autoscaler via HRA.
|
||||||
|
// It is used to prevent ephemeral runners from unnecessarily recreated.
|
||||||
|
//
|
||||||
|
// +optional
|
||||||
|
// +nullable
|
||||||
|
EffectiveTime *metav1.Time `json:"effectiveTime,omitempty"`
|
||||||
|
|
||||||
appsv1.StatefulSetSpec `json:",inline"`
|
appsv1.StatefulSetSpec `json:",inline"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ func (in *CacheEntry) DeepCopy() *CacheEntry {
|
|||||||
func (in *CapacityReservation) DeepCopyInto(out *CapacityReservation) {
|
func (in *CapacityReservation) DeepCopyInto(out *CapacityReservation) {
|
||||||
*out = *in
|
*out = *in
|
||||||
in.ExpirationTime.DeepCopyInto(&out.ExpirationTime)
|
in.ExpirationTime.DeepCopyInto(&out.ExpirationTime)
|
||||||
|
in.EffectiveTime.DeepCopyInto(&out.EffectiveTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CapacityReservation.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CapacityReservation.
|
||||||
@@ -107,6 +108,11 @@ func (in *GitHubEventScaleUpTriggerSpec) DeepCopyInto(out *GitHubEventScaleUpTri
|
|||||||
*out = new(PushSpec)
|
*out = new(PushSpec)
|
||||||
**out = **in
|
**out = **in
|
||||||
}
|
}
|
||||||
|
if in.WorkflowJob != nil {
|
||||||
|
in, out := &in.WorkflowJob, &out.WorkflowJob
|
||||||
|
*out = new(WorkflowJobSpec)
|
||||||
|
**out = **in
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitHubEventScaleUpTriggerSpec.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitHubEventScaleUpTriggerSpec.
|
||||||
@@ -498,6 +504,10 @@ func (in *RunnerDeploymentSpec) DeepCopyInto(out *RunnerDeploymentSpec) {
|
|||||||
*out = new(int)
|
*out = new(int)
|
||||||
**out = **in
|
**out = **in
|
||||||
}
|
}
|
||||||
|
if in.EffectiveTime != nil {
|
||||||
|
in, out := &in.EffectiveTime, &out.EffectiveTime
|
||||||
|
*out = (*in).DeepCopy()
|
||||||
|
}
|
||||||
if in.Selector != nil {
|
if in.Selector != nil {
|
||||||
in, out := &in.Selector, &out.Selector
|
in, out := &in.Selector, &out.Selector
|
||||||
*out = new(metav1.LabelSelector)
|
*out = new(metav1.LabelSelector)
|
||||||
@@ -599,6 +609,13 @@ func (in *RunnerPodSpec) DeepCopyInto(out *RunnerPodSpec) {
|
|||||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if in.DockerEnv != nil {
|
||||||
|
in, out := &in.DockerEnv, &out.DockerEnv
|
||||||
|
*out = make([]v1.EnvVar, len(*in))
|
||||||
|
for i := range *in {
|
||||||
|
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
if in.Containers != nil {
|
if in.Containers != nil {
|
||||||
in, out := &in.Containers, &out.Containers
|
in, out := &in.Containers, &out.Containers
|
||||||
*out = make([]v1.Container, len(*in))
|
*out = make([]v1.Container, len(*in))
|
||||||
@@ -721,10 +738,8 @@ func (in *RunnerPodSpec) DeepCopyInto(out *RunnerPodSpec) {
|
|||||||
}
|
}
|
||||||
if in.DnsConfig != nil {
|
if in.DnsConfig != nil {
|
||||||
in, out := &in.DnsConfig, &out.DnsConfig
|
in, out := &in.DnsConfig, &out.DnsConfig
|
||||||
*out = make([]v1.PodDNSConfig, len(*in))
|
*out = new(v1.PodDNSConfig)
|
||||||
for i := range *in {
|
(*in).DeepCopyInto(*out)
|
||||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -805,6 +820,10 @@ func (in *RunnerReplicaSetSpec) DeepCopyInto(out *RunnerReplicaSetSpec) {
|
|||||||
*out = new(int)
|
*out = new(int)
|
||||||
**out = **in
|
**out = **in
|
||||||
}
|
}
|
||||||
|
if in.EffectiveTime != nil {
|
||||||
|
in, out := &in.EffectiveTime, &out.EffectiveTime
|
||||||
|
*out = (*in).DeepCopy()
|
||||||
|
}
|
||||||
if in.Selector != nil {
|
if in.Selector != nil {
|
||||||
in, out := &in.Selector, &out.Selector
|
in, out := &in.Selector, &out.Selector
|
||||||
*out = new(metav1.LabelSelector)
|
*out = new(metav1.LabelSelector)
|
||||||
@@ -916,6 +935,10 @@ func (in *RunnerSetList) DeepCopyObject() runtime.Object {
|
|||||||
func (in *RunnerSetSpec) DeepCopyInto(out *RunnerSetSpec) {
|
func (in *RunnerSetSpec) DeepCopyInto(out *RunnerSetSpec) {
|
||||||
*out = *in
|
*out = *in
|
||||||
in.RunnerConfig.DeepCopyInto(&out.RunnerConfig)
|
in.RunnerConfig.DeepCopyInto(&out.RunnerConfig)
|
||||||
|
if in.EffectiveTime != nil {
|
||||||
|
in, out := &in.EffectiveTime, &out.EffectiveTime
|
||||||
|
*out = (*in).DeepCopy()
|
||||||
|
}
|
||||||
in.StatefulSetSpec.DeepCopyInto(&out.StatefulSetSpec)
|
in.StatefulSetSpec.DeepCopyInto(&out.StatefulSetSpec)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1102,3 +1125,18 @@ func (in *ScheduledOverride) DeepCopy() *ScheduledOverride {
|
|||||||
in.DeepCopyInto(out)
|
in.DeepCopyInto(out)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *WorkflowJobSpec) DeepCopyInto(out *WorkflowJobSpec) {
|
||||||
|
*out = *in
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkflowJobSpec.
|
||||||
|
func (in *WorkflowJobSpec) DeepCopy() *WorkflowJobSpec {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(WorkflowJobSpec)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ type: application
|
|||||||
# This is the chart version. This version number should be incremented each time you make changes
|
# This is the chart version. This version number should be incremented each time you make changes
|
||||||
# to the chart and its templates, including the app version.
|
# to the chart and its templates, including the app version.
|
||||||
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
||||||
version: 0.15.0
|
version: 0.19.0
|
||||||
|
|
||||||
# Used as the default manager tag value when no tag property is provided in the values.yaml
|
# Used as the default manager tag value when no tag property is provided in the values.yaml
|
||||||
appVersion: 0.20.3
|
appVersion: 0.24.0
|
||||||
|
|
||||||
home: https://github.com/actions-runner-controller/actions-runner-controller
|
home: https://github.com/actions-runner-controller/actions-runner-controller
|
||||||
|
|
||||||
|
|||||||
@@ -4,20 +4,25 @@ All additional docs are kept in the `docs/` folder, this README is solely for do
|
|||||||
|
|
||||||
## Values
|
## Values
|
||||||
|
|
||||||
**_The values are documented as of HEAD, to review the configuration options for your chart version ensure you view this file at the relevent [tag](https://github.com/actions-runner-controller/actions-runner-controller/tags)_**
|
**_The values are documented as of HEAD, to review the configuration options for your chart version ensure you view this file at the relevant [tag](https://github.com/actions-runner-controller/actions-runner-controller/tags)_**
|
||||||
|
|
||||||
> _Default values are the defaults set in the charts values.yaml, some properties have default configurations in the code for when the property is omitted or invalid_
|
> _Default values are the defaults set in the charts `values.yaml`, some properties have default configurations in the code for when the property is omitted or invalid_
|
||||||
|
|
||||||
| Key | Description | Default |
|
| Key | Description | Default |
|
||||||
|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
|
|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
|
||||||
| `labels` | Set labels to apply to all resources in the chart | |
|
| `labels` | Set labels to apply to all resources in the chart | |
|
||||||
| `replicaCount` | Set the number of controller pods | 1 |
|
| `replicaCount` | Set the number of controller pods | 1 |
|
||||||
|
| `webhookPort` | Set the containerPort for the webhook Pod | 9443 |
|
||||||
| `syncPeriod` | Set the period in which the controler reconciles the desired runners count | 10m |
|
| `syncPeriod` | Set the period in which the controler reconciles the desired runners count | 10m |
|
||||||
| `enableLeaderElection` | Enable election configuration | true |
|
| `enableLeaderElection` | Enable election configuration | true |
|
||||||
| `leaderElectionId` | Set the election ID for the controller group | |
|
| `leaderElectionId` | Set the election ID for the controller group | |
|
||||||
| `githubAPICacheDuration` | Set the cache period for API calls | |
|
|
||||||
| `githubEnterpriseServerURL` | Set the URL for a self-hosted GitHub Enterprise Server | |
|
| `githubEnterpriseServerURL` | Set the URL for a self-hosted GitHub Enterprise Server | |
|
||||||
|
| `githubURL` | Override GitHub URL to be used for GitHub API calls | |
|
||||||
|
| `githubUploadURL` | Override GitHub Upload URL to be used for GitHub API calls | |
|
||||||
|
| `runnerGithubURL` | Override GitHub URL to be used by runners during registration | |
|
||||||
| `logLevel` | Set the log level of the controller container | |
|
| `logLevel` | Set the log level of the controller container | |
|
||||||
|
| `additionalVolumes` | Set additional volumes to add to the manager container | |
|
||||||
|
| `additionalVolumeMounts` | Set additional volume mounts to add to the manager container | |
|
||||||
| `authSecret.create` | Deploy the controller auth secret | false |
|
| `authSecret.create` | Deploy the controller auth secret | false |
|
||||||
| `authSecret.name` | Set the name of the auth secret | controller-manager |
|
| `authSecret.name` | Set the name of the auth secret | controller-manager |
|
||||||
| `authSecret.annotations` | Set annotations for the auth Secret | |
|
| `authSecret.annotations` | Set annotations for the auth Secret | |
|
||||||
@@ -25,10 +30,14 @@ All additional docs are kept in the `docs/` folder, this README is solely for do
|
|||||||
| `authSecret.github_app_installation_id` | The ID of your GitHub App installation. **This can't be set at the same time as `authSecret.github_token`** | |
|
| `authSecret.github_app_installation_id` | The ID of your GitHub App installation. **This can't be set at the same time as `authSecret.github_token`** | |
|
||||||
| `authSecret.github_app_private_key` | The multiline string of your GitHub App's private key. **This can't be set at the same time as `authSecret.github_token`** | |
|
| `authSecret.github_app_private_key` | The multiline string of your GitHub App's private key. **This can't be set at the same time as `authSecret.github_token`** | |
|
||||||
| `authSecret.github_token` | Your chosen GitHub PAT token. **This can't be set at the same time as the `authSecret.github_app_*`** | |
|
| `authSecret.github_token` | Your chosen GitHub PAT token. **This can't be set at the same time as the `authSecret.github_app_*`** | |
|
||||||
|
| `authSecret.github_basicauth_username` | Username for GitHub basic auth to use instead of PAT or GitHub APP in case it's running behind a proxy API | |
|
||||||
|
| `authSecret.github_basicauth_password` | Password for GitHub basic auth to use instead of PAT or GitHub APP in case it's running behind a proxy API | |
|
||||||
| `dockerRegistryMirror` | The default Docker Registry Mirror used by runners. | |
|
| `dockerRegistryMirror` | The default Docker Registry Mirror used by runners. | |
|
||||||
|
| `hostNetwork` | The "hostNetwork" of the controller container | false |
|
||||||
| `image.repository` | The "repository/image" of the controller container | summerwind/actions-runner-controller |
|
| `image.repository` | The "repository/image" of the controller container | summerwind/actions-runner-controller |
|
||||||
| `image.tag` | The tag of the controller container | |
|
| `image.tag` | The tag of the controller container | |
|
||||||
| `image.actionsRunnerRepositoryAndTag` | The "repository/image" of the actions runner container | summerwind/actions-runner:latest |
|
| `image.actionsRunnerRepositoryAndTag` | The "repository/image" of the actions runner container | summerwind/actions-runner:latest |
|
||||||
|
| `image.actionsRunnerImagePullSecrets` | Optional image pull secrets to be included in the runner pod's ImagePullSecrets | |
|
||||||
| `image.dindSidecarRepositoryAndTag` | The "repository/image" of the dind sidecar container | docker:dind |
|
| `image.dindSidecarRepositoryAndTag` | The "repository/image" of the dind sidecar container | docker:dind |
|
||||||
| `image.pullPolicy` | The pull policy of the controller image | IfNotPresent |
|
| `image.pullPolicy` | The pull policy of the controller image | IfNotPresent |
|
||||||
| `metrics.serviceMonitor` | Deploy serviceMonitor kind for for use with prometheus-operator CRDs | false |
|
| `metrics.serviceMonitor` | Deploy serviceMonitor kind for for use with prometheus-operator CRDs | false |
|
||||||
@@ -39,9 +48,9 @@ All additional docs are kept in the `docs/` folder, this README is solely for do
|
|||||||
| `metrics.proxy.image.tag` | The tag of the kube-proxy image to use when pulling the container | v0.10.0 |
|
| `metrics.proxy.image.tag` | The tag of the kube-proxy image to use when pulling the container | v0.10.0 |
|
||||||
| `metrics.serviceMonitorLabels` | Set labels to apply to ServiceMonitor resources | |
|
| `metrics.serviceMonitorLabels` | Set labels to apply to ServiceMonitor resources | |
|
||||||
| `imagePullSecrets` | Specifies the secret to be used when pulling the controller pod containers | |
|
| `imagePullSecrets` | Specifies the secret to be used when pulling the controller pod containers | |
|
||||||
| `fullNameOverride` | Override the full resource names | |
|
| `fullnameOverride` | Override the full resource names | |
|
||||||
| `nameOverride` | Override the resource name prefix | |
|
| `nameOverride` | Override the resource name prefix | |
|
||||||
| `serviceAccont.annotations` | Set annotations to the service account | |
|
| `serviceAccount.annotations` | Set annotations to the service account | |
|
||||||
| `serviceAccount.create` | Deploy the controller pod under a service account | true |
|
| `serviceAccount.create` | Deploy the controller pod under a service account | true |
|
||||||
| `podAnnotations` | Set annotations for the controller pod | |
|
| `podAnnotations` | Set annotations for the controller pod | |
|
||||||
| `podLabels` | Set labels for the controller pod | |
|
| `podLabels` | Set labels for the controller pod | |
|
||||||
@@ -49,30 +58,34 @@ All additional docs are kept in the `docs/` folder, this README is solely for do
|
|||||||
| `securityContext` | Set the security context for each container in the controller pod | |
|
| `securityContext` | Set the security context for each container in the controller pod | |
|
||||||
| `podSecurityContext` | Set the security context to controller pod | |
|
| `podSecurityContext` | Set the security context to controller pod | |
|
||||||
| `service.annotations` | Set annotations for the provisioned webhook service resource | |
|
| `service.annotations` | Set annotations for the provisioned webhook service resource | |
|
||||||
| `service.port` | Set controller service type | |
|
| `service.port` | Set controller service ports | |
|
||||||
| `service.type` | Set controller service ports | |
|
| `service.type` | Set controller service type | |
|
||||||
| `topologySpreadConstraints` | Set the controller pod topologySpreadConstraints | |
|
| `topologySpreadConstraints` | Set the controller pod topologySpreadConstraints | |
|
||||||
| `nodeSelector` | Set the controller pod nodeSelector | |
|
| `nodeSelector` | Set the controller pod nodeSelector | |
|
||||||
| `resources` | Set the controller pod resources | |
|
| `resources` | Set the controller pod resources | |
|
||||||
| `affinity` | Set the controller pod affinity rules |
|
| `affinity` | Set the controller pod affinity rules | |
|
||||||
| `podDisruptionBudget.enabled` | Enables a PDB to ensure HA of controller pods | false |
|
| `podDisruptionBudget.enabled` | Enables a PDB to ensure HA of controller pods | false |
|
||||||
| `podDisruptionBudget.minAvailable` | Minimum number of pods that must be available after eviction | |
|
| `podDisruptionBudget.minAvailable` | Minimum number of pods that must be available after eviction | |
|
||||||
| `podDisruptionBudget.maxUnavailable` | Maximum number of pods that can be unavailable after eviction. Kubernetes 1.7+ required. | |
|
| `podDisruptionBudget.maxUnavailable` | Maximum number of pods that can be unavailable after eviction. Kubernetes 1.7+ required. | |
|
||||||
| `tolerations` | Set the controller pod tolerations | |
|
| `tolerations` | Set the controller pod tolerations | |
|
||||||
| `env` | Set environment variables for the controller container | |
|
| `env` | Set environment variables for the controller container | |
|
||||||
| `priorityClassName` | Set the controller pod priorityClassName | |
|
| `priorityClassName` | Set the controller pod priorityClassName | |
|
||||||
| `scope.watchNamespace` | Tells the controller and the github webhook server which namespace to watch if `scope.singleNamespace` is true | `Release.Namespace` (the default namespace of the helm chart). |
|
| `scope.watchNamespace` | Tells the controller and the github webhook server which namespace to watch if `scope.singleNamespace` is true | `Release.Namespace` (the default namespace of the helm chart). |
|
||||||
| `scope.singleNamespace` | Limit the controller to watch a single namespace | false |
|
| `scope.singleNamespace` | Limit the controller to watch a single namespace | false |
|
||||||
|
| `certManagerEnabled` | Enable cert-manager. If disabled you must set admissionWebHooks.caBundle and create TLS secrets manually | true |
|
||||||
|
| `admissionWebHooks.caBundle` | Base64-encoded PEM bundle containing the CA that signed the webhook's serving certificate | |
|
||||||
| `githubWebhookServer.logLevel` | Set the log level of the githubWebhookServer container | |
|
| `githubWebhookServer.logLevel` | Set the log level of the githubWebhookServer container | |
|
||||||
| `githubWebhookServer.replicaCount` | Set the number of webhook server pods | 1 |
|
| `githubWebhookServer.replicaCount` | Set the number of webhook server pods | 1 |
|
||||||
|
| `githubWebhookServer.useRunnerGroupsVisibility` | Enable supporting runner groups with custom visibility. This will incur in extra API calls and may blow up your budget. Currently, you also need to set `githubWebhookServer.secret.enabled` to enable this feature. | false |
|
||||||
| `githubWebhookServer.syncPeriod` | Set the period in which the controller reconciles the resources | 10m |
|
| `githubWebhookServer.syncPeriod` | Set the period in which the controller reconciles the resources | 10m |
|
||||||
| `githubWebhookServer.enabled` | Deploy the webhook server pod | false |
|
| `githubWebhookServer.enabled` | Deploy the webhook server pod | false |
|
||||||
|
| `githubWebhookServer.secret.enabled` | Passes the webhook hook secret to the github-webhook-server | false |
|
||||||
| `githubWebhookServer.secret.create` | Deploy the webhook hook secret | false |
|
| `githubWebhookServer.secret.create` | Deploy the webhook hook secret | false |
|
||||||
| `githubWebhookServer.secret.name` | Set the name of the webhook hook secret | github-webhook-server |
|
| `githubWebhookServer.secret.name` | Set the name of the webhook hook secret | github-webhook-server |
|
||||||
| `githubWebhookServer.secret.github_webhook_secret_token` | Set the webhook secret token value | |
|
| `githubWebhookServer.secret.github_webhook_secret_token` | Set the webhook secret token value | |
|
||||||
| `githubWebhookServer.imagePullSecrets` | Specifies the secret to be used when pulling the githubWebhookServer pod containers | |
|
| `githubWebhookServer.imagePullSecrets` | Specifies the secret to be used when pulling the githubWebhookServer pod containers | |
|
||||||
| `githubWebhookServer.nameOveride` | Override the resource name prefix | |
|
| `githubWebhookServer.nameOverride` | Override the resource name prefix | |
|
||||||
| `githubWebhookServer.fullNameOveride` | Override the full resource names | |
|
| `githubWebhookServer.fullnameOverride` | Override the full resource names | |
|
||||||
| `githubWebhookServer.serviceAccount.create` | Deploy the githubWebhookServer under a service account | true |
|
| `githubWebhookServer.serviceAccount.create` | Deploy the githubWebhookServer under a service account | true |
|
||||||
| `githubWebhookServer.serviceAccount.annotations` | Set annotations for the service account | |
|
| `githubWebhookServer.serviceAccount.annotations` | Set annotations for the service account | |
|
||||||
| `githubWebhookServer.serviceAccount.name` | Set the service account name | |
|
| `githubWebhookServer.serviceAccount.name` | Set the service account name | |
|
||||||
@@ -92,6 +105,7 @@ All additional docs are kept in the `docs/` folder, this README is solely for do
|
|||||||
| `githubWebhookServer.ingress.annotations` | Set annotations for the ingress kind | |
|
| `githubWebhookServer.ingress.annotations` | Set annotations for the ingress kind | |
|
||||||
| `githubWebhookServer.ingress.hosts` | Set hosts configuration for ingress | `[{"host": "chart-example.local", "paths": []}]` |
|
| `githubWebhookServer.ingress.hosts` | Set hosts configuration for ingress | `[{"host": "chart-example.local", "paths": []}]` |
|
||||||
| `githubWebhookServer.ingress.tls` | Set tls configuration for ingress | |
|
| `githubWebhookServer.ingress.tls` | Set tls configuration for ingress | |
|
||||||
| `githubWebhookServer.podDisruptionBudget.enabled` | Enables a PDB to ensure HA of githubwebhook pods | false |
|
| `githubWebhookServer.ingress.ingressClassName` | Set ingress class name | |
|
||||||
| `githubWebhookServer.podDisruptionBudget.minAvailable` | Minimum number of pods that must be available after eviction | |
|
| `githubWebhookServer.podDisruptionBudget.enabled` | Enables a PDB to ensure HA of githubwebhook pods | false |
|
||||||
| `githubWebhookServer.podDisruptionBudget.maxUnavailable` | Maximum number of pods that can be unavailable after eviction. Kubernetes 1.7+ required. | |
|
| `githubWebhookServer.podDisruptionBudget.minAvailable` | Minimum number of pods that must be available after eviction | |
|
||||||
|
| `githubWebhookServer.podDisruptionBudget.maxUnavailable` | Maximum number of pods that can be unavailable after eviction. Kubernetes 1.7+ required. | |
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
|
|||||||
kind: CustomResourceDefinition
|
kind: CustomResourceDefinition
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
controller-gen.kubebuilder.io/version: v0.6.0
|
controller-gen.kubebuilder.io/version: v0.7.0
|
||||||
creationTimestamp: null
|
creationTimestamp: null
|
||||||
name: horizontalrunnerautoscalers.actions.summerwind.dev
|
name: horizontalrunnerautoscalers.actions.summerwind.dev
|
||||||
spec:
|
spec:
|
||||||
@@ -49,6 +49,9 @@ spec:
|
|||||||
items:
|
items:
|
||||||
description: CapacityReservation specifies the number of replicas temporarily added to the scale target until ExpirationTime.
|
description: CapacityReservation specifies the number of replicas temporarily added to the scale target until ExpirationTime.
|
||||||
properties:
|
properties:
|
||||||
|
effectiveTime:
|
||||||
|
format: date-time
|
||||||
|
type: string
|
||||||
expirationTime:
|
expirationTime:
|
||||||
format: date-time
|
format: date-time
|
||||||
type: string
|
type: string
|
||||||
@@ -138,6 +141,7 @@ spec:
|
|||||||
status:
|
status:
|
||||||
type: string
|
type: string
|
||||||
types:
|
types:
|
||||||
|
description: 'One of: created, rerequested, or completed'
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
type: array
|
type: array
|
||||||
@@ -157,6 +161,9 @@ spec:
|
|||||||
push:
|
push:
|
||||||
description: PushSpec is the condition for triggering scale-up on push event Also see https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push
|
description: PushSpec is the condition for triggering scale-up on push event Also see https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push
|
||||||
type: object
|
type: object
|
||||||
|
workflowJob:
|
||||||
|
description: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_job
|
||||||
|
type: object
|
||||||
type: object
|
type: object
|
||||||
type: object
|
type: object
|
||||||
type: array
|
type: array
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -18,20 +18,23 @@ Due to the above you can't just do a `helm upgrade` to release the latest versio
|
|||||||
|
|
||||||
## Steps
|
## Steps
|
||||||
|
|
||||||
1. Upgrade CRDs
|
1. Upgrade CRDs, this isn't optional, the CRDs you are using must be those that correspond with the version of the controller you are installing
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# REMEMBER TO UPDATE THE CHART_VERSION TO RELEVANT CHART VERISON!!!!
|
# REMEMBER TO UPDATE THE CHART_VERSION TO RELEVANT CHART VERISON!!!!
|
||||||
CHART_VERSION=0.14.0
|
CHART_VERSION=0.18.0
|
||||||
|
|
||||||
curl -L https://github.com/actions-runner-controller/actions-runner-controller/releases/download/actions-runner-controller-${CHART_VERSION}/actions-runner-controller-${CHART_VERSION}.tgz | tar zxv --strip 1 actions-runner-controller/crds
|
curl -L https://github.com/actions-runner-controller/actions-runner-controller/releases/download/actions-runner-controller-${CHART_VERSION}/actions-runner-controller-${CHART_VERSION}.tgz | tar zxv --strip 1 actions-runner-controller/crds
|
||||||
|
|
||||||
kubectl apply -f crds/
|
kubectl replace -f crds/
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Upgrade the Helm release
|
2. Upgrade the Helm release
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
# helm repo [command]
|
||||||
|
helm repo update
|
||||||
|
|
||||||
# helm upgrade [RELEASE] [CHART] [flags]
|
# helm upgrade [RELEASE] [CHART] [flags]
|
||||||
helm upgrade actions-runner-controller \
|
helm upgrade actions-runner-controller \
|
||||||
actions-runner-controller/actions-runner-controller \
|
actions-runner-controller/actions-runner-controller \
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ Create the name of the service account to use
|
|||||||
{{- default (include "actions-runner-controller.fullname" .) .Values.authSecret.name -}}
|
{{- default (include "actions-runner-controller.fullname" .) .Values.authSecret.name -}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "actions-runner-controller.githubWebhookServerSecretName" -}}
|
||||||
|
{{- default (include "actions-runner-controller.fullname" .) .Values.githubWebhookServer.secret.name -}}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
{{- define "actions-runner-controller.leaderElectionRoleName" -}}
|
{{- define "actions-runner-controller.leaderElectionRoleName" -}}
|
||||||
{{- include "actions-runner-controller.fullname" . }}-leader-election
|
{{- include "actions-runner-controller.fullname" . }}-leader-election
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
{{- if .Values.certManagerEnabled }}
|
||||||
# The following manifests contain a self-signed issuer CR and a certificate CR.
|
# The following manifests contain a self-signed issuer CR and a certificate CR.
|
||||||
# More document can be found at https://docs.cert-manager.io
|
# More document can be found at https://docs.cert-manager.io
|
||||||
# WARNING: Targets CertManager 0.11 check https://docs.cert-manager.io/en/latest/tasks/upgrading/index.html for breaking changes
|
# WARNING: Targets CertManager 0.11 check https://docs.cert-manager.io/en/latest/tasks/upgrading/index.html for breaking changes
|
||||||
@@ -22,3 +23,4 @@ spec:
|
|||||||
kind: Issuer
|
kind: Issuer
|
||||||
name: {{ include "actions-runner-controller.selfsignedIssuerName" . }}
|
name: {{ include "actions-runner-controller.selfsignedIssuerName" . }}
|
||||||
secretName: {{ include "actions-runner-controller.servingCertName" . }}
|
secretName: {{ include "actions-runner-controller.servingCertName" . }}
|
||||||
|
{{- end }}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ spec:
|
|||||||
metadata:
|
metadata:
|
||||||
{{- with .Values.podAnnotations }}
|
{{- with .Values.podAnnotations }}
|
||||||
annotations:
|
annotations:
|
||||||
|
kubectl.kubernetes.io/default-logs-container: "manager"
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
labels:
|
labels:
|
||||||
@@ -43,9 +44,14 @@ spec:
|
|||||||
{{- if .Values.leaderElectionId }}
|
{{- if .Values.leaderElectionId }}
|
||||||
- "--leader-election-id={{ .Values.leaderElectionId }}"
|
- "--leader-election-id={{ .Values.leaderElectionId }}"
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
- "--port={{ .Values.webhookPort }}"
|
||||||
- "--sync-period={{ .Values.syncPeriod }}"
|
- "--sync-period={{ .Values.syncPeriod }}"
|
||||||
|
- "--default-scale-down-delay={{ .Values.defaultScaleDownDelay }}"
|
||||||
- "--docker-image={{ .Values.image.dindSidecarRepositoryAndTag }}"
|
- "--docker-image={{ .Values.image.dindSidecarRepositoryAndTag }}"
|
||||||
- "--runner-image={{ .Values.image.actionsRunnerRepositoryAndTag }}"
|
- "--runner-image={{ .Values.image.actionsRunnerRepositoryAndTag }}"
|
||||||
|
{{- range .Values.image.actionsRunnerImagePullSecrets }}
|
||||||
|
- "--runner-image-pull-secret={{ . }}"
|
||||||
|
{{- end }}
|
||||||
{{- if .Values.dockerRegistryMirror }}
|
{{- if .Values.dockerRegistryMirror }}
|
||||||
- "--docker-registry-mirror={{ .Values.dockerRegistryMirror }}"
|
- "--docker-registry-mirror={{ .Values.dockerRegistryMirror }}"
|
||||||
{{- end }}
|
{{- end }}
|
||||||
@@ -58,6 +64,9 @@ spec:
|
|||||||
{{- if .Values.logLevel }}
|
{{- if .Values.logLevel }}
|
||||||
- "--log-level={{ .Values.logLevel }}"
|
- "--log-level={{ .Values.logLevel }}"
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- if .Values.runnerGithubURL }}
|
||||||
|
- "--runner-github-url={{ .Values.runnerGithubURL }}"
|
||||||
|
{{- end }}
|
||||||
command:
|
command:
|
||||||
- "/manager"
|
- "/manager"
|
||||||
env:
|
env:
|
||||||
@@ -65,6 +74,15 @@ spec:
|
|||||||
- name: GITHUB_ENTERPRISE_URL
|
- name: GITHUB_ENTERPRISE_URL
|
||||||
value: {{ .Values.githubEnterpriseServerURL }}
|
value: {{ .Values.githubEnterpriseServerURL }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- if .Values.githubURL }}
|
||||||
|
- name: GITHUB_URL
|
||||||
|
value: {{ .Values.githubURL }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.githubUploadURL }}
|
||||||
|
- name: GITHUB_UPLOAD_URL
|
||||||
|
value: {{ .Values.githubUploadURL }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.authSecret.enabled }}
|
||||||
- name: GITHUB_TOKEN
|
- name: GITHUB_TOKEN
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
@@ -84,7 +102,22 @@ spec:
|
|||||||
name: {{ include "actions-runner-controller.secretName" . }}
|
name: {{ include "actions-runner-controller.secretName" . }}
|
||||||
optional: true
|
optional: true
|
||||||
- name: GITHUB_APP_PRIVATE_KEY
|
- name: GITHUB_APP_PRIVATE_KEY
|
||||||
value: /etc/actions-runner-controller/github_app_private_key
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
key: github_app_private_key
|
||||||
|
name: {{ include "actions-runner-controller.secretName" . }}
|
||||||
|
optional: true
|
||||||
|
{{- if .Values.authSecret.github_basicauth_username }}
|
||||||
|
- name: GITHUB_BASICAUTH_USERNAME
|
||||||
|
value: {{ .Values.authSecret.github_basicauth_username }}
|
||||||
|
{{- end }}
|
||||||
|
- name: GITHUB_BASICAUTH_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
key: github_basicauth_password
|
||||||
|
name: {{ include "actions-runner-controller.secretName" . }}
|
||||||
|
optional: true
|
||||||
|
{{- end }}
|
||||||
{{- range $key, $val := .Values.env }}
|
{{- range $key, $val := .Values.env }}
|
||||||
- name: {{ $key }}
|
- name: {{ $key }}
|
||||||
value: {{ $val | quote }}
|
value: {{ $val | quote }}
|
||||||
@@ -93,7 +126,7 @@ spec:
|
|||||||
name: manager
|
name: manager
|
||||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 9443
|
- containerPort: {{ .Values.webhookPort }}
|
||||||
name: webhook-server
|
name: webhook-server
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
{{- if not .Values.metrics.proxy.enabled }}
|
{{- if not .Values.metrics.proxy.enabled }}
|
||||||
@@ -106,14 +139,19 @@ spec:
|
|||||||
securityContext:
|
securityContext:
|
||||||
{{- toYaml .Values.securityContext | nindent 12 }}
|
{{- toYaml .Values.securityContext | nindent 12 }}
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
|
{{- if .Values.authSecret.enabled }}
|
||||||
- mountPath: "/etc/actions-runner-controller"
|
- mountPath: "/etc/actions-runner-controller"
|
||||||
name: secret
|
name: secret
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
{{- end }}
|
||||||
- mountPath: /tmp
|
- mountPath: /tmp
|
||||||
name: tmp
|
name: tmp
|
||||||
- mountPath: /tmp/k8s-webhook-server/serving-certs
|
- mountPath: /tmp/k8s-webhook-server/serving-certs
|
||||||
name: cert
|
name: cert
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
{{- if .Values.additionalVolumeMounts }}
|
||||||
|
{{- toYaml .Values.additionalVolumeMounts | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
{{- if .Values.metrics.proxy.enabled }}
|
{{- if .Values.metrics.proxy.enabled }}
|
||||||
- args:
|
- args:
|
||||||
- "--secure-listen-address=0.0.0.0:{{ .Values.metrics.port }}"
|
- "--secure-listen-address=0.0.0.0:{{ .Values.metrics.port }}"
|
||||||
@@ -133,15 +171,20 @@ spec:
|
|||||||
{{- end }}
|
{{- end }}
|
||||||
terminationGracePeriodSeconds: 10
|
terminationGracePeriodSeconds: 10
|
||||||
volumes:
|
volumes:
|
||||||
|
{{- if .Values.authSecret.enabled }}
|
||||||
- name: secret
|
- name: secret
|
||||||
secret:
|
secret:
|
||||||
secretName: {{ include "actions-runner-controller.secretName" . }}
|
secretName: {{ include "actions-runner-controller.secretName" . }}
|
||||||
|
{{- end }}
|
||||||
- name: cert
|
- name: cert
|
||||||
secret:
|
secret:
|
||||||
defaultMode: 420
|
defaultMode: 420
|
||||||
secretName: {{ include "actions-runner-controller.servingCertName" . }}
|
secretName: {{ include "actions-runner-controller.servingCertName" . }}
|
||||||
- name: tmp
|
- name: tmp
|
||||||
emptyDir: {}
|
emptyDir: {}
|
||||||
|
{{- if .Values.additionalVolumes }}
|
||||||
|
{{- toYaml .Values.additionalVolumes | nindent 6}}
|
||||||
|
{{- end }}
|
||||||
{{- with .Values.nodeSelector }}
|
{{- with .Values.nodeSelector }}
|
||||||
nodeSelector:
|
nodeSelector:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
@@ -158,3 +201,6 @@ spec:
|
|||||||
topologySpreadConstraints:
|
topologySpreadConstraints:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- if .Values.hostNetwork }}
|
||||||
|
hostNetwork: {{ .Values.hostNetwork }}
|
||||||
|
{{- end }}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ spec:
|
|||||||
metadata:
|
metadata:
|
||||||
{{- with .Values.githubWebhookServer.podAnnotations }}
|
{{- with .Values.githubWebhookServer.podAnnotations }}
|
||||||
annotations:
|
annotations:
|
||||||
|
kubectl.kubernetes.io/default-logs-container: "github-webhook-server"
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
labels:
|
labels:
|
||||||
@@ -45,6 +46,9 @@ spec:
|
|||||||
{{- if .Values.scope.singleNamespace }}
|
{{- if .Values.scope.singleNamespace }}
|
||||||
- "--watch-namespace={{ default .Release.Namespace .Values.scope.watchNamespace }}"
|
- "--watch-namespace={{ default .Release.Namespace .Values.scope.watchNamespace }}"
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- if .Values.runnerGithubURL }}
|
||||||
|
- "--runner-github-url={{ .Values.runnerGithubURL }}"
|
||||||
|
{{- end }}
|
||||||
command:
|
command:
|
||||||
- "/github-webhook-server"
|
- "/github-webhook-server"
|
||||||
env:
|
env:
|
||||||
@@ -54,6 +58,54 @@ spec:
|
|||||||
key: github_webhook_secret_token
|
key: github_webhook_secret_token
|
||||||
name: {{ include "actions-runner-controller-github-webhook-server.secretName" . }}
|
name: {{ include "actions-runner-controller-github-webhook-server.secretName" . }}
|
||||||
optional: true
|
optional: true
|
||||||
|
{{- if .Values.githubEnterpriseServerURL }}
|
||||||
|
- name: GITHUB_ENTERPRISE_URL
|
||||||
|
value: {{ .Values.githubEnterpriseServerURL }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.githubURL }}
|
||||||
|
- name: GITHUB_URL
|
||||||
|
value: {{ .Values.githubURL }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.githubUploadURL }}
|
||||||
|
- name: GITHUB_UPLOAD_URL
|
||||||
|
value: {{ .Values.githubUploadURL }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if and .Values.githubWebhookServer.useRunnerGroupsVisibility .Values.githubWebhookServer.secret.enabled }}
|
||||||
|
- name: GITHUB_TOKEN
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
key: github_token
|
||||||
|
name: {{ include "actions-runner-controller.githubWebhookServerSecretName" . }}
|
||||||
|
optional: true
|
||||||
|
- name: GITHUB_APP_ID
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
key: github_app_id
|
||||||
|
name: {{ include "actions-runner-controller.githubWebhookServerSecretName" . }}
|
||||||
|
optional: true
|
||||||
|
- name: GITHUB_APP_INSTALLATION_ID
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
key: github_app_installation_id
|
||||||
|
name: {{ include "actions-runner-controller.githubWebhookServerSecretName" . }}
|
||||||
|
optional: true
|
||||||
|
- name: GITHUB_APP_PRIVATE_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
key: github_app_private_key
|
||||||
|
name: {{ include "actions-runner-controller.githubWebhookServerSecretName" . }}
|
||||||
|
optional: true
|
||||||
|
{{- if .Values.authSecret.github_basicauth_username }}
|
||||||
|
- name: GITHUB_BASICAUTH_USERNAME
|
||||||
|
value: {{ .Values.authSecret.github_basicauth_username }}
|
||||||
|
{{- end }}
|
||||||
|
- name: GITHUB_BASICAUTH_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
key: github_basicauth_password
|
||||||
|
name: {{ include "actions-runner-controller.secretName" . }}
|
||||||
|
optional: true
|
||||||
|
{{- end }}
|
||||||
{{- range $key, $val := .Values.githubWebhookServer.env }}
|
{{- range $key, $val := .Values.githubWebhookServer.env }}
|
||||||
- name: {{ $key }}
|
- name: {{ $key }}
|
||||||
value: {{ $val | quote }}
|
value: {{ $val | quote }}
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
{{- if .Values.githubWebhookServer.ingress.enabled -}}
|
{{- if .Values.githubWebhookServer.ingress.enabled -}}
|
||||||
{{- $fullName := include "actions-runner-controller-github-webhook-server.fullname" . -}}
|
{{- $fullName := include "actions-runner-controller-github-webhook-server.fullname" . -}}
|
||||||
{{- $svcPort := (index .Values.githubWebhookServer.service.ports 0).port -}}
|
{{- $svcPort := (index .Values.githubWebhookServer.service.ports 0).port -}}
|
||||||
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
|
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
{{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }}
|
||||||
apiVersion: networking.k8s.io/v1beta1
|
apiVersion: networking.k8s.io/v1beta1
|
||||||
{{- else -}}
|
{{- else if .Capabilities.APIVersions.Has "extensions/v1beta1" }}
|
||||||
apiVersion: extensions/v1beta1
|
apiVersion: extensions/v1beta1
|
||||||
{{- end }}
|
{{- end }}
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ $fullName }}
|
name: {{ $fullName }}
|
||||||
|
namespace: {{ .Release.Namespace }}
|
||||||
labels:
|
labels:
|
||||||
{{- include "actions-runner-controller.labels" . | nindent 4 }}
|
{{- include "actions-runner-controller.labels" . | nindent 4 }}
|
||||||
{{- with .Values.githubWebhookServer.ingress.annotations }}
|
{{- with .Values.githubWebhookServer.ingress.annotations }}
|
||||||
@@ -26,16 +29,32 @@ spec:
|
|||||||
secretName: {{ .secretName }}
|
secretName: {{ .secretName }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with .Values.githubWebhookServer.ingress.ingressClassName }}
|
||||||
|
ingressClassName: {{ . }}
|
||||||
|
{{- end }}
|
||||||
rules:
|
rules:
|
||||||
{{- range .Values.githubWebhookServer.ingress.hosts }}
|
{{- range .Values.githubWebhookServer.ingress.hosts }}
|
||||||
- host: {{ .host | quote }}
|
- host: {{ .host | quote }}
|
||||||
http:
|
http:
|
||||||
paths:
|
paths:
|
||||||
|
{{- if .extraPaths }}
|
||||||
|
{{- toYaml .extraPaths | nindent 10 }}
|
||||||
|
{{- end }}
|
||||||
{{- range .paths }}
|
{{- range .paths }}
|
||||||
- path: {{ .path }}
|
- path: {{ .path }}
|
||||||
|
{{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
|
||||||
|
pathType: {{ .pathType }}
|
||||||
|
{{- end }}
|
||||||
backend:
|
backend:
|
||||||
|
{{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
|
||||||
|
service:
|
||||||
|
name: {{ $fullName }}
|
||||||
|
port:
|
||||||
|
number: {{ $svcPort }}
|
||||||
|
{{- else }}
|
||||||
serviceName: {{ $fullName }}
|
serviceName: {{ $fullName }}
|
||||||
servicePort: {{ $svcPort }}
|
servicePort: {{ $svcPort }}
|
||||||
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|||||||
@@ -195,6 +195,28 @@ rules:
|
|||||||
verbs:
|
verbs:
|
||||||
- create
|
- create
|
||||||
- patch
|
- patch
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- persistentvolumeclaims
|
||||||
|
verbs:
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- persistentvolumes
|
||||||
|
verbs:
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- coordination.k8s.io
|
- coordination.k8s.io
|
||||||
resources:
|
resources:
|
||||||
|
|||||||
@@ -26,4 +26,7 @@ data:
|
|||||||
{{- if .Values.authSecret.github_token }}
|
{{- if .Values.authSecret.github_token }}
|
||||||
github_token: {{ .Values.authSecret.github_token | toString | b64enc }}
|
github_token: {{ .Values.authSecret.github_token | toString | b64enc }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- if .Values.authSecret.github_basicauth_password }}
|
||||||
|
github_basicauth_password: {{ .Values.authSecret.github_basicauth_password | toString | b64enc }}
|
||||||
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|||||||
@@ -5,12 +5,22 @@ kind: MutatingWebhookConfiguration
|
|||||||
metadata:
|
metadata:
|
||||||
creationTimestamp: null
|
creationTimestamp: null
|
||||||
name: {{ include "actions-runner-controller.fullname" . }}-mutating-webhook-configuration
|
name: {{ include "actions-runner-controller.fullname" . }}-mutating-webhook-configuration
|
||||||
|
{{- if .Values.certManagerEnabled }}
|
||||||
annotations:
|
annotations:
|
||||||
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "actions-runner-controller.servingCertName" . }}
|
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "actions-runner-controller.servingCertName" . }}
|
||||||
|
{{- end }}
|
||||||
webhooks:
|
webhooks:
|
||||||
- admissionReviewVersions:
|
- admissionReviewVersions:
|
||||||
- v1beta1
|
- v1beta1
|
||||||
|
{{- if .Values.scope.singleNamespace }}
|
||||||
|
namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
name: {{ default .Release.Namespace .Values.scope.watchNamespace }}
|
||||||
|
{{- end }}
|
||||||
clientConfig:
|
clientConfig:
|
||||||
|
{{- if .Values.admissionWebHooks.caBundle }}
|
||||||
|
caBundle: {{ quote .Values.admissionWebHooks.caBundle }}
|
||||||
|
{{- end }}
|
||||||
service:
|
service:
|
||||||
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
||||||
namespace: {{ .Release.Namespace }}
|
namespace: {{ .Release.Namespace }}
|
||||||
@@ -30,7 +40,15 @@ webhooks:
|
|||||||
sideEffects: None
|
sideEffects: None
|
||||||
- admissionReviewVersions:
|
- admissionReviewVersions:
|
||||||
- v1beta1
|
- v1beta1
|
||||||
|
{{- if .Values.scope.singleNamespace }}
|
||||||
|
namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
name: {{ default .Release.Namespace .Values.scope.watchNamespace }}
|
||||||
|
{{- end }}
|
||||||
clientConfig:
|
clientConfig:
|
||||||
|
{{- if .Values.admissionWebHooks.caBundle }}
|
||||||
|
caBundle: {{ .Values.admissionWebHooks.caBundle }}
|
||||||
|
{{- end }}
|
||||||
service:
|
service:
|
||||||
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
||||||
namespace: {{ .Release.Namespace }}
|
namespace: {{ .Release.Namespace }}
|
||||||
@@ -50,7 +68,15 @@ webhooks:
|
|||||||
sideEffects: None
|
sideEffects: None
|
||||||
- admissionReviewVersions:
|
- admissionReviewVersions:
|
||||||
- v1beta1
|
- v1beta1
|
||||||
|
{{- if .Values.scope.singleNamespace }}
|
||||||
|
namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
name: {{ default .Release.Namespace .Values.scope.watchNamespace }}
|
||||||
|
{{- end }}
|
||||||
clientConfig:
|
clientConfig:
|
||||||
|
{{- if .Values.admissionWebHooks.caBundle }}
|
||||||
|
caBundle: {{ .Values.admissionWebHooks.caBundle }}
|
||||||
|
{{- end }}
|
||||||
service:
|
service:
|
||||||
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
||||||
namespace: {{ .Release.Namespace }}
|
namespace: {{ .Release.Namespace }}
|
||||||
@@ -70,7 +96,15 @@ webhooks:
|
|||||||
sideEffects: None
|
sideEffects: None
|
||||||
- admissionReviewVersions:
|
- admissionReviewVersions:
|
||||||
- v1beta1
|
- v1beta1
|
||||||
|
{{- if .Values.scope.singleNamespace }}
|
||||||
|
namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
name: {{ default .Release.Namespace .Values.scope.watchNamespace }}
|
||||||
|
{{- end }}
|
||||||
clientConfig:
|
clientConfig:
|
||||||
|
{{- if .Values.admissionWebHooks.caBundle }}
|
||||||
|
caBundle: {{ .Values.admissionWebHooks.caBundle }}
|
||||||
|
{{- end }}
|
||||||
service:
|
service:
|
||||||
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
||||||
namespace: {{ .Release.Namespace }}
|
namespace: {{ .Release.Namespace }}
|
||||||
@@ -96,12 +130,22 @@ kind: ValidatingWebhookConfiguration
|
|||||||
metadata:
|
metadata:
|
||||||
creationTimestamp: null
|
creationTimestamp: null
|
||||||
name: {{ include "actions-runner-controller.fullname" . }}-validating-webhook-configuration
|
name: {{ include "actions-runner-controller.fullname" . }}-validating-webhook-configuration
|
||||||
|
{{- if .Values.certManagerEnabled }}
|
||||||
annotations:
|
annotations:
|
||||||
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "actions-runner-controller.servingCertName" . }}
|
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "actions-runner-controller.servingCertName" . }}
|
||||||
|
{{- end }}
|
||||||
webhooks:
|
webhooks:
|
||||||
- admissionReviewVersions:
|
- admissionReviewVersions:
|
||||||
- v1beta1
|
- v1beta1
|
||||||
|
{{- if .Values.scope.singleNamespace }}
|
||||||
|
namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
name: {{ default .Release.Namespace .Values.scope.watchNamespace }}
|
||||||
|
{{- end }}
|
||||||
clientConfig:
|
clientConfig:
|
||||||
|
{{- if .Values.admissionWebHooks.caBundle }}
|
||||||
|
caBundle: {{ .Values.admissionWebHooks.caBundle }}
|
||||||
|
{{- end }}
|
||||||
service:
|
service:
|
||||||
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
||||||
namespace: {{ .Release.Namespace }}
|
namespace: {{ .Release.Namespace }}
|
||||||
@@ -121,7 +165,15 @@ webhooks:
|
|||||||
sideEffects: None
|
sideEffects: None
|
||||||
- admissionReviewVersions:
|
- admissionReviewVersions:
|
||||||
- v1beta1
|
- v1beta1
|
||||||
|
{{- if .Values.scope.singleNamespace }}
|
||||||
|
namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
name: {{ default .Release.Namespace .Values.scope.watchNamespace }}
|
||||||
|
{{- end }}
|
||||||
clientConfig:
|
clientConfig:
|
||||||
|
{{- if .Values.admissionWebHooks.caBundle }}
|
||||||
|
caBundle: {{ .Values.admissionWebHooks.caBundle }}
|
||||||
|
{{- end }}
|
||||||
service:
|
service:
|
||||||
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
||||||
namespace: {{ .Release.Namespace }}
|
namespace: {{ .Release.Namespace }}
|
||||||
@@ -141,7 +193,15 @@ webhooks:
|
|||||||
sideEffects: None
|
sideEffects: None
|
||||||
- admissionReviewVersions:
|
- admissionReviewVersions:
|
||||||
- v1beta1
|
- v1beta1
|
||||||
|
{{- if .Values.scope.singleNamespace }}
|
||||||
|
namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
name: {{ default .Release.Namespace .Values.scope.watchNamespace }}
|
||||||
|
{{- end }}
|
||||||
clientConfig:
|
clientConfig:
|
||||||
|
{{- if .Values.admissionWebHooks.caBundle }}
|
||||||
|
caBundle: {{ .Values.admissionWebHooks.caBundle }}
|
||||||
|
{{- end }}
|
||||||
service:
|
service:
|
||||||
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
name: {{ include "actions-runner-controller.webhookServiceName" . }}
|
||||||
namespace: {{ .Release.Namespace }}
|
namespace: {{ .Release.Namespace }}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ spec:
|
|||||||
type: {{ .Values.service.type }}
|
type: {{ .Values.service.type }}
|
||||||
ports:
|
ports:
|
||||||
- port: 443
|
- port: 443
|
||||||
targetPort: 9443
|
targetPort: {{ .Values.webhookPort }}
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
name: https
|
name: https
|
||||||
selector:
|
selector:
|
||||||
|
|||||||
@@ -6,13 +6,16 @@ labels: {}
|
|||||||
|
|
||||||
replicaCount: 1
|
replicaCount: 1
|
||||||
|
|
||||||
syncPeriod: 10m
|
webhookPort: 9443
|
||||||
|
syncPeriod: 1m
|
||||||
|
defaultScaleDownDelay: 10m
|
||||||
|
|
||||||
enableLeaderElection: true
|
enableLeaderElection: true
|
||||||
# Specifies the controller id for leader election.
|
# Specifies the controller id for leader election.
|
||||||
# Must be unique if more than one controller installed onto the same namespace.
|
# Must be unique if more than one controller installed onto the same namespace.
|
||||||
#leaderElectionId: "actions-runner-controller"
|
#leaderElectionId: "actions-runner-controller"
|
||||||
|
|
||||||
|
# DEPRECATED: This has been removed as unnecessary in #1192
|
||||||
# The controller tries its best not to repeat the duplicate GitHub API call
|
# The controller tries its best not to repeat the duplicate GitHub API call
|
||||||
# within this duration.
|
# within this duration.
|
||||||
# Defaults to syncPeriod - 10s.
|
# Defaults to syncPeriod - 10s.
|
||||||
@@ -21,9 +24,21 @@ enableLeaderElection: true
|
|||||||
# The URL of your GitHub Enterprise server, if you're using one.
|
# The URL of your GitHub Enterprise server, if you're using one.
|
||||||
#githubEnterpriseServerURL: https://github.example.com
|
#githubEnterpriseServerURL: https://github.example.com
|
||||||
|
|
||||||
|
# Override GitHub URLs in case of using proxy APIs
|
||||||
|
#githubURL: ""
|
||||||
|
#githubUploadURL: ""
|
||||||
|
#runnerGithubURL: ""
|
||||||
|
|
||||||
# Only 1 authentication method can be deployed at a time
|
# Only 1 authentication method can be deployed at a time
|
||||||
# Uncomment the configuration you are applying and fill in the details
|
# Uncomment the configuration you are applying and fill in the details
|
||||||
|
#
|
||||||
|
# If authSecret.enabled=true these values are inherited to actions-runner-controller's controller-manager container's env.
|
||||||
|
#
|
||||||
|
# Do set authSecret.enabled=false and set env if you want full control over
|
||||||
|
# the GitHub authn related envvars of the container.
|
||||||
|
# See https://github.com/actions-runner-controller/actions-runner-controller/pull/937 for more details.
|
||||||
authSecret:
|
authSecret:
|
||||||
|
enabled: true
|
||||||
create: false
|
create: false
|
||||||
name: "controller-manager"
|
name: "controller-manager"
|
||||||
annotations: {}
|
annotations: {}
|
||||||
@@ -34,6 +49,9 @@ authSecret:
|
|||||||
#github_app_private_key: |
|
#github_app_private_key: |
|
||||||
### GitHub PAT Configuration
|
### GitHub PAT Configuration
|
||||||
#github_token: ""
|
#github_token: ""
|
||||||
|
### Basic auth for github API proxy
|
||||||
|
#github_basicauth_username: ""
|
||||||
|
#github_basicauth_password: ""
|
||||||
|
|
||||||
dockerRegistryMirror: ""
|
dockerRegistryMirror: ""
|
||||||
image:
|
image:
|
||||||
@@ -41,6 +59,9 @@ image:
|
|||||||
actionsRunnerRepositoryAndTag: "summerwind/actions-runner:latest"
|
actionsRunnerRepositoryAndTag: "summerwind/actions-runner:latest"
|
||||||
dindSidecarRepositoryAndTag: "docker:dind"
|
dindSidecarRepositoryAndTag: "docker:dind"
|
||||||
pullPolicy: IfNotPresent
|
pullPolicy: IfNotPresent
|
||||||
|
# The default image-pull secrets name for self-hosted runner container.
|
||||||
|
# It's added to spec.ImagePullSecrets of self-hosted runner pods.
|
||||||
|
actionsRunnerImagePullSecrets: []
|
||||||
|
|
||||||
imagePullSecrets: []
|
imagePullSecrets: []
|
||||||
nameOverride: ""
|
nameOverride: ""
|
||||||
@@ -88,7 +109,7 @@ metrics:
|
|||||||
enabled: true
|
enabled: true
|
||||||
image:
|
image:
|
||||||
repository: quay.io/brancz/kube-rbac-proxy
|
repository: quay.io/brancz/kube-rbac-proxy
|
||||||
tag: v0.10.0
|
tag: v0.12.0
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
{}
|
{}
|
||||||
@@ -126,6 +147,14 @@ env:
|
|||||||
# https_proxy: "proxy.com:8080"
|
# https_proxy: "proxy.com:8080"
|
||||||
# no_proxy: ""
|
# no_proxy: ""
|
||||||
|
|
||||||
|
## specify additional volumes to mount in the manager container, this can be used
|
||||||
|
## to specify additional storage of material or to inject files from ConfigMaps
|
||||||
|
## into the running container
|
||||||
|
additionalVolumes: []
|
||||||
|
|
||||||
|
## specify where the additional volumes are mounted in the manager container
|
||||||
|
additionalVolumeMounts: []
|
||||||
|
|
||||||
scope:
|
scope:
|
||||||
# If true, the controller will only watch custom resources in a single namespace
|
# If true, the controller will only watch custom resources in a single namespace
|
||||||
singleNamespace: false
|
singleNamespace: false
|
||||||
@@ -133,11 +162,23 @@ scope:
|
|||||||
# The default value is "", which means the namespace of the controller
|
# The default value is "", which means the namespace of the controller
|
||||||
watchNamespace: ""
|
watchNamespace: ""
|
||||||
|
|
||||||
|
certManagerEnabled: true
|
||||||
|
|
||||||
|
admissionWebHooks:
|
||||||
|
{}
|
||||||
|
#caBundle: "Ci0tLS0tQk...<base64-encoded PEM bundle containing the CA that signed the webhook's serving certificate>...tLS0K"
|
||||||
|
|
||||||
|
# There may be alternatives to setting `hostNetwork: true`, see
|
||||||
|
# https://github.com/actions-runner-controller/actions-runner-controller/issues/1005#issuecomment-993097155
|
||||||
|
#hostNetwork: true
|
||||||
|
|
||||||
githubWebhookServer:
|
githubWebhookServer:
|
||||||
enabled: false
|
enabled: false
|
||||||
replicaCount: 1
|
replicaCount: 1
|
||||||
syncPeriod: 10m
|
syncPeriod: 10m
|
||||||
|
useRunnerGroupsVisibility: false
|
||||||
secret:
|
secret:
|
||||||
|
enabled: false
|
||||||
create: false
|
create: false
|
||||||
name: "github-webhook-server"
|
name: "github-webhook-server"
|
||||||
### GitHub Webhook Configuration
|
### GitHub Webhook Configuration
|
||||||
@@ -174,13 +215,29 @@ githubWebhookServer:
|
|||||||
#nodePort: someFixedPortForUseWithTerraformCdkCfnEtc
|
#nodePort: someFixedPortForUseWithTerraformCdkCfnEtc
|
||||||
ingress:
|
ingress:
|
||||||
enabled: false
|
enabled: false
|
||||||
annotations:
|
ingressClassName: ""
|
||||||
{}
|
annotations: {}
|
||||||
# kubernetes.io/ingress.class: nginx
|
# kubernetes.io/ingress.class: nginx
|
||||||
# kubernetes.io/tls-acme: "true"
|
# kubernetes.io/tls-acme: "true"
|
||||||
hosts:
|
hosts:
|
||||||
- host: chart-example.local
|
- host: chart-example.local
|
||||||
paths: []
|
paths: []
|
||||||
|
# - path: /*
|
||||||
|
# pathType: ImplementationSpecific
|
||||||
|
# Extra paths that are not automatically connected to the server. This is useful when working with annotation based services.
|
||||||
|
extraPaths: []
|
||||||
|
# - path: /*
|
||||||
|
# backend:
|
||||||
|
# serviceName: ssl-redirect
|
||||||
|
# servicePort: use-annotation
|
||||||
|
## for Kubernetes >=1.19 (when "networking.k8s.io/v1" is used)
|
||||||
|
# - path: /*
|
||||||
|
# pathType: Prefix
|
||||||
|
# backend:
|
||||||
|
# service:
|
||||||
|
# name: ssl-redirect
|
||||||
|
# port:
|
||||||
|
# name: use-annotation
|
||||||
tls: []
|
tls: []
|
||||||
# - secretName: chart-example-tls
|
# - secretName: chart-example-tls
|
||||||
# hosts:
|
# hosts:
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -27,14 +28,15 @@ import (
|
|||||||
|
|
||||||
actionsv1alpha1 "github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
actionsv1alpha1 "github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/controllers"
|
"github.com/actions-runner-controller/actions-runner-controller/controllers"
|
||||||
zaplib "go.uber.org/zap"
|
"github.com/actions-runner-controller/actions-runner-controller/github"
|
||||||
|
"github.com/actions-runner-controller/actions-runner-controller/logging"
|
||||||
|
"github.com/kelseyhightower/envconfig"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||||
_ "k8s.io/client-go/plugin/pkg/client/auth/exec"
|
_ "k8s.io/client-go/plugin/pkg/client/auth/exec"
|
||||||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
||||||
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
|
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
|
||||||
// +kubebuilder:scaffold:imports
|
// +kubebuilder:scaffold:imports
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -44,10 +46,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
logLevelDebug = "debug"
|
webhookSecretTokenEnvName = "GITHUB_WEBHOOK_SECRET_TOKEN"
|
||||||
logLevelInfo = "info"
|
|
||||||
logLevelWarn = "warn"
|
|
||||||
logLevelError = "error"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -65,16 +64,26 @@ func main() {
|
|||||||
metricsAddr string
|
metricsAddr string
|
||||||
|
|
||||||
// The secret token of the GitHub Webhook. See https://docs.github.com/en/developers/webhooks-and-events/securing-your-webhooks
|
// The secret token of the GitHub Webhook. See https://docs.github.com/en/developers/webhooks-and-events/securing-your-webhooks
|
||||||
webhookSecretToken string
|
webhookSecretToken string
|
||||||
|
webhookSecretTokenEnv string
|
||||||
|
|
||||||
watchNamespace string
|
watchNamespace string
|
||||||
|
|
||||||
enableLeaderElection bool
|
enableLeaderElection bool
|
||||||
syncPeriod time.Duration
|
syncPeriod time.Duration
|
||||||
logLevel string
|
logLevel string
|
||||||
|
|
||||||
|
ghClient *github.Client
|
||||||
)
|
)
|
||||||
|
|
||||||
webhookSecretToken = os.Getenv("GITHUB_WEBHOOK_SECRET_TOKEN")
|
var c github.Config
|
||||||
|
err = envconfig.Process("github", &c)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: processing environment variables: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
webhookSecretTokenEnv = os.Getenv(webhookSecretTokenEnvName)
|
||||||
|
|
||||||
flag.StringVar(&webhookAddr, "webhook-addr", ":8000", "The address the metric endpoint binds to.")
|
flag.StringVar(&webhookAddr, "webhook-addr", ":8000", "The address the metric endpoint binds to.")
|
||||||
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
|
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
|
||||||
@@ -82,11 +91,27 @@ func main() {
|
|||||||
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
|
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
|
||||||
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
|
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
|
||||||
flag.DurationVar(&syncPeriod, "sync-period", 10*time.Minute, "Determines the minimum frequency at which K8s resources managed by this controller are reconciled. When you use autoscaling, set to a lower value like 10 minute, because this corresponds to the minimum time to react on demand change")
|
flag.DurationVar(&syncPeriod, "sync-period", 10*time.Minute, "Determines the minimum frequency at which K8s resources managed by this controller are reconciled. When you use autoscaling, set to a lower value like 10 minute, because this corresponds to the minimum time to react on demand change")
|
||||||
flag.StringVar(&logLevel, "log-level", logLevelDebug, `The verbosity of the logging. Valid values are "debug", "info", "warn", "error". Defaults to "debug".`)
|
flag.StringVar(&logLevel, "log-level", logging.LogLevelDebug, `The verbosity of the logging. Valid values are "debug", "info", "warn", "error". Defaults to "debug".`)
|
||||||
|
flag.StringVar(&webhookSecretToken, "github-webhook-secret-token", "", "The personal access token of GitHub.")
|
||||||
|
flag.StringVar(&c.Token, "github-token", c.Token, "The personal access token of GitHub.")
|
||||||
|
flag.Int64Var(&c.AppID, "github-app-id", c.AppID, "The application ID of GitHub App.")
|
||||||
|
flag.Int64Var(&c.AppInstallationID, "github-app-installation-id", c.AppInstallationID, "The installation ID of GitHub App.")
|
||||||
|
flag.StringVar(&c.AppPrivateKey, "github-app-private-key", c.AppPrivateKey, "The path of a private key file to authenticate as a GitHub App")
|
||||||
|
flag.StringVar(&c.URL, "github-url", c.URL, "GitHub URL to be used for GitHub API calls")
|
||||||
|
flag.StringVar(&c.UploadURL, "github-upload-url", c.UploadURL, "GitHub Upload URL to be used for GitHub API calls")
|
||||||
|
flag.StringVar(&c.BasicauthUsername, "github-basicauth-username", c.BasicauthUsername, "Username for GitHub basic auth to use instead of PAT or GitHub APP in case it's running behind a proxy API")
|
||||||
|
flag.StringVar(&c.BasicauthPassword, "github-basicauth-password", c.BasicauthPassword, "Password for GitHub basic auth to use instead of PAT or GitHub APP in case it's running behind a proxy API")
|
||||||
|
flag.StringVar(&c.RunnerGitHubURL, "runner-github-url", c.RunnerGitHubURL, "GitHub URL to be used by runners during registration")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if webhookSecretToken == "" && webhookSecretTokenEnv != "" {
|
||||||
|
setupLog.Info(fmt.Sprintf("Using the value from %s for -github-webhook-secret-token", webhookSecretTokenEnvName))
|
||||||
|
webhookSecretToken = webhookSecretTokenEnv
|
||||||
|
}
|
||||||
|
|
||||||
if webhookSecretToken == "" {
|
if webhookSecretToken == "" {
|
||||||
setupLog.Info("-webhook-secret-token is missing or empty. Create one following https://docs.github.com/en/developers/webhooks-and-events/securing-your-webhooks")
|
setupLog.Info(fmt.Sprintf("-github-webhook-secret-token and %s are missing or empty. Create one following https://docs.github.com/en/developers/webhooks-and-events/securing-your-webhooks and specify it via the flag or the envvar", webhookSecretTokenEnvName))
|
||||||
}
|
}
|
||||||
|
|
||||||
if watchNamespace == "" {
|
if watchNamespace == "" {
|
||||||
@@ -95,24 +120,28 @@ func main() {
|
|||||||
setupLog.Info("-watch-namespace is %q. Only HorizontalRunnerAutoscalers in %q are watched, cached, and considered as scale targets.")
|
setupLog.Info("-watch-namespace is %q. Only HorizontalRunnerAutoscalers in %q are watched, cached, and considered as scale targets.")
|
||||||
}
|
}
|
||||||
|
|
||||||
logger := zap.New(func(o *zap.Options) {
|
logger := logging.NewLogger(logLevel)
|
||||||
switch logLevel {
|
|
||||||
case logLevelDebug:
|
|
||||||
o.Development = true
|
|
||||||
case logLevelInfo:
|
|
||||||
lvl := zaplib.NewAtomicLevelAt(zaplib.InfoLevel)
|
|
||||||
o.Level = &lvl
|
|
||||||
case logLevelWarn:
|
|
||||||
lvl := zaplib.NewAtomicLevelAt(zaplib.WarnLevel)
|
|
||||||
o.Level = &lvl
|
|
||||||
case logLevelError:
|
|
||||||
lvl := zaplib.NewAtomicLevelAt(zaplib.ErrorLevel)
|
|
||||||
o.Level = &lvl
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
ctrl.SetLogger(logger)
|
ctrl.SetLogger(logger)
|
||||||
|
|
||||||
|
// In order to support runner groups with custom visibility (selected repositories), we need to perform some GitHub API calls.
|
||||||
|
// Let the user define if they want to opt-in supporting this option by providing the proper GitHub authentication parameters
|
||||||
|
// Without an opt-in, runner groups with custom visibility won't be supported to save API calls
|
||||||
|
// That is, all runner groups managed by ARC are assumed to be visible to any repositories,
|
||||||
|
// which is wrong when you have one or more non-default runner groups in your organization or enterprise.
|
||||||
|
if len(c.Token) > 0 || (c.AppID > 0 && c.AppInstallationID > 0 && c.AppPrivateKey != "") || (len(c.BasicauthUsername) > 0 && len(c.BasicauthPassword) > 0) {
|
||||||
|
c.Log = &logger
|
||||||
|
|
||||||
|
ghClient, err = c.NewClient()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "Error: Client creation failed.", err)
|
||||||
|
setupLog.Error(err, "unable to create controller", "controller", "Runner")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setupLog.Info("GitHub client is not initialized. Runner groups with custom visibility are not supported. If needed, please provide GitHub authentication. This will incur in extra GitHub API calls")
|
||||||
|
}
|
||||||
|
|
||||||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
|
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
SyncPeriod: &syncPeriod,
|
SyncPeriod: &syncPeriod,
|
||||||
@@ -127,16 +156,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hraGitHubWebhook := &controllers.HorizontalRunnerAutoscalerGitHubWebhook{
|
hraGitHubWebhook := &controllers.HorizontalRunnerAutoscalerGitHubWebhook{
|
||||||
|
Name: "webhookbasedautoscaler",
|
||||||
Client: mgr.GetClient(),
|
Client: mgr.GetClient(),
|
||||||
Log: ctrl.Log.WithName("controllers").WithName("Runner"),
|
Log: ctrl.Log.WithName("controllers").WithName("webhookbasedautoscaler"),
|
||||||
Recorder: nil,
|
Recorder: nil,
|
||||||
Scheme: mgr.GetScheme(),
|
Scheme: mgr.GetScheme(),
|
||||||
SecretKeyBytes: []byte(webhookSecretToken),
|
SecretKeyBytes: []byte(webhookSecretToken),
|
||||||
Namespace: watchNamespace,
|
Namespace: watchNamespace,
|
||||||
|
GitHubClient: ghClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = hraGitHubWebhook.SetupWithManager(mgr); err != nil {
|
if err = hraGitHubWebhook.SetupWithManager(mgr); err != nil {
|
||||||
setupLog.Error(err, "unable to create controller", "controller", "Runner")
|
setupLog.Error(err, "unable to create controller", "controller", "webhookbasedautoscaler")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
|
|||||||
kind: CustomResourceDefinition
|
kind: CustomResourceDefinition
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
controller-gen.kubebuilder.io/version: v0.6.0
|
controller-gen.kubebuilder.io/version: v0.7.0
|
||||||
creationTimestamp: null
|
creationTimestamp: null
|
||||||
name: horizontalrunnerautoscalers.actions.summerwind.dev
|
name: horizontalrunnerautoscalers.actions.summerwind.dev
|
||||||
spec:
|
spec:
|
||||||
@@ -49,6 +49,9 @@ spec:
|
|||||||
items:
|
items:
|
||||||
description: CapacityReservation specifies the number of replicas temporarily added to the scale target until ExpirationTime.
|
description: CapacityReservation specifies the number of replicas temporarily added to the scale target until ExpirationTime.
|
||||||
properties:
|
properties:
|
||||||
|
effectiveTime:
|
||||||
|
format: date-time
|
||||||
|
type: string
|
||||||
expirationTime:
|
expirationTime:
|
||||||
format: date-time
|
format: date-time
|
||||||
type: string
|
type: string
|
||||||
@@ -138,6 +141,7 @@ spec:
|
|||||||
status:
|
status:
|
||||||
type: string
|
type: string
|
||||||
types:
|
types:
|
||||||
|
description: 'One of: created, rerequested, or completed'
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
type: array
|
type: array
|
||||||
@@ -157,6 +161,9 @@ spec:
|
|||||||
push:
|
push:
|
||||||
description: PushSpec is the condition for triggering scale-up on push event Also see https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push
|
description: PushSpec is the condition for triggering scale-up on push event Also see https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push
|
||||||
type: object
|
type: object
|
||||||
|
workflowJob:
|
||||||
|
description: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_job
|
||||||
|
type: object
|
||||||
type: object
|
type: object
|
||||||
type: object
|
type: object
|
||||||
type: array
|
type: array
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -8,6 +8,7 @@ spec:
|
|||||||
conversion:
|
conversion:
|
||||||
strategy: Webhook
|
strategy: Webhook
|
||||||
webhook:
|
webhook:
|
||||||
|
conversionReviewVersions: ["v1","v1beta1"]
|
||||||
clientConfig:
|
clientConfig:
|
||||||
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
|
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
|
||||||
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
|
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
|
||||||
|
|||||||
23
config/default/gh-webhook-server-auth-proxy-patch.yaml
Normal file
23
config/default/gh-webhook-server-auth-proxy-patch.yaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# This patch injects an HTTP proxy sidecar container that performs RBAC
|
||||||
|
# authorization against the Kubernetes API using SubjectAccessReviews.
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: github-webhook-server
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: kube-rbac-proxy
|
||||||
|
image: quay.io/brancz/kube-rbac-proxy:v0.10.0
|
||||||
|
args:
|
||||||
|
- '--secure-listen-address=0.0.0.0:8443'
|
||||||
|
- '--upstream=http://127.0.0.1:8080/'
|
||||||
|
- '--logtostderr=true'
|
||||||
|
- '--v=10'
|
||||||
|
ports:
|
||||||
|
- containerPort: 8443
|
||||||
|
name: https
|
||||||
|
- name: github-webhook-server
|
||||||
|
args:
|
||||||
|
- '--metrics-addr=127.0.0.1:8080'
|
||||||
@@ -22,17 +22,20 @@ bases:
|
|||||||
- ../certmanager
|
- ../certmanager
|
||||||
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
|
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
|
||||||
#- ../prometheus
|
#- ../prometheus
|
||||||
|
# [GH_WEBHOOK_SERVER] To enable the GitHub webhook server, uncomment all sections with 'GH_WEBHOOK_SERVER'.
|
||||||
|
#- ../github-webhook-server
|
||||||
|
|
||||||
patchesStrategicMerge:
|
patchesStrategicMerge:
|
||||||
# Protect the /metrics endpoint by putting it behind auth.
|
# Protect the /metrics endpoint by putting it behind auth.
|
||||||
# Only one of manager_auth_proxy_patch.yaml and
|
# Only one of manager_auth_proxy_patch.yaml and
|
||||||
# manager_prometheus_metrics_patch.yaml should be enabled.
|
# manager_prometheus_metrics_patch.yaml should be enabled.
|
||||||
- manager_auth_proxy_patch.yaml
|
- manager_auth_proxy_patch.yaml
|
||||||
# If you want your controller-manager to expose the /metrics
|
|
||||||
# endpoint w/o any authn/z, uncomment the following line and
|
# If you want your controller-manager to expose the /metrics
|
||||||
# comment manager_auth_proxy_patch.yaml.
|
# endpoint w/o any authn/z, uncomment the following line and
|
||||||
# Only one of manager_auth_proxy_patch.yaml and
|
# comment manager_auth_proxy_patch.yaml.
|
||||||
# manager_prometheus_metrics_patch.yaml should be enabled.
|
# Only one of manager_auth_proxy_patch.yaml and
|
||||||
|
# manager_prometheus_metrics_patch.yaml should be enabled.
|
||||||
#- manager_prometheus_metrics_patch.yaml
|
#- manager_prometheus_metrics_patch.yaml
|
||||||
|
|
||||||
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in crd/kustomization.yaml
|
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in crd/kustomization.yaml
|
||||||
@@ -43,6 +46,10 @@ patchesStrategicMerge:
|
|||||||
# 'CERTMANAGER' needs to be enabled to use ca injection
|
# 'CERTMANAGER' needs to be enabled to use ca injection
|
||||||
- webhookcainjection_patch.yaml
|
- webhookcainjection_patch.yaml
|
||||||
|
|
||||||
|
# [GH_WEBHOOK_SERVER] To enable the GitHub webhook server, uncomment all sections with 'GH_WEBHOOK_SERVER'.
|
||||||
|
# Protect the GitHub webhook server metrics endpoint by putting it behind auth.
|
||||||
|
# - gh-webhook-server-auth-proxy-patch.yaml
|
||||||
|
|
||||||
# the following config is for teaching kustomize how to do var substitution
|
# the following config is for teaching kustomize how to do var substitution
|
||||||
vars:
|
vars:
|
||||||
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
|
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
|
||||||
|
|||||||
@@ -23,4 +23,3 @@ spec:
|
|||||||
args:
|
args:
|
||||||
- "--metrics-addr=127.0.0.1:8080"
|
- "--metrics-addr=127.0.0.1:8080"
|
||||||
- "--enable-leader-election"
|
- "--enable-leader-election"
|
||||||
- "--sync-period=10m"
|
|
||||||
|
|||||||
37
config/github-webhook-server/deployment.yaml
Normal file
37
config/github-webhook-server/deployment.yaml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/component: github-webhook-server
|
||||||
|
app.kubernetes.io/part-of: actions-runner-controller
|
||||||
|
name: github-webhook-server
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app.kubernetes.io/component: github-webhook-server
|
||||||
|
app.kubernetes.io/part-of: actions-runner-controller
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/component: github-webhook-server
|
||||||
|
app.kubernetes.io/part-of: actions-runner-controller
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: github-webhook-server
|
||||||
|
image: controller:latest
|
||||||
|
command:
|
||||||
|
- '/github-webhook-server'
|
||||||
|
env:
|
||||||
|
- name: GITHUB_WEBHOOK_SECRET_TOKEN
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
key: github_webhook_secret_token
|
||||||
|
name: github-webhook-server
|
||||||
|
optional: true
|
||||||
|
ports:
|
||||||
|
- containerPort: 8000
|
||||||
|
name: http
|
||||||
|
protocol: TCP
|
||||||
|
serviceAccountName: github-webhook-server
|
||||||
|
terminationGracePeriodSeconds: 10
|
||||||
12
config/github-webhook-server/kustomization.yaml
Normal file
12
config/github-webhook-server/kustomization.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
images:
|
||||||
|
- name: controller
|
||||||
|
newName: summerwind/actions-runner-controller
|
||||||
|
newTag: latest
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
- rbac.yaml
|
||||||
|
- service.yaml
|
||||||
113
config/github-webhook-server/rbac.yaml
Normal file
113
config/github-webhook-server/rbac.yaml
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/component: github-webhook-server
|
||||||
|
app.kubernetes.io/part-of: actions-runner-controller
|
||||||
|
name: github-webhook-server
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/component: github-webhook-server
|
||||||
|
app.kubernetes.io/part-of: actions-runner-controller
|
||||||
|
name: github-webhook-server
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- actions.summerwind.dev
|
||||||
|
resources:
|
||||||
|
- horizontalrunnerautoscalers
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- actions.summerwind.dev
|
||||||
|
resources:
|
||||||
|
- horizontalrunnerautoscalers/finalizers
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- actions.summerwind.dev
|
||||||
|
resources:
|
||||||
|
- horizontalrunnerautoscalers/status
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- apiGroups:
|
||||||
|
- actions.summerwind.dev
|
||||||
|
resources:
|
||||||
|
- runnersets
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- actions.summerwind.dev
|
||||||
|
resources:
|
||||||
|
- runnerdeployments
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- actions.summerwind.dev
|
||||||
|
resources:
|
||||||
|
- runnerdeployments/finalizers
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- actions.summerwind.dev
|
||||||
|
resources:
|
||||||
|
- runnerdeployments/status
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- apiGroups:
|
||||||
|
- authentication.k8s.io
|
||||||
|
resources:
|
||||||
|
- tokenreviews
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- apiGroups:
|
||||||
|
- authorization.k8s.io
|
||||||
|
resources:
|
||||||
|
- subjectaccessreviews
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/component: github-webhook-server
|
||||||
|
app.kubernetes.io/part-of: actions-runner-controller
|
||||||
|
name: github-webhook-server
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: github-webhook-server
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: github-webhook-server
|
||||||
16
config/github-webhook-server/service.yaml
Normal file
16
config/github-webhook-server/service.yaml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/component: github-webhook-server
|
||||||
|
app.kubernetes.io/part-of: actions-runner-controller
|
||||||
|
name: github-webhook-server
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: http
|
||||||
|
protocol: TCP
|
||||||
|
name: http
|
||||||
|
selector:
|
||||||
|
app.kubernetes.io/component: github-webhook-server
|
||||||
|
app.kubernetes.io/part-of: actions-runner-controller
|
||||||
@@ -202,6 +202,29 @@ rules:
|
|||||||
verbs:
|
verbs:
|
||||||
- create
|
- create
|
||||||
- patch
|
- patch
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- persistentvolumeclaims
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- persistentvolumes
|
||||||
|
verbs:
|
||||||
|
- delete
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- patch
|
||||||
|
- update
|
||||||
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- ""
|
- ""
|
||||||
resources:
|
resources:
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
||||||
|
"github.com/google/go-github/v39/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -19,47 +19,6 @@ const (
|
|||||||
defaultScaleDownFactor = 0.7
|
defaultScaleDownFactor = 0.7
|
||||||
)
|
)
|
||||||
|
|
||||||
func getValueAvailableAt(now time.Time, from, to *time.Time, reservedValue int) *int {
|
|
||||||
if to != nil && now.After(*to) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if from != nil && now.Before(*from) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return &reservedValue
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *HorizontalRunnerAutoscalerReconciler) fetchSuggestedReplicasFromCache(hra v1alpha1.HorizontalRunnerAutoscaler) *int {
|
|
||||||
var entry *v1alpha1.CacheEntry
|
|
||||||
|
|
||||||
for i := range hra.Status.CacheEntries {
|
|
||||||
ent := hra.Status.CacheEntries[i]
|
|
||||||
|
|
||||||
if ent.Key != v1alpha1.CacheEntryKeyDesiredReplicas {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !time.Now().Before(ent.ExpirationTime.Time) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
entry = &ent
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if entry != nil {
|
|
||||||
v := getValueAvailableAt(time.Now(), nil, &entry.ExpirationTime.Time, entry.Value)
|
|
||||||
if v != nil {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *HorizontalRunnerAutoscalerReconciler) suggestDesiredReplicas(st scaleTarget, hra v1alpha1.HorizontalRunnerAutoscaler) (*int, error) {
|
func (r *HorizontalRunnerAutoscalerReconciler) suggestDesiredReplicas(st scaleTarget, hra v1alpha1.HorizontalRunnerAutoscaler) (*int, error) {
|
||||||
if hra.Spec.MinReplicas == nil {
|
if hra.Spec.MinReplicas == nil {
|
||||||
return nil, fmt.Errorf("horizontalrunnerautoscaler %s/%s is missing minReplicas", hra.Namespace, hra.Name)
|
return nil, fmt.Errorf("horizontalrunnerautoscaler %s/%s is missing minReplicas", hra.Namespace, hra.Name)
|
||||||
@@ -70,10 +29,8 @@ func (r *HorizontalRunnerAutoscalerReconciler) suggestDesiredReplicas(st scaleTa
|
|||||||
metrics := hra.Spec.Metrics
|
metrics := hra.Spec.Metrics
|
||||||
numMetrics := len(metrics)
|
numMetrics := len(metrics)
|
||||||
if numMetrics == 0 {
|
if numMetrics == 0 {
|
||||||
if len(hra.Spec.ScaleUpTriggers) == 0 {
|
// We don't default to anything since ARC 0.23.0
|
||||||
return r.suggestReplicasByQueuedAndInProgressWorkflowRuns(st, hra, nil)
|
// See https://github.com/actions-runner-controller/actions-runner-controller/issues/728
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else if numMetrics > 2 {
|
} else if numMetrics > 2 {
|
||||||
return nil, fmt.Errorf("too many autoscaling metrics configured: It must be 0 to 2, but got %d", numMetrics)
|
return nil, fmt.Errorf("too many autoscaling metrics configured: It must be 0 to 2, but got %d", numMetrics)
|
||||||
@@ -164,14 +121,46 @@ func (r *HorizontalRunnerAutoscalerReconciler) suggestReplicasByQueuedAndInProgr
|
|||||||
fallback_cb()
|
fallback_cb()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
jobs, _, err := r.GitHubClient.Actions.ListWorkflowJobs(context.TODO(), user, repoName, runID, nil)
|
opt := github.ListWorkflowJobsOptions{ListOptions: github.ListOptions{PerPage: 50}}
|
||||||
if err != nil {
|
var allJobs []*github.WorkflowJob
|
||||||
r.Log.Error(err, "Error listing workflow jobs")
|
for {
|
||||||
fallback_cb()
|
jobs, resp, err := r.GitHubClient.Actions.ListWorkflowJobs(context.TODO(), user, repoName, runID, &opt)
|
||||||
} else if len(jobs.Jobs) == 0 {
|
if err != nil {
|
||||||
|
r.Log.Error(err, "Error listing workflow jobs")
|
||||||
|
return //err
|
||||||
|
}
|
||||||
|
allJobs = append(allJobs, jobs.Jobs...)
|
||||||
|
if resp.NextPage == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
opt.Page = resp.NextPage
|
||||||
|
}
|
||||||
|
if len(allJobs) == 0 {
|
||||||
fallback_cb()
|
fallback_cb()
|
||||||
} else {
|
} else {
|
||||||
for _, job := range jobs.Jobs {
|
JOB:
|
||||||
|
for _, job := range allJobs {
|
||||||
|
runnerLabels := make(map[string]struct{}, len(st.labels))
|
||||||
|
for _, l := range st.labels {
|
||||||
|
runnerLabels[l] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(job.Labels) == 0 {
|
||||||
|
// This shouldn't usually happen
|
||||||
|
r.Log.Info("Detected job with no labels, which is not supported by ARC. Skipping anyway.", "labels", job.Labels, "run_id", job.GetRunID(), "job_id", job.GetID())
|
||||||
|
continue JOB
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, l := range job.Labels {
|
||||||
|
if l == "self-hosted" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := runnerLabels[l]; !ok {
|
||||||
|
continue JOB
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch job.GetStatus() {
|
switch job.GetStatus() {
|
||||||
case "completed":
|
case "completed":
|
||||||
// We add a case for `completed` so it is not counted in `unknown`.
|
// We add a case for `completed` so it is not counted in `unknown`.
|
||||||
|
|||||||
@@ -41,8 +41,12 @@ func TestDetermineDesiredReplicas_RepositoryRunner(t *testing.T) {
|
|||||||
|
|
||||||
metav1Now := metav1.Now()
|
metav1Now := metav1.Now()
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
repo string
|
description string
|
||||||
org string
|
|
||||||
|
repo string
|
||||||
|
org string
|
||||||
|
labels []string
|
||||||
|
|
||||||
fixed *int
|
fixed *int
|
||||||
max *int
|
max *int
|
||||||
min *int
|
min *int
|
||||||
@@ -68,6 +72,19 @@ func TestDetermineDesiredReplicas_RepositoryRunner(t *testing.T) {
|
|||||||
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"status":"in_progress"}, {"status":"in_progress"}]}"`,
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"status":"in_progress"}, {"status":"in_progress"}]}"`,
|
||||||
want: 3,
|
want: 3,
|
||||||
},
|
},
|
||||||
|
// Explicitly speified the default `self-hosted` label which is ignored by the simulator,
|
||||||
|
// as we assume that GitHub Actions automatically associates the `self-hosted` label to every self-hosted runner.
|
||||||
|
// 3 demanded, max at 3
|
||||||
|
{
|
||||||
|
repo: "test/valid",
|
||||||
|
labels: []string{"self-hosted"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(3),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"status":"queued"}, {"status":"in_progress"}, {"status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"status":"in_progress"}, {"status":"in_progress"}]}"`,
|
||||||
|
want: 3,
|
||||||
|
},
|
||||||
// 2 demanded, max at 3, currently 3, delay scaling down due to grace period
|
// 2 demanded, max at 3, currently 3, delay scaling down due to grace period
|
||||||
{
|
{
|
||||||
repo: "test/valid",
|
repo: "test/valid",
|
||||||
@@ -152,9 +169,40 @@ func TestDetermineDesiredReplicas_RepositoryRunner(t *testing.T) {
|
|||||||
want: 3,
|
want: 3,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Job-level autoscaling
|
|
||||||
// 5 requested from 3 workflows
|
|
||||||
{
|
{
|
||||||
|
description: "Job-level autoscaling with no explicit runner label (runners have implicit self-hosted, requested self-hosted, 5 jobs from 3 workflows)",
|
||||||
|
repo: "test/valid",
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted"]}, {"status":"queued", "labels":["self-hosted"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted"]}, {"status":"completed", "labels":["self-hosted"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted"]}, {"status":"queued", "labels":["self-hosted"]}]}`,
|
||||||
|
},
|
||||||
|
want: 5,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Skipped job-level autoscaling with no explicit runner label (runners have implicit self-hosted, requested self-hosted+custom, 0 jobs from 3 workflows)",
|
||||||
|
repo: "test/valid",
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"completed", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
},
|
||||||
|
want: 2,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Skipped job-level autoscaling with no label (runners have implicit self-hosted, jobs had no labels, 0 jobs from 3 workflows)",
|
||||||
repo: "test/valid",
|
repo: "test/valid",
|
||||||
min: intPtr(2),
|
min: intPtr(2),
|
||||||
max: intPtr(10),
|
max: intPtr(10),
|
||||||
@@ -166,6 +214,91 @@ func TestDetermineDesiredReplicas_RepositoryRunner(t *testing.T) {
|
|||||||
2: `{"jobs": [{"status": "in_progress"}, {"status":"completed"}]}`,
|
2: `{"jobs": [{"status": "in_progress"}, {"status":"completed"}]}`,
|
||||||
3: `{"jobs": [{"status": "in_progress"}, {"status":"queued"}]}`,
|
3: `{"jobs": [{"status": "in_progress"}, {"status":"queued"}]}`,
|
||||||
},
|
},
|
||||||
|
want: 2,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Skipped job-level autoscaling with default runner label (runners have self-hosted only, requested self-hosted+custom, 0 jobs from 3 workflows)",
|
||||||
|
repo: "test/valid",
|
||||||
|
labels: []string{"self-hosted"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"completed", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
},
|
||||||
|
want: 2,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Skipped job-level autoscaling with custom runner label (runners have custom2, requested self-hosted+custom, 0 jobs from 5 workflows",
|
||||||
|
repo: "test/valid",
|
||||||
|
labels: []string{"custom2"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"completed", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
},
|
||||||
|
want: 2,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Skipped job-level autoscaling with default runner label (runners have self-hosted, requested managed-runner-label, 0 jobs from 3 runs)",
|
||||||
|
repo: "test/valid",
|
||||||
|
labels: []string{"self-hosted"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["managed-runner-label"]}, {"status":"queued", "labels":["managed-runner-label"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["managed-runner-label"]}, {"status":"completed", "labels":["managed-runner-label"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["managed-runner-label"]}, {"status":"queued", "labels":["managed-runner-label"]}]}`,
|
||||||
|
},
|
||||||
|
want: 2,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Job-level autoscaling with default + custom runner label (runners have self-hosted+custom, requested self-hosted+custom, 5 jobs from 3 workflows)",
|
||||||
|
repo: "test/valid",
|
||||||
|
labels: []string{"self-hosted", "custom"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"completed", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
},
|
||||||
|
want: 5,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Job-level autoscaling with custom runner label (runners have custom, requested self-hosted+custom, 5 jobs from 3 workflows)",
|
||||||
|
repo: "test/valid",
|
||||||
|
labels: []string{"custom"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"completed", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
},
|
||||||
want: 5,
|
want: 5,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -181,7 +314,12 @@ func TestDetermineDesiredReplicas_RepositoryRunner(t *testing.T) {
|
|||||||
_ = clientgoscheme.AddToScheme(scheme)
|
_ = clientgoscheme.AddToScheme(scheme)
|
||||||
_ = v1alpha1.AddToScheme(scheme)
|
_ = v1alpha1.AddToScheme(scheme)
|
||||||
|
|
||||||
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
|
testName := fmt.Sprintf("case %d", i)
|
||||||
|
if tc.description != "" {
|
||||||
|
testName = tc.description
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run(testName, func(t *testing.T) {
|
||||||
server := fake.NewServer(
|
server := fake.NewServer(
|
||||||
fake.WithListRepositoryWorkflowRunsResponse(200, tc.workflowRuns, tc.workflowRuns_queued, tc.workflowRuns_in_progress),
|
fake.WithListRepositoryWorkflowRunsResponse(200, tc.workflowRuns, tc.workflowRuns_queued, tc.workflowRuns_in_progress),
|
||||||
fake.WithListWorkflowJobsResponse(200, tc.workflowJobs),
|
fake.WithListWorkflowJobsResponse(200, tc.workflowJobs),
|
||||||
@@ -191,9 +329,10 @@ func TestDetermineDesiredReplicas_RepositoryRunner(t *testing.T) {
|
|||||||
client := newGithubClient(server)
|
client := newGithubClient(server)
|
||||||
|
|
||||||
h := &HorizontalRunnerAutoscalerReconciler{
|
h := &HorizontalRunnerAutoscalerReconciler{
|
||||||
Log: log,
|
Log: log,
|
||||||
GitHubClient: client,
|
GitHubClient: client,
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
|
DefaultScaleDownDelay: DefaultScaleDownDelay,
|
||||||
}
|
}
|
||||||
|
|
||||||
rd := v1alpha1.RunnerDeployment{
|
rd := v1alpha1.RunnerDeployment{
|
||||||
@@ -206,6 +345,7 @@ func TestDetermineDesiredReplicas_RepositoryRunner(t *testing.T) {
|
|||||||
Spec: v1alpha1.RunnerSpec{
|
Spec: v1alpha1.RunnerSpec{
|
||||||
RunnerConfig: v1alpha1.RunnerConfig{
|
RunnerConfig: v1alpha1.RunnerConfig{
|
||||||
Repository: tc.repo,
|
Repository: tc.repo,
|
||||||
|
Labels: tc.labels,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -220,6 +360,11 @@ func TestDetermineDesiredReplicas_RepositoryRunner(t *testing.T) {
|
|||||||
Spec: v1alpha1.HorizontalRunnerAutoscalerSpec{
|
Spec: v1alpha1.HorizontalRunnerAutoscalerSpec{
|
||||||
MaxReplicas: tc.max,
|
MaxReplicas: tc.max,
|
||||||
MinReplicas: tc.min,
|
MinReplicas: tc.min,
|
||||||
|
Metrics: []v1alpha1.MetricSpec{
|
||||||
|
{
|
||||||
|
Type: "TotalNumberOfQueuedAndInProgressWorkflowRuns",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Status: v1alpha1.HorizontalRunnerAutoscalerStatus{
|
Status: v1alpha1.HorizontalRunnerAutoscalerStatus{
|
||||||
DesiredReplicas: tc.sReplicas,
|
DesiredReplicas: tc.sReplicas,
|
||||||
@@ -234,7 +379,7 @@ func TestDetermineDesiredReplicas_RepositoryRunner(t *testing.T) {
|
|||||||
|
|
||||||
st := h.scaleTargetFromRD(context.Background(), rd)
|
st := h.scaleTargetFromRD(context.Background(), rd)
|
||||||
|
|
||||||
got, _, _, err := h.computeReplicasWithCache(log, metav1Now.Time, st, hra, minReplicas)
|
got, err := h.computeReplicasWithCache(log, metav1Now.Time, st, hra, minReplicas)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if tc.err == "" {
|
if tc.err == "" {
|
||||||
t.Fatalf("unexpected error: expected none, got %v", err)
|
t.Fatalf("unexpected error: expected none, got %v", err)
|
||||||
@@ -258,8 +403,12 @@ func TestDetermineDesiredReplicas_OrganizationalRunner(t *testing.T) {
|
|||||||
|
|
||||||
metav1Now := metav1.Now()
|
metav1Now := metav1.Now()
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
repos []string
|
description string
|
||||||
org string
|
|
||||||
|
repos []string
|
||||||
|
org string
|
||||||
|
labels []string
|
||||||
|
|
||||||
fixed *int
|
fixed *int
|
||||||
max *int
|
max *int
|
||||||
min *int
|
min *int
|
||||||
@@ -399,9 +548,43 @@ func TestDetermineDesiredReplicas_OrganizationalRunner(t *testing.T) {
|
|||||||
err: "validating autoscaling metrics: spec.autoscaling.metrics[].repositoryNames is required and must have one more more entries for organizational runner deployment",
|
err: "validating autoscaling metrics: spec.autoscaling.metrics[].repositoryNames is required and must have one more more entries for organizational runner deployment",
|
||||||
},
|
},
|
||||||
|
|
||||||
// Job-level autoscaling
|
|
||||||
// 5 requested from 3 workflows
|
|
||||||
{
|
{
|
||||||
|
description: "Job-level autoscaling (runners have implicit self-hosted, requested self-hosted, 5 jobs from 3 runs)",
|
||||||
|
org: "test",
|
||||||
|
repos: []string{"valid"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted"]}, {"status":"queued", "labels":["self-hosted"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted"]}, {"status":"completed", "labels":["self-hosted"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted"]}, {"status":"queued", "labels":["self-hosted"]}]}`,
|
||||||
|
},
|
||||||
|
want: 5,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Job-level autoscaling (runners have explicit self-hosted, requested self-hosted, 5 jobs from 3 runs)",
|
||||||
|
org: "test",
|
||||||
|
repos: []string{"valid"},
|
||||||
|
labels: []string{"self-hosted"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted"]}, {"status":"queued", "labels":["self-hosted"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted"]}, {"status":"completed", "labels":["self-hosted"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted"]}, {"status":"queued", "labels":["self-hosted"]}]}`,
|
||||||
|
},
|
||||||
|
want: 5,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Skipped job-level autoscaling (jobs lack labels, 0 requested from 3 workflows)",
|
||||||
org: "test",
|
org: "test",
|
||||||
repos: []string{"valid"},
|
repos: []string{"valid"},
|
||||||
min: intPtr(2),
|
min: intPtr(2),
|
||||||
@@ -414,8 +597,97 @@ func TestDetermineDesiredReplicas_OrganizationalRunner(t *testing.T) {
|
|||||||
2: `{"jobs": [{"status": "in_progress"}, {"status":"completed"}]}`,
|
2: `{"jobs": [{"status": "in_progress"}, {"status":"completed"}]}`,
|
||||||
3: `{"jobs": [{"status": "in_progress"}, {"status":"queued"}]}`,
|
3: `{"jobs": [{"status": "in_progress"}, {"status":"queued"}]}`,
|
||||||
},
|
},
|
||||||
|
want: 2,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Skipped job-level autoscaling (runners have valid and implicit self-hosted, requested self-hosted+custom, 0 jobs from 3 runs)",
|
||||||
|
org: "test",
|
||||||
|
repos: []string{"valid"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"completed", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
},
|
||||||
|
want: 2,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Skipped job-level autoscaling (runners have self-hosted, requested self-hosted+custom, 0 jobs from 3 workflows)",
|
||||||
|
org: "test",
|
||||||
|
repos: []string{"valid"},
|
||||||
|
labels: []string{"self-hosted"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"completed", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
},
|
||||||
|
want: 2,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Job-level autoscaling (runners have custom, requested self-hosted+custom, 5 requested from 3 workflows)",
|
||||||
|
org: "test",
|
||||||
|
repos: []string{"valid"},
|
||||||
|
labels: []string{"custom"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"completed", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
},
|
||||||
want: 5,
|
want: 5,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Job-level autoscaling (runners have custom, requested custom, 5 requested from 3 workflows)",
|
||||||
|
org: "test",
|
||||||
|
repos: []string{"valid"},
|
||||||
|
labels: []string{"custom"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["custom"]}, {"status":"queued", "labels":["custom"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["custom"]}, {"status":"completed", "labels":["custom"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["custom"]}, {"status":"queued", "labels":["custom"]}]}`,
|
||||||
|
},
|
||||||
|
want: 5,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
description: "Skipped job-level autoscaling (specified custom2, 0 requested from 3 workflows)",
|
||||||
|
org: "test",
|
||||||
|
repos: []string{"valid"},
|
||||||
|
labels: []string{"custom2"},
|
||||||
|
min: intPtr(2),
|
||||||
|
max: intPtr(10),
|
||||||
|
workflowRuns: `{"total_count": 4, "workflow_runs":[{"id": 1, "status":"queued"}, {"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowRuns_queued: `{"total_count": 1, "workflow_runs":[{"id": 1, "status":"queued"}]}"`,
|
||||||
|
workflowRuns_in_progress: `{"total_count": 2, "workflow_runs":[{"id": 2, "status":"in_progress"}, {"id": 3, "status":"in_progress"}, {"status":"completed"}]}"`,
|
||||||
|
workflowJobs: map[int]string{
|
||||||
|
1: `{"jobs": [{"status":"queued", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
2: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"completed", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
3: `{"jobs": [{"status": "in_progress", "labels":["self-hosted", "custom"]}, {"status":"queued", "labels":["self-hosted", "custom"]}]}`,
|
||||||
|
},
|
||||||
|
want: 2,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range testcases {
|
for i := range testcases {
|
||||||
@@ -429,7 +701,12 @@ func TestDetermineDesiredReplicas_OrganizationalRunner(t *testing.T) {
|
|||||||
_ = clientgoscheme.AddToScheme(scheme)
|
_ = clientgoscheme.AddToScheme(scheme)
|
||||||
_ = v1alpha1.AddToScheme(scheme)
|
_ = v1alpha1.AddToScheme(scheme)
|
||||||
|
|
||||||
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
|
testName := fmt.Sprintf("case %d", i)
|
||||||
|
if tc.description != "" {
|
||||||
|
testName = tc.description
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run(testName, func(t *testing.T) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
server := fake.NewServer(
|
server := fake.NewServer(
|
||||||
@@ -441,9 +718,10 @@ func TestDetermineDesiredReplicas_OrganizationalRunner(t *testing.T) {
|
|||||||
client := newGithubClient(server)
|
client := newGithubClient(server)
|
||||||
|
|
||||||
h := &HorizontalRunnerAutoscalerReconciler{
|
h := &HorizontalRunnerAutoscalerReconciler{
|
||||||
Log: log,
|
Log: log,
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
GitHubClient: client,
|
GitHubClient: client,
|
||||||
|
DefaultScaleDownDelay: DefaultScaleDownDelay,
|
||||||
}
|
}
|
||||||
|
|
||||||
rd := v1alpha1.RunnerDeployment{
|
rd := v1alpha1.RunnerDeployment{
|
||||||
@@ -465,6 +743,7 @@ func TestDetermineDesiredReplicas_OrganizationalRunner(t *testing.T) {
|
|||||||
Spec: v1alpha1.RunnerSpec{
|
Spec: v1alpha1.RunnerSpec{
|
||||||
RunnerConfig: v1alpha1.RunnerConfig{
|
RunnerConfig: v1alpha1.RunnerConfig{
|
||||||
Organization: tc.org,
|
Organization: tc.org,
|
||||||
|
Labels: tc.labels,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -502,7 +781,7 @@ func TestDetermineDesiredReplicas_OrganizationalRunner(t *testing.T) {
|
|||||||
|
|
||||||
st := h.scaleTargetFromRD(context.Background(), rd)
|
st := h.scaleTargetFromRD(context.Background(), rd)
|
||||||
|
|
||||||
got, _, _, err := h.computeReplicasWithCache(log, metav1Now.Time, st, hra, minReplicas)
|
got, err := h.computeReplicasWithCache(log, metav1Now.Time, st, hra, minReplicas)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if tc.err == "" {
|
if tc.err == "" {
|
||||||
t.Fatalf("unexpected error: expected none, got %v", err)
|
t.Fatalf("unexpected error: expected none, got %v", err)
|
||||||
|
|||||||
64
controllers/constants.go
Normal file
64
controllers/constants.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
const (
|
||||||
|
LabelKeyRunnerSetName = "runnerset-name"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// This names requires at least one slash to work.
|
||||||
|
// See https://github.com/google/knative-gcp/issues/378
|
||||||
|
runnerPodFinalizerName = "actions.summerwind.dev/runner-pod"
|
||||||
|
|
||||||
|
annotationKeyPrefix = "actions-runner/"
|
||||||
|
|
||||||
|
AnnotationKeyLastRegistrationCheckTime = "actions-runner-controller/last-registration-check-time"
|
||||||
|
|
||||||
|
// AnnotationKeyUnregistrationCompleteTimestamp is the annotation that is added onto the pod once the previously started unregistration process has been completed.
|
||||||
|
AnnotationKeyUnregistrationCompleteTimestamp = annotationKeyPrefix + "unregistration-complete-timestamp"
|
||||||
|
|
||||||
|
// AnnotationKeyRunnerCompletionWaitStartTimestamp is the annotation that is added onto the pod when
|
||||||
|
// ARC decided to wait until the pod to complete by itself, without the need for ARC to unregister the corresponding runner.
|
||||||
|
AnnotationKeyRunnerCompletionWaitStartTimestamp = annotationKeyPrefix + "runner-completion-wait-start-timestamp"
|
||||||
|
|
||||||
|
// unregistarionStartTimestamp is the annotation that contains the time that the requested unregistration process has been started
|
||||||
|
AnnotationKeyUnregistrationStartTimestamp = annotationKeyPrefix + "unregistration-start-timestamp"
|
||||||
|
|
||||||
|
// AnnotationKeyUnregistrationRequestTimestamp is the annotation that contains the time that the unregistration has been requested.
|
||||||
|
// This doesn't immediately start the unregistration. Instead, ARC will first check if the runner has already been registered.
|
||||||
|
// If not, ARC will hold on until the registration to complete first, and only after that it starts the unregistration process.
|
||||||
|
// This is crucial to avoid a race between ARC marking the runner pod for deletion while the actions-runner registers itself to GitHub, leaving the assigned job
|
||||||
|
// hang like forever.
|
||||||
|
AnnotationKeyUnregistrationRequestTimestamp = annotationKeyPrefix + "unregistration-request-timestamp"
|
||||||
|
|
||||||
|
AnnotationKeyRunnerID = annotationKeyPrefix + "id"
|
||||||
|
|
||||||
|
// This can be any value but a larger value can make an unregistration timeout longer than configured in practice.
|
||||||
|
DefaultUnregistrationRetryDelay = time.Minute
|
||||||
|
|
||||||
|
// RetryDelayOnCreateRegistrationError is the delay between retry attempts for runner registration token creation.
|
||||||
|
// Usually, a retry in this case happens when e.g. your PAT has no access to certain scope of runners, like you're using repository admin's token
|
||||||
|
// for creating a broader scoped runner token, like organizationa or enterprise runner token.
|
||||||
|
// Such permission issue will never fixed automatically, so we don't need to retry so often, hence this value.
|
||||||
|
RetryDelayOnCreateRegistrationError = 3 * time.Minute
|
||||||
|
|
||||||
|
// registrationTimeout is the duration until a pod times out after it becomes Ready and Running.
|
||||||
|
// A pod that is timed out can be terminated if needed.
|
||||||
|
registrationTimeout = 10 * time.Minute
|
||||||
|
|
||||||
|
// DefaultRunnerPodRecreationDelayAfterWebhookScale is the delay until syncing the runners with the desired replicas
|
||||||
|
// after a webhook-based scale up.
|
||||||
|
// This is used to prevent ARC from recreating completed runner pods that are deleted soon without being used at all.
|
||||||
|
// In other words, this is used as a timer to wait for the completed runner to emit the next `workflow_job` webhook event to decrease the desired replicas.
|
||||||
|
// So if we set 30 seconds for this, you are basically saying that you would assume GitHub and your installation of ARC to
|
||||||
|
// emit and propagate a workflow_job completion event down to the RunnerSet or RunnerReplicaSet, vha ARC's github webhook server and HRA, in approximately 30 seconds.
|
||||||
|
// In case it actually took more than DefaultRunnerPodRecreationDelayAfterWebhookScale for the workflow_job completion event to arrive,
|
||||||
|
// ARC will recreate the completed runner(s), assuming something went wrong in either GitHub, your K8s cluster, or ARC, so ARC needs to resync anyway.
|
||||||
|
//
|
||||||
|
// See https://github.com/actions-runner-controller/actions-runner-controller/pull/1180
|
||||||
|
DefaultRunnerPodRecreationDelayAfterWebhookScale = 10 * time.Minute
|
||||||
|
|
||||||
|
EnvVarRunnerName = "RUNNER_NAME"
|
||||||
|
EnvVarRunnerToken = "RUNNER_TOKEN"
|
||||||
|
)
|
||||||
@@ -30,19 +30,22 @@ import (
|
|||||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||||
|
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
gogithub "github.com/google/go-github/v37/github"
|
gogithub "github.com/google/go-github/v39/github"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
||||||
|
"github.com/actions-runner-controller/actions-runner-controller/github"
|
||||||
|
"github.com/actions-runner-controller/actions-runner-controller/simulator"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
scaleTargetKey = "scaleTarget"
|
scaleTargetKey = "scaleTarget"
|
||||||
|
|
||||||
keyPrefixEnterprise = "enterprises/"
|
keyPrefixEnterprise = "enterprises/"
|
||||||
|
keyRunnerGroup = "/group/"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HorizontalRunnerAutoscalerGitHubWebhook autoscales a HorizontalRunnerAutoscaler and the RunnerDeployment on each
|
// HorizontalRunnerAutoscalerGitHubWebhook autoscales a HorizontalRunnerAutoscaler and the RunnerDeployment on each
|
||||||
@@ -57,6 +60,9 @@ type HorizontalRunnerAutoscalerGitHubWebhook struct {
|
|||||||
// the administrator is generated and specified in GitHub Web UI.
|
// the administrator is generated and specified in GitHub Web UI.
|
||||||
SecretKeyBytes []byte
|
SecretKeyBytes []byte
|
||||||
|
|
||||||
|
// GitHub Client to discover runner groups assigned to a repository
|
||||||
|
GitHubClient *github.Client
|
||||||
|
|
||||||
// Namespace is the namespace to watch for HorizontalRunnerAutoscaler's to be
|
// Namespace is the namespace to watch for HorizontalRunnerAutoscaler's to be
|
||||||
// scaled on Webhook.
|
// scaled on Webhook.
|
||||||
// Set to empty for letting it watch for all namespaces.
|
// Set to empty for letting it watch for all namespaces.
|
||||||
@@ -87,7 +93,7 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) Handle(w http.Respons
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
msg := err.Error()
|
msg := err.Error()
|
||||||
if written, err := w.Write([]byte(msg)); err != nil {
|
if written, err := w.Write([]byte(msg)); err != nil {
|
||||||
autoscaler.Log.Error(err, "failed writing http error response", "msg", msg, "written", written)
|
autoscaler.Log.V(1).Error(err, "failed writing http error response", "msg", msg, "written", written)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,18 +242,23 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) Handle(w http.Respons
|
|||||||
enterpriseSlug,
|
enterpriseSlug,
|
||||||
labels,
|
labels,
|
||||||
)
|
)
|
||||||
|
if target == nil {
|
||||||
if target != nil {
|
break
|
||||||
if e.GetAction() == "queued" {
|
|
||||||
target.Amount = 1
|
|
||||||
} else if e.GetAction() == "completed" {
|
|
||||||
// A nagative amount is processed in the tryScale func as a scale-down request,
|
|
||||||
// that erasese the oldest CapacityReservation with the same amount.
|
|
||||||
// If the first CapacityReservation was with Replicas=1, this negative scale target erases that,
|
|
||||||
// so that the resulting desired replicas decreases by 1.
|
|
||||||
target.Amount = -1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.GetAction() == "queued" {
|
||||||
|
target.Amount = 1
|
||||||
|
break
|
||||||
|
} else if e.GetAction() == "completed" && e.GetWorkflowJob().GetConclusion() != "skipped" {
|
||||||
|
// A nagative amount is processed in the tryScale func as a scale-down request,
|
||||||
|
// that erasese the oldest CapacityReservation with the same amount.
|
||||||
|
// If the first CapacityReservation was with Replicas=1, this negative scale target erases that,
|
||||||
|
// so that the resulting desired replicas decreases by 1.
|
||||||
|
target.Amount = -1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// If the conclusion is "skipped", we will ignore it and fallthrough to the default case.
|
||||||
|
fallthrough
|
||||||
default:
|
default:
|
||||||
ok = true
|
ok = true
|
||||||
|
|
||||||
@@ -284,7 +295,7 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) Handle(w http.Respons
|
|||||||
}
|
}
|
||||||
|
|
||||||
if target == nil {
|
if target == nil {
|
||||||
log.Info(
|
log.V(1).Info(
|
||||||
"Scale target not found. If this is unexpected, ensure that there is exactly one repository-wide or organizational runner deployment that matches this webhook event",
|
"Scale target not found. If this is unexpected, ensure that there is exactly one repository-wide or organizational runner deployment that matches this webhook event",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -345,9 +356,7 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) findHRAsByKey(ctx con
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range hraList.Items {
|
hras = append(hras, hraList.Items...)
|
||||||
hras = append(hras, d)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hras, nil
|
return hras, nil
|
||||||
@@ -436,63 +445,30 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getScaleTarget(ctx co
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getScaleUpTarget(ctx context.Context, log logr.Logger, repo, owner, ownerType, enterprise string, f func(v1alpha1.ScaleUpTrigger) bool) (*ScaleTarget, error) {
|
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getScaleUpTarget(ctx context.Context, log logr.Logger, repo, owner, ownerType, enterprise string, f func(v1alpha1.ScaleUpTrigger) bool) (*ScaleTarget, error) {
|
||||||
repositoryRunnerKey := owner + "/" + repo
|
scaleTarget := func(value string) (*ScaleTarget, error) {
|
||||||
|
return autoscaler.getScaleTarget(ctx, value, f)
|
||||||
if target, err := autoscaler.getScaleTarget(ctx, repositoryRunnerKey, f); err != nil {
|
|
||||||
log.Info("finding repository-wide runner", "repository", repositoryRunnerKey)
|
|
||||||
return nil, err
|
|
||||||
} else if target != nil {
|
|
||||||
log.Info("scale up target is repository-wide runners", "repository", repo)
|
|
||||||
return target, nil
|
|
||||||
}
|
}
|
||||||
|
return autoscaler.getScaleUpTargetWithFunction(ctx, log, repo, owner, ownerType, enterprise, scaleTarget)
|
||||||
if ownerType == "User" {
|
|
||||||
log.V(1).Info("no repository runner found", "organization", owner)
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if target, err := autoscaler.getScaleTarget(ctx, owner, f); err != nil {
|
|
||||||
log.Info("finding organizational runner", "organization", owner)
|
|
||||||
return nil, err
|
|
||||||
} else if target != nil {
|
|
||||||
log.Info("scale up target is organizational runners", "organization", owner)
|
|
||||||
return target, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if enterprise == "" {
|
|
||||||
log.V(1).Info("no repository runner or organizational runner found",
|
|
||||||
"repository", repositoryRunnerKey,
|
|
||||||
"organization", owner,
|
|
||||||
)
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if target, err := autoscaler.getScaleTarget(ctx, enterpriseKey(enterprise), f); err != nil {
|
|
||||||
log.Error(err, "finding enterprise runner", "enterprise", enterprise)
|
|
||||||
return nil, err
|
|
||||||
} else if target != nil {
|
|
||||||
log.Info("scale up target is enterprise runners", "enterprise", enterprise)
|
|
||||||
return target, nil
|
|
||||||
} else {
|
|
||||||
log.V(1).Info("no repository/organizational/enterprise runner found",
|
|
||||||
"repository", repositoryRunnerKey,
|
|
||||||
"organization", owner,
|
|
||||||
"enterprises", enterprise,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getJobScaleUpTargetForRepoOrOrg(
|
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getJobScaleUpTargetForRepoOrOrg(
|
||||||
ctx context.Context, log logr.Logger, repo, owner, ownerType, enterprise string, labels []string,
|
ctx context.Context, log logr.Logger, repo, owner, ownerType, enterprise string, labels []string,
|
||||||
) (*ScaleTarget, error) {
|
) (*ScaleTarget, error) {
|
||||||
|
|
||||||
|
scaleTarget := func(value string) (*ScaleTarget, error) {
|
||||||
|
return autoscaler.getJobScaleTarget(ctx, value, labels)
|
||||||
|
}
|
||||||
|
return autoscaler.getScaleUpTargetWithFunction(ctx, log, repo, owner, ownerType, enterprise, scaleTarget)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getScaleUpTargetWithFunction(
|
||||||
|
ctx context.Context, log logr.Logger, repo, owner, ownerType, enterprise string, scaleTarget func(value string) (*ScaleTarget, error)) (*ScaleTarget, error) {
|
||||||
|
|
||||||
repositoryRunnerKey := owner + "/" + repo
|
repositoryRunnerKey := owner + "/" + repo
|
||||||
|
|
||||||
if target, err := autoscaler.getJobScaleTarget(ctx, repositoryRunnerKey, labels); err != nil {
|
// Search for repository HRAs
|
||||||
log.Info("finding repository-wide runner", "repository", repositoryRunnerKey)
|
if target, err := scaleTarget(repositoryRunnerKey); err != nil {
|
||||||
|
log.Error(err, "finding repository-wide runner", "repository", repositoryRunnerKey)
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if target != nil {
|
} else if target != nil {
|
||||||
log.Info("job scale up target is repository-wide runners", "repository", repo)
|
log.Info("job scale up target is repository-wide runners", "repository", repo)
|
||||||
@@ -500,42 +476,180 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getJobScaleUpTargetFo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ownerType == "User" {
|
if ownerType == "User" {
|
||||||
log.V(1).Info("no repository runner found", "organization", owner)
|
log.V(1).Info("user repositories not supported", "owner", owner)
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if target, err := autoscaler.getJobScaleTarget(ctx, owner, labels); err != nil {
|
// Find the potential runner groups first to avoid spending API queries needless. Once/if GitHub improves an
|
||||||
log.Info("finding organizational runner", "organization", owner)
|
// API to find related/linked runner groups from a specific repository this logic could be removed
|
||||||
|
managedRunnerGroups, err := autoscaler.getManagedRunnerGroupsFromHRAs(ctx, enterprise, owner)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err, "finding potential organization/enterprise runner groups from HRAs", "organization", owner)
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if target != nil {
|
|
||||||
log.Info("job scale up target is organizational runners", "organization", owner)
|
|
||||||
return target, nil
|
|
||||||
}
|
}
|
||||||
|
if managedRunnerGroups.IsEmpty() {
|
||||||
if enterprise == "" {
|
|
||||||
log.V(1).Info("no repository runner or organizational runner found",
|
|
||||||
"repository", repositoryRunnerKey,
|
|
||||||
"organization", owner,
|
|
||||||
)
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if target, err := autoscaler.getJobScaleTarget(ctx, enterpriseKey(enterprise), labels); err != nil {
|
|
||||||
log.Error(err, "finding enterprise runner", "enterprise", enterprise)
|
|
||||||
return nil, err
|
|
||||||
} else if target != nil {
|
|
||||||
log.Info("scale up target is enterprise runners", "enterprise", enterprise)
|
|
||||||
return target, nil
|
|
||||||
} else {
|
|
||||||
log.V(1).Info("no repository/organizational/enterprise runner found",
|
log.V(1).Info("no repository/organizational/enterprise runner found",
|
||||||
"repository", repositoryRunnerKey,
|
"repository", repositoryRunnerKey,
|
||||||
"organization", owner,
|
"organization", owner,
|
||||||
"enterprises", enterprise,
|
"enterprises", enterprise,
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
log.V(1).Info("Found some runner groups are managed by ARC", "groups", managedRunnerGroups)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
var visibleGroups *simulator.VisibleRunnerGroups
|
||||||
|
if autoscaler.GitHubClient != nil {
|
||||||
|
simu := &simulator.Simulator{
|
||||||
|
Client: autoscaler.GitHubClient,
|
||||||
|
}
|
||||||
|
// Get available organization runner groups and enterprise runner groups for a repository
|
||||||
|
// These are the sum of runner groups with repository access = All repositories and runner groups
|
||||||
|
// where owner/repo has access to as well. The list will include default runner group also if it has access to
|
||||||
|
visibleGroups, err = simu.GetRunnerGroupsVisibleToRepository(ctx, owner, repositoryRunnerKey, managedRunnerGroups)
|
||||||
|
log.V(1).Info("Searching in runner groups", "groups", visibleGroups)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err, "Unable to find runner groups from repository", "organization", owner, "repository", repo)
|
||||||
|
return nil, fmt.Errorf("error while finding visible runner groups: %v", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For backwards compatibility if GitHub authentication is not configured, we assume all runner groups have
|
||||||
|
// visibility=all to honor the previous implementation, therefore any available enterprise/organization runner
|
||||||
|
// is a potential target for scaling. This will also avoid doing extra API calls caused by
|
||||||
|
// GitHubClient.GetRunnerGroupsVisibleToRepository in case users are not using custom visibility on their runner
|
||||||
|
// groups or they are using only default runner groups
|
||||||
|
visibleGroups = managedRunnerGroups
|
||||||
|
}
|
||||||
|
|
||||||
|
scaleTargetKey := func(rg simulator.RunnerGroup) string {
|
||||||
|
switch rg.Kind {
|
||||||
|
case simulator.Default:
|
||||||
|
switch rg.Scope {
|
||||||
|
case simulator.Organization:
|
||||||
|
return owner
|
||||||
|
case simulator.Enterprise:
|
||||||
|
return enterpriseKey(enterprise)
|
||||||
|
}
|
||||||
|
case simulator.Custom:
|
||||||
|
switch rg.Scope {
|
||||||
|
case simulator.Organization:
|
||||||
|
return organizationalRunnerGroupKey(owner, rg.Name)
|
||||||
|
case simulator.Enterprise:
|
||||||
|
return enterpriseRunnerGroupKey(enterprise, rg.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(1).Info("groups", "groups", visibleGroups)
|
||||||
|
|
||||||
|
var t *ScaleTarget
|
||||||
|
|
||||||
|
traverseErr := visibleGroups.Traverse(func(rg simulator.RunnerGroup) (bool, error) {
|
||||||
|
key := scaleTargetKey(rg)
|
||||||
|
|
||||||
|
target, err := scaleTarget(key)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err, "finding runner group", "enterprise", enterprise, "organization", owner, "repository", repo, "key", key)
|
||||||
|
return false, err
|
||||||
|
} else if target == nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
t = target
|
||||||
|
log.V(1).Info("job scale up target found", "enterprise", enterprise, "organization", owner, "repository", repo, "key", key)
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if traverseErr != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
log.V(1).Info("no repository/organizational/enterprise runner found",
|
||||||
|
"repository", repositoryRunnerKey,
|
||||||
|
"organization", owner,
|
||||||
|
"enterprise", enterprise,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return t, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getManagedRunnerGroupsFromHRAs(ctx context.Context, enterprise, org string) (*simulator.VisibleRunnerGroups, error) {
|
||||||
|
groups := simulator.NewVisibleRunnerGroups()
|
||||||
|
ns := autoscaler.Namespace
|
||||||
|
|
||||||
|
var defaultListOpts []client.ListOption
|
||||||
|
if ns != "" {
|
||||||
|
defaultListOpts = append(defaultListOpts, client.InNamespace(ns))
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := append([]client.ListOption{}, defaultListOpts...)
|
||||||
|
if autoscaler.Namespace != "" {
|
||||||
|
opts = append(opts, client.InNamespace(autoscaler.Namespace))
|
||||||
|
}
|
||||||
|
|
||||||
|
var hraList v1alpha1.HorizontalRunnerAutoscalerList
|
||||||
|
if err := autoscaler.List(ctx, &hraList, opts...); err != nil {
|
||||||
|
return groups, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, hra := range hraList.Items {
|
||||||
|
var o, e, g string
|
||||||
|
|
||||||
|
kind := hra.Spec.ScaleTargetRef.Kind
|
||||||
|
switch kind {
|
||||||
|
case "RunnerSet":
|
||||||
|
var rs v1alpha1.RunnerSet
|
||||||
|
if err := autoscaler.Client.Get(context.Background(), types.NamespacedName{Namespace: hra.Namespace, Name: hra.Spec.ScaleTargetRef.Name}, &rs); err != nil {
|
||||||
|
return groups, err
|
||||||
|
}
|
||||||
|
o, e, g = rs.Spec.Organization, rs.Spec.Enterprise, rs.Spec.Group
|
||||||
|
case "RunnerDeployment", "":
|
||||||
|
var rd v1alpha1.RunnerDeployment
|
||||||
|
if err := autoscaler.Client.Get(context.Background(), types.NamespacedName{Namespace: hra.Namespace, Name: hra.Spec.ScaleTargetRef.Name}, &rd); err != nil {
|
||||||
|
return groups, err
|
||||||
|
}
|
||||||
|
o, e, g = rd.Spec.Template.Spec.Organization, rd.Spec.Template.Spec.Enterprise, rd.Spec.Template.Spec.Group
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported scale target kind: %v", kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
if g != "" && e == "" && o == "" {
|
||||||
|
autoscaler.Log.V(1).Info(
|
||||||
|
"invalid runner group config in scale target: spec.group must be set along with either spec.enterprise or spec.organization",
|
||||||
|
"scaleTargetKind", kind,
|
||||||
|
"group", g,
|
||||||
|
"enterprise", e,
|
||||||
|
"organization", o,
|
||||||
|
)
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if e != enterprise && o != org {
|
||||||
|
autoscaler.Log.V(1).Info(
|
||||||
|
"Skipped scale target irrelevant to event",
|
||||||
|
"eventOrganization", org,
|
||||||
|
"eventEnterprise", enterprise,
|
||||||
|
"scaleTargetKind", kind,
|
||||||
|
"scaleTargetGroup", g,
|
||||||
|
"scaleTargetEnterprise", e,
|
||||||
|
"scaleTargetOrganization", o,
|
||||||
|
)
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
rg := simulator.NewRunnerGroupFromProperties(e, o, g)
|
||||||
|
|
||||||
|
if err := groups.Add(rg); err != nil {
|
||||||
|
return groups, fmt.Errorf("failed adding visible group from HRA %s/%s: %w", hra.Namespace, hra.Name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groups, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getJobScaleTarget(ctx context.Context, name string, labels []string) (*ScaleTarget, error) {
|
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getJobScaleTarget(ctx context.Context, name string, labels []string) (*ScaleTarget, error) {
|
||||||
@@ -554,16 +668,29 @@ HRA:
|
|||||||
|
|
||||||
if len(hra.Spec.ScaleUpTriggers) > 1 {
|
if len(hra.Spec.ScaleUpTriggers) > 1 {
|
||||||
autoscaler.Log.V(1).Info("Skipping this HRA as it has too many ScaleUpTriggers to be used in workflow_job based scaling", "hra", hra.Name)
|
autoscaler.Log.V(1).Info("Skipping this HRA as it has too many ScaleUpTriggers to be used in workflow_job based scaling", "hra", hra.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(hra.Spec.ScaleUpTriggers) == 0 {
|
||||||
|
autoscaler.Log.V(1).Info("Skipping this HRA as it has no ScaleUpTriggers configured", "hra", hra.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
scaleUpTrigger := hra.Spec.ScaleUpTriggers[0]
|
||||||
|
|
||||||
|
if scaleUpTrigger.GitHubEvent == nil {
|
||||||
|
autoscaler.Log.V(1).Info("Skipping this HRA as it has no `githubEvent` scale trigger configured", "hra", hra.Name)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var duration metav1.Duration
|
if scaleUpTrigger.GitHubEvent.WorkflowJob == nil {
|
||||||
|
autoscaler.Log.V(1).Info("Skipping this HRA as it has no `githubEvent.workflowJob` scale trigger configured", "hra", hra.Name)
|
||||||
|
|
||||||
if len(hra.Spec.ScaleUpTriggers) > 0 {
|
continue
|
||||||
duration = hra.Spec.ScaleUpTriggers[0].Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duration := scaleUpTrigger.Duration
|
||||||
if duration.Duration <= 0 {
|
if duration.Duration <= 0 {
|
||||||
// Try to release the reserved capacity after at least 10 minutes by default,
|
// Try to release the reserved capacity after at least 10 minutes by default,
|
||||||
// we won't end up in the reserved capacity remained forever in case GitHub somehow stopped sending us "completed" workflow_job events.
|
// we won't end up in the reserved capacity remained forever in case GitHub somehow stopped sending us "completed" workflow_job events.
|
||||||
@@ -580,13 +707,17 @@ HRA:
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(labels) == 1 && labels[0] == "self-hosted" {
|
|
||||||
return &ScaleTarget{HorizontalRunnerAutoscaler: hra, ScaleUpTrigger: v1alpha1.ScaleUpTrigger{Duration: duration}}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that the RunnerSet-managed runners have all the labels requested by the workflow_job.
|
// Ensure that the RunnerSet-managed runners have all the labels requested by the workflow_job.
|
||||||
for _, l := range labels {
|
for _, l := range labels {
|
||||||
var matched bool
|
var matched bool
|
||||||
|
|
||||||
|
// ignore "self-hosted" label as all instance here are self-hosted
|
||||||
|
if l == "self-hosted" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO labels related to OS and architecture needs to be explicitly declared or the current implementation will not be able to find them.
|
||||||
|
|
||||||
for _, l2 := range rs.Spec.Labels {
|
for _, l2 := range rs.Spec.Labels {
|
||||||
if l == l2 {
|
if l == l2 {
|
||||||
matched = true
|
matched = true
|
||||||
@@ -607,13 +738,17 @@ HRA:
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(labels) == 1 && labels[0] == "self-hosted" {
|
|
||||||
return &ScaleTarget{HorizontalRunnerAutoscaler: hra, ScaleUpTrigger: v1alpha1.ScaleUpTrigger{Duration: duration}}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that the RunnerDeployment-managed runners have all the labels requested by the workflow_job.
|
// Ensure that the RunnerDeployment-managed runners have all the labels requested by the workflow_job.
|
||||||
for _, l := range labels {
|
for _, l := range labels {
|
||||||
var matched bool
|
var matched bool
|
||||||
|
|
||||||
|
// ignore "self-hosted" label as all instance here are self-hosted
|
||||||
|
if l == "self-hosted" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO labels related to OS and architecture needs to be explicitly declared or the current implementation will not be able to find them.
|
||||||
|
|
||||||
for _, l2 := range rd.Spec.Template.Spec.Labels {
|
for _, l2 := range rd.Spec.Template.Spec.Labels {
|
||||||
if l == l2 {
|
if l == l2 {
|
||||||
matched = true
|
matched = true
|
||||||
@@ -651,8 +786,10 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) tryScale(ctx context.
|
|||||||
capacityReservations := getValidCapacityReservations(copy)
|
capacityReservations := getValidCapacityReservations(copy)
|
||||||
|
|
||||||
if amount > 0 {
|
if amount > 0 {
|
||||||
|
now := time.Now()
|
||||||
copy.Spec.CapacityReservations = append(capacityReservations, v1alpha1.CapacityReservation{
|
copy.Spec.CapacityReservations = append(capacityReservations, v1alpha1.CapacityReservation{
|
||||||
ExpirationTime: metav1.Time{Time: time.Now().Add(target.ScaleUpTrigger.Duration.Duration)},
|
EffectiveTime: metav1.Time{Time: now},
|
||||||
|
ExpirationTime: metav1.Time{Time: now.Add(target.ScaleUpTrigger.Duration.Duration)},
|
||||||
Replicas: amount,
|
Replicas: amount,
|
||||||
})
|
})
|
||||||
} else if amount < 0 {
|
} else if amount < 0 {
|
||||||
@@ -671,10 +808,16 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) tryScale(ctx context.
|
|||||||
copy.Spec.CapacityReservations = reservations
|
copy.Spec.CapacityReservations = reservations
|
||||||
}
|
}
|
||||||
|
|
||||||
autoscaler.Log.Info(
|
before := len(target.HorizontalRunnerAutoscaler.Spec.CapacityReservations)
|
||||||
"Patching hra for capacityReservations update",
|
expired := before - len(capacityReservations)
|
||||||
"before", target.HorizontalRunnerAutoscaler.Spec.CapacityReservations,
|
after := len(copy.Spec.CapacityReservations)
|
||||||
"after", copy.Spec.CapacityReservations,
|
|
||||||
|
autoscaler.Log.V(1).Info(
|
||||||
|
fmt.Sprintf("Patching hra %s for capacityReservations update", target.HorizontalRunnerAutoscaler.Name),
|
||||||
|
"before", before,
|
||||||
|
"expired", expired,
|
||||||
|
"amount", amount,
|
||||||
|
"after", after,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := autoscaler.Client.Patch(ctx, copy, client.MergeFrom(&target.HorizontalRunnerAutoscaler)); err != nil {
|
if err := autoscaler.Client.Patch(ctx, copy, client.MergeFrom(&target.HorizontalRunnerAutoscaler)); err != nil {
|
||||||
@@ -710,37 +853,62 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) SetupWithManager(mgr
|
|||||||
hra := rawObj.(*v1alpha1.HorizontalRunnerAutoscaler)
|
hra := rawObj.(*v1alpha1.HorizontalRunnerAutoscaler)
|
||||||
|
|
||||||
if hra.Spec.ScaleTargetRef.Name == "" {
|
if hra.Spec.ScaleTargetRef.Name == "" {
|
||||||
|
autoscaler.Log.V(1).Info(fmt.Sprintf("scale target ref name not set for hra %s", hra.Name))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
switch hra.Spec.ScaleTargetRef.Kind {
|
switch hra.Spec.ScaleTargetRef.Kind {
|
||||||
case "", "RunnerDeployment":
|
case "", "RunnerDeployment":
|
||||||
var rd v1alpha1.RunnerDeployment
|
var rd v1alpha1.RunnerDeployment
|
||||||
|
|
||||||
if err := autoscaler.Client.Get(context.Background(), types.NamespacedName{Namespace: hra.Namespace, Name: hra.Spec.ScaleTargetRef.Name}, &rd); err != nil {
|
if err := autoscaler.Client.Get(context.Background(), types.NamespacedName{Namespace: hra.Namespace, Name: hra.Spec.ScaleTargetRef.Name}, &rd); err != nil {
|
||||||
|
autoscaler.Log.V(1).Info(fmt.Sprintf("RunnerDeployment not found with scale target ref name %s for hra %s", hra.Spec.ScaleTargetRef.Name, hra.Name))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := []string{rd.Spec.Template.Spec.Repository, rd.Spec.Template.Spec.Organization}
|
keys := []string{}
|
||||||
|
if rd.Spec.Template.Spec.Repository != "" {
|
||||||
if enterprise := rd.Spec.Template.Spec.Enterprise; enterprise != "" {
|
keys = append(keys, rd.Spec.Template.Spec.Repository) // Repository runners
|
||||||
keys = append(keys, enterpriseKey(enterprise))
|
|
||||||
}
|
}
|
||||||
|
if rd.Spec.Template.Spec.Organization != "" {
|
||||||
|
if group := rd.Spec.Template.Spec.Group; group != "" {
|
||||||
|
keys = append(keys, organizationalRunnerGroupKey(rd.Spec.Template.Spec.Organization, rd.Spec.Template.Spec.Group)) // Organization runner groups
|
||||||
|
} else {
|
||||||
|
keys = append(keys, rd.Spec.Template.Spec.Organization) // Organization runners
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if enterprise := rd.Spec.Template.Spec.Enterprise; enterprise != "" {
|
||||||
|
if group := rd.Spec.Template.Spec.Group; group != "" {
|
||||||
|
keys = append(keys, enterpriseRunnerGroupKey(enterprise, rd.Spec.Template.Spec.Group)) // Enterprise runner groups
|
||||||
|
} else {
|
||||||
|
keys = append(keys, enterpriseKey(enterprise)) // Enterprise runners
|
||||||
|
}
|
||||||
|
}
|
||||||
|
autoscaler.Log.V(2).Info(fmt.Sprintf("HRA keys indexed for HRA %s: %v", hra.Name, keys))
|
||||||
return keys
|
return keys
|
||||||
case "RunnerSet":
|
case "RunnerSet":
|
||||||
var rs v1alpha1.RunnerSet
|
var rs v1alpha1.RunnerSet
|
||||||
|
|
||||||
if err := autoscaler.Client.Get(context.Background(), types.NamespacedName{Namespace: hra.Namespace, Name: hra.Spec.ScaleTargetRef.Name}, &rs); err != nil {
|
if err := autoscaler.Client.Get(context.Background(), types.NamespacedName{Namespace: hra.Namespace, Name: hra.Spec.ScaleTargetRef.Name}, &rs); err != nil {
|
||||||
|
autoscaler.Log.V(1).Info(fmt.Sprintf("RunnerSet not found with scale target ref name %s for hra %s", hra.Spec.ScaleTargetRef.Name, hra.Name))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := []string{rs.Spec.Repository, rs.Spec.Organization}
|
keys := []string{}
|
||||||
|
if rs.Spec.Repository != "" {
|
||||||
if enterprise := rs.Spec.Enterprise; enterprise != "" {
|
keys = append(keys, rs.Spec.Repository) // Repository runners
|
||||||
keys = append(keys, enterpriseKey(enterprise))
|
|
||||||
}
|
}
|
||||||
|
if rs.Spec.Organization != "" {
|
||||||
|
keys = append(keys, rs.Spec.Organization) // Organization runners
|
||||||
|
if group := rs.Spec.Group; group != "" {
|
||||||
|
keys = append(keys, organizationalRunnerGroupKey(rs.Spec.Organization, rs.Spec.Group)) // Organization runner groups
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if enterprise := rs.Spec.Enterprise; enterprise != "" {
|
||||||
|
keys = append(keys, enterpriseKey(enterprise)) // Enterprise runners
|
||||||
|
if group := rs.Spec.Group; group != "" {
|
||||||
|
keys = append(keys, enterpriseRunnerGroupKey(enterprise, rs.Spec.Group)) // Enterprise runner groups
|
||||||
|
}
|
||||||
|
}
|
||||||
|
autoscaler.Log.V(2).Info(fmt.Sprintf("HRA keys indexed for HRA %s: %v", hra.Name, keys))
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -758,3 +926,11 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) SetupWithManager(mgr
|
|||||||
func enterpriseKey(name string) string {
|
func enterpriseKey(name string) string {
|
||||||
return keyPrefixEnterprise + name
|
return keyPrefixEnterprise + name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func organizationalRunnerGroupKey(owner, group string) string {
|
||||||
|
return owner + keyRunnerGroup + group
|
||||||
|
}
|
||||||
|
|
||||||
|
func enterpriseRunnerGroupKey(enterprise, group string) string {
|
||||||
|
return keyPrefixEnterprise + enterprise + keyRunnerGroup + group
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/pkg/actionsglob"
|
"github.com/actions-runner-controller/actions-runner-controller/pkg/actionsglob"
|
||||||
"github.com/google/go-github/v37/github"
|
"github.com/google/go-github/v39/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) MatchCheckRunEvent(event *github.CheckRunEvent) func(scaleUpTrigger v1alpha1.ScaleUpTrigger) bool {
|
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) MatchCheckRunEvent(event *github.CheckRunEvent) func(scaleUpTrigger v1alpha1.ScaleUpTrigger) bool {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
||||||
"github.com/google/go-github/v37/github"
|
"github.com/google/go-github/v39/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) MatchPullRequestEvent(event *github.PullRequestEvent) func(scaleUpTrigger v1alpha1.ScaleUpTrigger) bool {
|
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) MatchPullRequestEvent(event *github.PullRequestEvent) func(scaleUpTrigger v1alpha1.ScaleUpTrigger) bool {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
||||||
"github.com/google/go-github/v37/github"
|
"github.com/google/go-github/v39/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) MatchPushEvent(event *github.PushEvent) func(scaleUpTrigger v1alpha1.ScaleUpTrigger) bool {
|
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) MatchPushEvent(event *github.PushEvent) func(scaleUpTrigger v1alpha1.ScaleUpTrigger) bool {
|
||||||
@@ -15,10 +15,6 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) MatchPushEvent(event
|
|||||||
|
|
||||||
push := g.Push
|
push := g.Push
|
||||||
|
|
||||||
if push == nil {
|
return push != nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
actionsv1alpha1 "github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
actionsv1alpha1 "github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
"github.com/google/go-github/v37/github"
|
"github.com/google/go-github/v39/github"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||||
@@ -138,6 +138,13 @@ func TestWebhookWorkflowJob(t *testing.T) {
|
|||||||
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
||||||
Name: "test-name",
|
Name: "test-name",
|
||||||
},
|
},
|
||||||
|
ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{
|
||||||
|
{
|
||||||
|
GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{
|
||||||
|
WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +184,13 @@ func TestWebhookWorkflowJob(t *testing.T) {
|
|||||||
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
||||||
Name: "test-name",
|
Name: "test-name",
|
||||||
},
|
},
|
||||||
|
ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{
|
||||||
|
{
|
||||||
|
GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{
|
||||||
|
WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,6 +231,173 @@ func TestWebhookWorkflowJob(t *testing.T) {
|
|||||||
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
||||||
Name: "test-name",
|
Name: "test-name",
|
||||||
},
|
},
|
||||||
|
ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{
|
||||||
|
{
|
||||||
|
GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{
|
||||||
|
WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
rd := &actionsv1alpha1.RunnerDeployment{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test-name",
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerDeploymentSpec{
|
||||||
|
Template: actionsv1alpha1.RunnerTemplate{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"label1": "label1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerSpec{
|
||||||
|
RunnerConfig: actionsv1alpha1.RunnerConfig{
|
||||||
|
Organization: "MYORG",
|
||||||
|
Labels: []string{"bad-label"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
initObjs := []runtime.Object{hra, rd}
|
||||||
|
|
||||||
|
testServerWithInitObjs(t,
|
||||||
|
"workflow_job",
|
||||||
|
&e,
|
||||||
|
200,
|
||||||
|
"no horizontalrunnerautoscaler to scale for this github event",
|
||||||
|
initObjs,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWebhookWorkflowJobWithSelfHostedLabel(t *testing.T) {
|
||||||
|
setupTest := func() github.WorkflowJobEvent {
|
||||||
|
f, err := os.Open("testdata/org_webhook_workflow_job_with_self_hosted_label_payload.json")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not open the fixture: %s", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
var e github.WorkflowJobEvent
|
||||||
|
if err := json.NewDecoder(f).Decode(&e); err != nil {
|
||||||
|
t.Fatalf("invalid json: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
t.Run("Successful", func(t *testing.T) {
|
||||||
|
e := setupTest()
|
||||||
|
hra := &actionsv1alpha1.HorizontalRunnerAutoscaler{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test-name",
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.HorizontalRunnerAutoscalerSpec{
|
||||||
|
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
||||||
|
Name: "test-name",
|
||||||
|
},
|
||||||
|
ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{
|
||||||
|
{
|
||||||
|
GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{
|
||||||
|
WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
rd := &actionsv1alpha1.RunnerDeployment{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test-name",
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerDeploymentSpec{
|
||||||
|
Template: actionsv1alpha1.RunnerTemplate{
|
||||||
|
Spec: actionsv1alpha1.RunnerSpec{
|
||||||
|
RunnerConfig: actionsv1alpha1.RunnerConfig{
|
||||||
|
Organization: "MYORG",
|
||||||
|
Labels: []string{"label1"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
initObjs := []runtime.Object{hra, rd}
|
||||||
|
|
||||||
|
testServerWithInitObjs(t,
|
||||||
|
"workflow_job",
|
||||||
|
&e,
|
||||||
|
200,
|
||||||
|
"scaled test-name by 1",
|
||||||
|
initObjs,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
t.Run("WrongLabels", func(t *testing.T) {
|
||||||
|
e := setupTest()
|
||||||
|
hra := &actionsv1alpha1.HorizontalRunnerAutoscaler{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test-name",
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.HorizontalRunnerAutoscalerSpec{
|
||||||
|
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
||||||
|
Name: "test-name",
|
||||||
|
},
|
||||||
|
ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{
|
||||||
|
{
|
||||||
|
GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{
|
||||||
|
WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
rd := &actionsv1alpha1.RunnerDeployment{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test-name",
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerDeploymentSpec{
|
||||||
|
Template: actionsv1alpha1.RunnerTemplate{
|
||||||
|
Spec: actionsv1alpha1.RunnerSpec{
|
||||||
|
RunnerConfig: actionsv1alpha1.RunnerConfig{
|
||||||
|
Organization: "MYORG",
|
||||||
|
Labels: []string{"bad-label"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
initObjs := []runtime.Object{hra, rd}
|
||||||
|
|
||||||
|
testServerWithInitObjs(t,
|
||||||
|
"workflow_job",
|
||||||
|
&e,
|
||||||
|
200,
|
||||||
|
"no horizontalrunnerautoscaler to scale for this github event",
|
||||||
|
initObjs,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
// This test verifies that the old way of matching labels doesn't work anymore
|
||||||
|
t.Run("OldLabels", func(t *testing.T) {
|
||||||
|
e := setupTest()
|
||||||
|
hra := &actionsv1alpha1.HorizontalRunnerAutoscaler{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test-name",
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.HorizontalRunnerAutoscalerSpec{
|
||||||
|
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
||||||
|
Name: "test-name",
|
||||||
|
},
|
||||||
|
ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{
|
||||||
|
{
|
||||||
|
GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{
|
||||||
|
WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,12 +487,14 @@ func TestGetValidCapacityReservations(t *testing.T) {
|
|||||||
func installTestLogger(webhook *HorizontalRunnerAutoscalerGitHubWebhook) *bytes.Buffer {
|
func installTestLogger(webhook *HorizontalRunnerAutoscalerGitHubWebhook) *bytes.Buffer {
|
||||||
logs := &bytes.Buffer{}
|
logs := &bytes.Buffer{}
|
||||||
|
|
||||||
log := testLogger{
|
sink := &testLogSink{
|
||||||
name: "testlog",
|
name: "testlog",
|
||||||
writer: logs,
|
writer: logs,
|
||||||
}
|
}
|
||||||
|
|
||||||
webhook.Log = &log
|
log := logr.New(sink)
|
||||||
|
|
||||||
|
webhook.Log = log
|
||||||
|
|
||||||
return logs
|
return logs
|
||||||
}
|
}
|
||||||
@@ -398,18 +581,22 @@ func sendWebhook(server *httptest.Server, eventType string, event interface{}) (
|
|||||||
return http.DefaultClient.Do(req)
|
return http.DefaultClient.Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// testLogger is a sample logr.Logger that logs in-memory.
|
// testLogSink is a sample logr.Logger that logs in-memory.
|
||||||
// It's only for testing log outputs.
|
// It's only for testing log outputs.
|
||||||
type testLogger struct {
|
type testLogSink struct {
|
||||||
name string
|
name string
|
||||||
keyValues map[string]interface{}
|
keyValues map[string]interface{}
|
||||||
|
|
||||||
writer io.Writer
|
writer io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ logr.Logger = &testLogger{}
|
var _ logr.LogSink = &testLogSink{}
|
||||||
|
|
||||||
func (l *testLogger) Info(msg string, kvs ...interface{}) {
|
func (l *testLogSink) Init(_ logr.RuntimeInfo) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *testLogSink) Info(_ int, msg string, kvs ...interface{}) {
|
||||||
fmt.Fprintf(l.writer, "%s] %s\t", l.name, msg)
|
fmt.Fprintf(l.writer, "%s] %s\t", l.name, msg)
|
||||||
for k, v := range l.keyValues {
|
for k, v := range l.keyValues {
|
||||||
fmt.Fprintf(l.writer, "%s=%+v ", k, v)
|
fmt.Fprintf(l.writer, "%s=%+v ", k, v)
|
||||||
@@ -420,28 +607,24 @@ func (l *testLogger) Info(msg string, kvs ...interface{}) {
|
|||||||
fmt.Fprintf(l.writer, "\n")
|
fmt.Fprintf(l.writer, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *testLogger) Enabled() bool {
|
func (_ *testLogSink) Enabled(level int) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *testLogger) Error(err error, msg string, kvs ...interface{}) {
|
func (l *testLogSink) Error(err error, msg string, kvs ...interface{}) {
|
||||||
kvs = append(kvs, "error", err)
|
kvs = append(kvs, "error", err)
|
||||||
l.Info(msg, kvs...)
|
l.Info(0, msg, kvs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *testLogger) V(_ int) logr.InfoLogger {
|
func (l *testLogSink) WithName(name string) logr.LogSink {
|
||||||
return l
|
return &testLogSink{
|
||||||
}
|
|
||||||
|
|
||||||
func (l *testLogger) WithName(name string) logr.Logger {
|
|
||||||
return &testLogger{
|
|
||||||
name: l.name + "." + name,
|
name: l.name + "." + name,
|
||||||
keyValues: l.keyValues,
|
keyValues: l.keyValues,
|
||||||
writer: l.writer,
|
writer: l.writer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *testLogger) WithValues(kvs ...interface{}) logr.Logger {
|
func (l *testLogSink) WithValues(kvs ...interface{}) logr.LogSink {
|
||||||
newMap := make(map[string]interface{}, len(l.keyValues)+len(kvs)/2)
|
newMap := make(map[string]interface{}, len(l.keyValues)+len(kvs)/2)
|
||||||
for k, v := range l.keyValues {
|
for k, v := range l.keyValues {
|
||||||
newMap[k] = v
|
newMap[k] = v
|
||||||
@@ -449,7 +632,7 @@ func (l *testLogger) WithValues(kvs ...interface{}) logr.Logger {
|
|||||||
for i := 0; i < len(kvs); i += 2 {
|
for i := 0; i < len(kvs); i += 2 {
|
||||||
newMap[kvs[i].(string)] = kvs[i+1]
|
newMap[kvs[i].(string)] = kvs[i+1]
|
||||||
}
|
}
|
||||||
return &testLogger{
|
return &testLogSink{
|
||||||
name: l.name,
|
name: l.name,
|
||||||
keyValues: newMap,
|
keyValues: newMap,
|
||||||
writer: l.writer,
|
writer: l.writer,
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ import (
|
|||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/github"
|
"github.com/actions-runner-controller/actions-runner-controller/github"
|
||||||
|
"github.com/go-logr/logr"
|
||||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
|
||||||
"github.com/go-logr/logr"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
@@ -47,13 +47,13 @@ const (
|
|||||||
// HorizontalRunnerAutoscalerReconciler reconciles a HorizontalRunnerAutoscaler object
|
// HorizontalRunnerAutoscalerReconciler reconciles a HorizontalRunnerAutoscaler object
|
||||||
type HorizontalRunnerAutoscalerReconciler struct {
|
type HorizontalRunnerAutoscalerReconciler struct {
|
||||||
client.Client
|
client.Client
|
||||||
GitHubClient *github.Client
|
GitHubClient *github.Client
|
||||||
Log logr.Logger
|
Log logr.Logger
|
||||||
Recorder record.EventRecorder
|
Recorder record.EventRecorder
|
||||||
Scheme *runtime.Scheme
|
Scheme *runtime.Scheme
|
||||||
|
CacheDuration time.Duration
|
||||||
CacheDuration time.Duration
|
DefaultScaleDownDelay time.Duration
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultReplicas = 1
|
const defaultReplicas = 1
|
||||||
@@ -99,11 +99,33 @@ func (r *HorizontalRunnerAutoscalerReconciler) Reconcile(ctx context.Context, re
|
|||||||
return r.reconcile(ctx, req, log, hra, st, func(newDesiredReplicas int) error {
|
return r.reconcile(ctx, req, log, hra, st, func(newDesiredReplicas int) error {
|
||||||
currentDesiredReplicas := getIntOrDefault(rd.Spec.Replicas, defaultReplicas)
|
currentDesiredReplicas := getIntOrDefault(rd.Spec.Replicas, defaultReplicas)
|
||||||
|
|
||||||
|
ephemeral := rd.Spec.Template.Spec.Ephemeral == nil || *rd.Spec.Template.Spec.Ephemeral
|
||||||
|
|
||||||
|
var effectiveTime *time.Time
|
||||||
|
|
||||||
|
for _, r := range hra.Spec.CapacityReservations {
|
||||||
|
t := r.EffectiveTime
|
||||||
|
if effectiveTime == nil || effectiveTime.Before(t.Time) {
|
||||||
|
effectiveTime = &t.Time
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Please add more conditions that we can in-place update the newest runnerreplicaset without disruption
|
// Please add more conditions that we can in-place update the newest runnerreplicaset without disruption
|
||||||
if currentDesiredReplicas != newDesiredReplicas {
|
if currentDesiredReplicas != newDesiredReplicas {
|
||||||
copy := rd.DeepCopy()
|
copy := rd.DeepCopy()
|
||||||
copy.Spec.Replicas = &newDesiredReplicas
|
copy.Spec.Replicas = &newDesiredReplicas
|
||||||
|
|
||||||
|
if ephemeral && effectiveTime != nil {
|
||||||
|
copy.Spec.EffectiveTime = &metav1.Time{Time: *effectiveTime}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.Client.Patch(ctx, copy, client.MergeFrom(&rd)); err != nil {
|
||||||
|
return fmt.Errorf("patching runnerdeployment to have %d replicas: %w", newDesiredReplicas, err)
|
||||||
|
}
|
||||||
|
} else if ephemeral && effectiveTime != nil {
|
||||||
|
copy := rd.DeepCopy()
|
||||||
|
copy.Spec.EffectiveTime = &metav1.Time{Time: *effectiveTime}
|
||||||
|
|
||||||
if err := r.Client.Patch(ctx, copy, client.MergeFrom(&rd)); err != nil {
|
if err := r.Client.Patch(ctx, copy, client.MergeFrom(&rd)); err != nil {
|
||||||
return fmt.Errorf("patching runnerdeployment to have %d replicas: %w", newDesiredReplicas, err)
|
return fmt.Errorf("patching runnerdeployment to have %d replicas: %w", newDesiredReplicas, err)
|
||||||
}
|
}
|
||||||
@@ -137,6 +159,7 @@ func (r *HorizontalRunnerAutoscalerReconciler) Reconcile(ctx context.Context, re
|
|||||||
org: rs.Spec.Organization,
|
org: rs.Spec.Organization,
|
||||||
repo: rs.Spec.Repository,
|
repo: rs.Spec.Repository,
|
||||||
replicas: replicas,
|
replicas: replicas,
|
||||||
|
labels: rs.Spec.RunnerConfig.Labels,
|
||||||
getRunnerMap: func() (map[string]struct{}, error) {
|
getRunnerMap: func() (map[string]struct{}, error) {
|
||||||
// return the list of runners in namespace. Horizontal Runner Autoscaler should only be responsible for scaling resources in its own ns.
|
// return the list of runners in namespace. Horizontal Runner Autoscaler should only be responsible for scaling resources in its own ns.
|
||||||
var runnerPodList corev1.PodList
|
var runnerPodList corev1.PodList
|
||||||
@@ -180,15 +203,38 @@ func (r *HorizontalRunnerAutoscalerReconciler) Reconcile(ctx context.Context, re
|
|||||||
}
|
}
|
||||||
currentDesiredReplicas := getIntOrDefault(replicas, defaultReplicas)
|
currentDesiredReplicas := getIntOrDefault(replicas, defaultReplicas)
|
||||||
|
|
||||||
|
ephemeral := rs.Spec.Ephemeral == nil || *rs.Spec.Ephemeral
|
||||||
|
|
||||||
|
var effectiveTime *time.Time
|
||||||
|
|
||||||
|
for _, r := range hra.Spec.CapacityReservations {
|
||||||
|
t := r.EffectiveTime
|
||||||
|
if effectiveTime == nil || effectiveTime.Before(t.Time) {
|
||||||
|
effectiveTime = &t.Time
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if currentDesiredReplicas != newDesiredReplicas {
|
if currentDesiredReplicas != newDesiredReplicas {
|
||||||
copy := rs.DeepCopy()
|
copy := rs.DeepCopy()
|
||||||
v := int32(newDesiredReplicas)
|
v := int32(newDesiredReplicas)
|
||||||
copy.Spec.Replicas = &v
|
copy.Spec.Replicas = &v
|
||||||
|
|
||||||
|
if ephemeral && effectiveTime != nil {
|
||||||
|
copy.Spec.EffectiveTime = &metav1.Time{Time: *effectiveTime}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.Client.Patch(ctx, copy, client.MergeFrom(&rs)); err != nil {
|
||||||
|
return fmt.Errorf("patching runnerset to have %d replicas: %w", newDesiredReplicas, err)
|
||||||
|
}
|
||||||
|
} else if ephemeral && effectiveTime != nil {
|
||||||
|
copy := rs.DeepCopy()
|
||||||
|
copy.Spec.EffectiveTime = &metav1.Time{Time: *effectiveTime}
|
||||||
|
|
||||||
if err := r.Client.Patch(ctx, copy, client.MergeFrom(&rs)); err != nil {
|
if err := r.Client.Patch(ctx, copy, client.MergeFrom(&rs)); err != nil {
|
||||||
return fmt.Errorf("patching runnerset to have %d replicas: %w", newDesiredReplicas, err)
|
return fmt.Errorf("patching runnerset to have %d replicas: %w", newDesiredReplicas, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -206,6 +252,7 @@ func (r *HorizontalRunnerAutoscalerReconciler) scaleTargetFromRD(ctx context.Con
|
|||||||
org: rd.Spec.Template.Spec.Organization,
|
org: rd.Spec.Template.Spec.Organization,
|
||||||
repo: rd.Spec.Template.Spec.Repository,
|
repo: rd.Spec.Template.Spec.Repository,
|
||||||
replicas: rd.Spec.Replicas,
|
replicas: rd.Spec.Replicas,
|
||||||
|
labels: rd.Spec.Template.Spec.RunnerConfig.Labels,
|
||||||
getRunnerMap: func() (map[string]struct{}, error) {
|
getRunnerMap: func() (map[string]struct{}, error) {
|
||||||
// return the list of runners in namespace. Horizontal Runner Autoscaler should only be responsible for scaling resources in its own ns.
|
// return the list of runners in namespace. Horizontal Runner Autoscaler should only be responsible for scaling resources in its own ns.
|
||||||
var runnerList v1alpha1.RunnerList
|
var runnerList v1alpha1.RunnerList
|
||||||
@@ -248,6 +295,7 @@ type scaleTarget struct {
|
|||||||
st, kind string
|
st, kind string
|
||||||
enterprise, repo, org string
|
enterprise, repo, org string
|
||||||
replicas *int
|
replicas *int
|
||||||
|
labels []string
|
||||||
|
|
||||||
getRunnerMap func() (map[string]struct{}, error)
|
getRunnerMap func() (map[string]struct{}, error)
|
||||||
}
|
}
|
||||||
@@ -262,7 +310,7 @@ func (r *HorizontalRunnerAutoscalerReconciler) reconcile(ctx context.Context, re
|
|||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
newDesiredReplicas, computedReplicas, computedReplicasFromCache, err := r.computeReplicasWithCache(log, now, st, hra, minReplicas)
|
newDesiredReplicas, err := r.computeReplicasWithCache(log, now, st, hra, minReplicas)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Recorder.Event(&hra, corev1.EventTypeNormal, "RunnerAutoscalingFailure", err.Error())
|
r.Recorder.Event(&hra, corev1.EventTypeNormal, "RunnerAutoscalingFailure", err.Error())
|
||||||
|
|
||||||
@@ -287,24 +335,6 @@ func (r *HorizontalRunnerAutoscalerReconciler) reconcile(ctx context.Context, re
|
|||||||
updated.Status.DesiredReplicas = &newDesiredReplicas
|
updated.Status.DesiredReplicas = &newDesiredReplicas
|
||||||
}
|
}
|
||||||
|
|
||||||
if computedReplicasFromCache == nil {
|
|
||||||
cacheEntries := getValidCacheEntries(updated, now)
|
|
||||||
|
|
||||||
var cacheDuration time.Duration
|
|
||||||
|
|
||||||
if r.CacheDuration > 0 {
|
|
||||||
cacheDuration = r.CacheDuration
|
|
||||||
} else {
|
|
||||||
cacheDuration = 10 * time.Minute
|
|
||||||
}
|
|
||||||
|
|
||||||
updated.Status.CacheEntries = append(cacheEntries, v1alpha1.CacheEntry{
|
|
||||||
Key: v1alpha1.CacheEntryKeyDesiredReplicas,
|
|
||||||
Value: computedReplicas,
|
|
||||||
ExpirationTime: metav1.Time{Time: time.Now().Add(cacheDuration)},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
var overridesSummary string
|
var overridesSummary string
|
||||||
|
|
||||||
if (active != nil && upcoming == nil) || (active != nil && upcoming != nil && active.Period.EndTime.Before(upcoming.Period.StartTime)) {
|
if (active != nil && upcoming == nil) || (active != nil && upcoming != nil && active.Period.EndTime.Before(upcoming.Period.StartTime)) {
|
||||||
@@ -339,18 +369,6 @@ func (r *HorizontalRunnerAutoscalerReconciler) reconcile(ctx context.Context, re
|
|||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getValidCacheEntries(hra *v1alpha1.HorizontalRunnerAutoscaler, now time.Time) []v1alpha1.CacheEntry {
|
|
||||||
var cacheEntries []v1alpha1.CacheEntry
|
|
||||||
|
|
||||||
for _, ent := range hra.Status.CacheEntries {
|
|
||||||
if ent.ExpirationTime.After(now) {
|
|
||||||
cacheEntries = append(cacheEntries, ent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return cacheEntries
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *HorizontalRunnerAutoscalerReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
func (r *HorizontalRunnerAutoscalerReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
name := "horizontalrunnerautoscaler-controller"
|
name := "horizontalrunnerautoscaler-controller"
|
||||||
if r.Name != "" {
|
if r.Name != "" {
|
||||||
@@ -443,32 +461,18 @@ func (r *HorizontalRunnerAutoscalerReconciler) getMinReplicas(log logr.Logger, n
|
|||||||
return minReplicas, active, upcoming, nil
|
return minReplicas, active, upcoming, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HorizontalRunnerAutoscalerReconciler) computeReplicasWithCache(log logr.Logger, now time.Time, st scaleTarget, hra v1alpha1.HorizontalRunnerAutoscaler, minReplicas int) (int, int, *int, error) {
|
func (r *HorizontalRunnerAutoscalerReconciler) computeReplicasWithCache(log logr.Logger, now time.Time, st scaleTarget, hra v1alpha1.HorizontalRunnerAutoscaler, minReplicas int) (int, error) {
|
||||||
var suggestedReplicas int
|
var suggestedReplicas int
|
||||||
|
|
||||||
suggestedReplicasFromCache := r.fetchSuggestedReplicasFromCache(hra)
|
v, err := r.suggestDesiredReplicas(st, hra)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
var cached *int
|
if v == nil {
|
||||||
|
suggestedReplicas = minReplicas
|
||||||
if suggestedReplicasFromCache != nil {
|
|
||||||
cached = suggestedReplicasFromCache
|
|
||||||
|
|
||||||
if cached == nil {
|
|
||||||
suggestedReplicas = minReplicas
|
|
||||||
} else {
|
|
||||||
suggestedReplicas = *cached
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
v, err := r.suggestDesiredReplicas(st, hra)
|
suggestedReplicas = *v
|
||||||
if err != nil {
|
|
||||||
return 0, 0, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if v == nil {
|
|
||||||
suggestedReplicas = minReplicas
|
|
||||||
} else {
|
|
||||||
suggestedReplicas = *v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var reserved int
|
var reserved int
|
||||||
@@ -496,7 +500,7 @@ func (r *HorizontalRunnerAutoscalerReconciler) computeReplicasWithCache(log logr
|
|||||||
if hra.Spec.ScaleDownDelaySecondsAfterScaleUp != nil {
|
if hra.Spec.ScaleDownDelaySecondsAfterScaleUp != nil {
|
||||||
scaleDownDelay = time.Duration(*hra.Spec.ScaleDownDelaySecondsAfterScaleUp) * time.Second
|
scaleDownDelay = time.Duration(*hra.Spec.ScaleDownDelaySecondsAfterScaleUp) * time.Second
|
||||||
} else {
|
} else {
|
||||||
scaleDownDelay = DefaultScaleDownDelay
|
scaleDownDelay = r.DefaultScaleDownDelay
|
||||||
}
|
}
|
||||||
|
|
||||||
var scaleDownDelayUntil *time.Time
|
var scaleDownDelayUntil *time.Time
|
||||||
@@ -527,8 +531,8 @@ func (r *HorizontalRunnerAutoscalerReconciler) computeReplicasWithCache(log logr
|
|||||||
"min", minReplicas,
|
"min", minReplicas,
|
||||||
}
|
}
|
||||||
|
|
||||||
if cached != nil {
|
if maxReplicas := hra.Spec.MaxReplicas; maxReplicas != nil {
|
||||||
kvs = append(kvs, "cached", *cached)
|
kvs = append(kvs, "max", *maxReplicas)
|
||||||
}
|
}
|
||||||
|
|
||||||
if scaleDownDelayUntil != nil {
|
if scaleDownDelayUntil != nil {
|
||||||
@@ -536,13 +540,9 @@ func (r *HorizontalRunnerAutoscalerReconciler) computeReplicasWithCache(log logr
|
|||||||
kvs = append(kvs, "scale_down_delay_until", scaleDownDelayUntil)
|
kvs = append(kvs, "scale_down_delay_until", scaleDownDelayUntil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if maxReplicas := hra.Spec.MaxReplicas; maxReplicas != nil {
|
|
||||||
kvs = append(kvs, "max", *maxReplicas)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.V(1).Info(fmt.Sprintf("Calculated desired replicas of %d", newDesiredReplicas),
|
log.V(1).Info(fmt.Sprintf("Calculated desired replicas of %d", newDesiredReplicas),
|
||||||
kvs...,
|
kvs...,
|
||||||
)
|
)
|
||||||
|
|
||||||
return newDesiredReplicas, suggestedReplicas, suggestedReplicasFromCache, nil
|
return newDesiredReplicas, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
package controllers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
actionsv1alpha1 "github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
|
||||||
"github.com/google/go-cmp/cmp"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestGetValidCacheEntries(t *testing.T) {
|
|
||||||
now := time.Now()
|
|
||||||
|
|
||||||
hra := &actionsv1alpha1.HorizontalRunnerAutoscaler{
|
|
||||||
Status: actionsv1alpha1.HorizontalRunnerAutoscalerStatus{
|
|
||||||
CacheEntries: []actionsv1alpha1.CacheEntry{
|
|
||||||
{
|
|
||||||
Key: "foo",
|
|
||||||
Value: 1,
|
|
||||||
ExpirationTime: metav1.Time{Time: now.Add(-time.Second)},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "foo",
|
|
||||||
Value: 2,
|
|
||||||
ExpirationTime: metav1.Time{Time: now},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "foo",
|
|
||||||
Value: 3,
|
|
||||||
ExpirationTime: metav1.Time{Time: now.Add(time.Second)},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
revs := getValidCacheEntries(hra, now)
|
|
||||||
|
|
||||||
counts := map[string]int{}
|
|
||||||
|
|
||||||
for _, r := range revs {
|
|
||||||
counts[r.Key] += r.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
want := map[string]int{"foo": 3}
|
|
||||||
|
|
||||||
if d := cmp.Diff(want, counts); d != "" {
|
|
||||||
t.Errorf("%s", d)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
github2 "github.com/actions-runner-controller/actions-runner-controller/github"
|
github2 "github.com/actions-runner-controller/actions-runner-controller/github"
|
||||||
"github.com/google/go-github/v37/github"
|
"github.com/google/go-github/v39/github"
|
||||||
|
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/github/fake"
|
"github.com/actions-runner-controller/actions-runner-controller/github/fake"
|
||||||
|
|
||||||
@@ -108,8 +108,9 @@ func SetupIntegrationTest(ctx2 context.Context) *testEnvironment {
|
|||||||
RunnerImage: "example/runner:test",
|
RunnerImage: "example/runner:test",
|
||||||
DockerImage: "example/docker:test",
|
DockerImage: "example/docker:test",
|
||||||
Name: controllerName("runner"),
|
Name: controllerName("runner"),
|
||||||
RegistrationRecheckInterval: time.Millisecond,
|
RegistrationRecheckInterval: time.Millisecond * 100,
|
||||||
RegistrationRecheckJitter: time.Millisecond,
|
RegistrationRecheckJitter: time.Millisecond * 10,
|
||||||
|
UnregistrationRetryDelay: 1 * time.Second,
|
||||||
}
|
}
|
||||||
err = runnerController.SetupWithManager(mgr)
|
err = runnerController.SetupWithManager(mgr)
|
||||||
Expect(err).NotTo(HaveOccurred(), "failed to setup runner controller")
|
Expect(err).NotTo(HaveOccurred(), "failed to setup runner controller")
|
||||||
@@ -268,7 +269,6 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
|
|||||||
|
|
||||||
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1)
|
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1)
|
||||||
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 2)
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 2)
|
||||||
ExpectHRAStatusCacheEntryLengthEventuallyEquals(ctx, ns.Name, name, 1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -371,7 +371,6 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
|
|||||||
|
|
||||||
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1)
|
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1)
|
||||||
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 3)
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 3)
|
||||||
ExpectHRAStatusCacheEntryLengthEventuallyEquals(ctx, ns.Name, name, 1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -538,6 +537,106 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should create and scale organization's repository runners on workflow_job event", func() {
|
||||||
|
name := "example-runnerdeploy"
|
||||||
|
|
||||||
|
{
|
||||||
|
rd := &actionsv1alpha1.RunnerDeployment{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: ns.Name,
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerDeploymentSpec{
|
||||||
|
Replicas: intPtr(1),
|
||||||
|
Selector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Template: actionsv1alpha1.RunnerTemplate{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerSpec{
|
||||||
|
RunnerConfig: actionsv1alpha1.RunnerConfig{
|
||||||
|
Repository: "test/valid",
|
||||||
|
Image: "bar",
|
||||||
|
Group: "baz",
|
||||||
|
},
|
||||||
|
RunnerPodSpec: actionsv1alpha1.RunnerPodSpec{
|
||||||
|
Env: []corev1.EnvVar{
|
||||||
|
{Name: "FOO", Value: "FOOVALUE"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpectCreate(ctx, rd, "test RunnerDeployment")
|
||||||
|
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1)
|
||||||
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 1)
|
||||||
|
env.ExpectRegisteredNumberCountEventuallyEquals(1, "count of fake list runners")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale-up to 1 replica via ScaleUpTriggers.GitHubEvent.WorkflowJob based scaling
|
||||||
|
{
|
||||||
|
hra := &actionsv1alpha1.HorizontalRunnerAutoscaler{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: ns.Name,
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.HorizontalRunnerAutoscalerSpec{
|
||||||
|
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
||||||
|
Name: name,
|
||||||
|
},
|
||||||
|
MinReplicas: intPtr(1),
|
||||||
|
MaxReplicas: intPtr(5),
|
||||||
|
ScaleDownDelaySecondsAfterScaleUp: intPtr(1),
|
||||||
|
ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{
|
||||||
|
{
|
||||||
|
GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{
|
||||||
|
WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{},
|
||||||
|
},
|
||||||
|
Amount: 1,
|
||||||
|
Duration: metav1.Duration{Duration: time.Minute},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpectCreate(ctx, hra, "test HorizontalRunnerAutoscaler")
|
||||||
|
|
||||||
|
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1)
|
||||||
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 1)
|
||||||
|
env.ExpectRegisteredNumberCountEventuallyEquals(1, "count of fake list runners")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale-up to 2 replicas on first workflow_job.queued webhook event
|
||||||
|
{
|
||||||
|
env.SendWorkflowJobEvent("test", "valid", "queued", []string{"self-hosted"})
|
||||||
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 2, "runners after first webhook event")
|
||||||
|
env.ExpectRegisteredNumberCountEventuallyEquals(2, "count of fake list runners")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale-up to 3 replicas on second workflow_job.queued webhook event
|
||||||
|
{
|
||||||
|
env.SendWorkflowJobEvent("test", "valid", "queued", []string{"self-hosted"})
|
||||||
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 3, "runners after second webhook event")
|
||||||
|
env.ExpectRegisteredNumberCountEventuallyEquals(3, "count of fake list runners")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not scale-up on third workflow_job.queued webhook event
|
||||||
|
// repo "example" doesn't match our Spec
|
||||||
|
{
|
||||||
|
env.SendWorkflowJobEvent("test", "example", "queued", []string{"self-hosted"})
|
||||||
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 3, "runners after third webhook event")
|
||||||
|
env.ExpectRegisteredNumberCountEventuallyEquals(3, "count of fake list runners")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
It("should create and scale organization's repository runners only on check_run event", func() {
|
It("should create and scale organization's repository runners only on check_run event", func() {
|
||||||
name := "example-runnerdeploy"
|
name := "example-runnerdeploy"
|
||||||
|
|
||||||
@@ -582,9 +681,7 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
|
|||||||
env.ExpectRegisteredNumberCountEventuallyEquals(1, "count of fake list runners")
|
env.ExpectRegisteredNumberCountEventuallyEquals(1, "count of fake list runners")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale-up to 3 replicas by the default TotalNumberOfQueuedAndInProgressWorkflowRuns-based scaling
|
// Scale-up to 1 replica via ScaleUpTriggers.GitHubEvent.CheckRun based scaling
|
||||||
// See workflowRunsFor3Replicas_queued and workflowRunsFor3Replicas_in_progress for GitHub List-Runners API responses
|
|
||||||
// used while testing.
|
|
||||||
{
|
{
|
||||||
hra := &actionsv1alpha1.HorizontalRunnerAutoscaler{
|
hra := &actionsv1alpha1.HorizontalRunnerAutoscaler{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
@@ -1077,24 +1174,176 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should be able to scale visible organization runner group with default labels", func() {
|
||||||
|
name := "example-runnerdeploy"
|
||||||
|
|
||||||
|
{
|
||||||
|
rd := &actionsv1alpha1.RunnerDeployment{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: ns.Name,
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerDeploymentSpec{
|
||||||
|
Replicas: intPtr(1),
|
||||||
|
Selector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Template: actionsv1alpha1.RunnerTemplate{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerSpec{
|
||||||
|
RunnerConfig: actionsv1alpha1.RunnerConfig{
|
||||||
|
Repository: "test/valid",
|
||||||
|
Image: "bar",
|
||||||
|
Group: "baz",
|
||||||
|
},
|
||||||
|
RunnerPodSpec: actionsv1alpha1.RunnerPodSpec{
|
||||||
|
Env: []corev1.EnvVar{
|
||||||
|
{Name: "FOO", Value: "FOOVALUE"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpectCreate(ctx, rd, "test RunnerDeployment")
|
||||||
|
|
||||||
|
hra := &actionsv1alpha1.HorizontalRunnerAutoscaler{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: ns.Name,
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.HorizontalRunnerAutoscalerSpec{
|
||||||
|
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
||||||
|
Name: name,
|
||||||
|
},
|
||||||
|
MinReplicas: intPtr(1),
|
||||||
|
MaxReplicas: intPtr(5),
|
||||||
|
ScaleDownDelaySecondsAfterScaleUp: intPtr(1),
|
||||||
|
ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{
|
||||||
|
{
|
||||||
|
GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{
|
||||||
|
WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{},
|
||||||
|
},
|
||||||
|
Amount: 1,
|
||||||
|
Duration: metav1.Duration{Duration: time.Minute},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpectCreate(ctx, hra, "test HorizontalRunnerAutoscaler")
|
||||||
|
|
||||||
|
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1)
|
||||||
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
env.ExpectRegisteredNumberCountEventuallyEquals(1, "count of fake list runners")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale-up to 2 replicas on first workflow_job webhook event
|
||||||
|
{
|
||||||
|
env.SendWorkflowJobEvent("test", "valid", "queued", []string{"self-hosted"})
|
||||||
|
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1, "runner sets after webhook")
|
||||||
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 2, "runners after first webhook event")
|
||||||
|
env.ExpectRegisteredNumberCountEventuallyEquals(2, "count of fake list runners")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should be able to scale visible organization runner group with custom labels", func() {
|
||||||
|
name := "example-runnerdeploy"
|
||||||
|
|
||||||
|
{
|
||||||
|
rd := &actionsv1alpha1.RunnerDeployment{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: ns.Name,
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerDeploymentSpec{
|
||||||
|
Replicas: intPtr(1),
|
||||||
|
Selector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Template: actionsv1alpha1.RunnerTemplate{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerSpec{
|
||||||
|
RunnerConfig: actionsv1alpha1.RunnerConfig{
|
||||||
|
Repository: "test/valid",
|
||||||
|
Image: "bar",
|
||||||
|
Group: "baz",
|
||||||
|
Labels: []string{"custom-label"},
|
||||||
|
},
|
||||||
|
RunnerPodSpec: actionsv1alpha1.RunnerPodSpec{
|
||||||
|
Env: []corev1.EnvVar{
|
||||||
|
{Name: "FOO", Value: "FOOVALUE"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpectCreate(ctx, rd, "test RunnerDeployment")
|
||||||
|
|
||||||
|
hra := &actionsv1alpha1.HorizontalRunnerAutoscaler{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: ns.Name,
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.HorizontalRunnerAutoscalerSpec{
|
||||||
|
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
|
||||||
|
Name: name,
|
||||||
|
},
|
||||||
|
MinReplicas: intPtr(1),
|
||||||
|
MaxReplicas: intPtr(5),
|
||||||
|
ScaleDownDelaySecondsAfterScaleUp: intPtr(1),
|
||||||
|
ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{
|
||||||
|
{
|
||||||
|
GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{
|
||||||
|
WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{},
|
||||||
|
},
|
||||||
|
Amount: 1,
|
||||||
|
Duration: metav1.Duration{Duration: time.Minute},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpectCreate(ctx, hra, "test HorizontalRunnerAutoscaler")
|
||||||
|
|
||||||
|
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1)
|
||||||
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
env.ExpectRegisteredNumberCountEventuallyEquals(1, "count of fake list runners")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale-up to 2 replicas on first workflow_job webhook event
|
||||||
|
{
|
||||||
|
env.SendWorkflowJobEvent("test", "valid", "queued", []string{"custom-label"})
|
||||||
|
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1, "runner sets after webhook")
|
||||||
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 2, "runners after first webhook event")
|
||||||
|
env.ExpectRegisteredNumberCountEventuallyEquals(2, "count of fake list runners")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
func ExpectHRAStatusCacheEntryLengthEventuallyEquals(ctx context.Context, ns string, name string, value int, optionalDescriptions ...interface{}) {
|
|
||||||
EventuallyWithOffset(
|
|
||||||
1,
|
|
||||||
func() int {
|
|
||||||
var hra actionsv1alpha1.HorizontalRunnerAutoscaler
|
|
||||||
|
|
||||||
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns, Name: name}, &hra)
|
|
||||||
|
|
||||||
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "failed to get test HRA resource")
|
|
||||||
|
|
||||||
return len(hra.Status.CacheEntries)
|
|
||||||
},
|
|
||||||
time.Second*5, time.Millisecond*500).Should(Equal(value), optionalDescriptions...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExpectHRADesiredReplicasEquals(ctx context.Context, ns, name string, desired int, optionalDescriptions ...interface{}) {
|
func ExpectHRADesiredReplicasEquals(ctx context.Context, ns, name string, desired int, optionalDescriptions ...interface{}) {
|
||||||
var rd actionsv1alpha1.HorizontalRunnerAutoscaler
|
var rd actionsv1alpha1.HorizontalRunnerAutoscaler
|
||||||
|
|
||||||
@@ -1166,6 +1415,30 @@ func (env *testEnvironment) SendOrgCheckRunEvent(org, repo, status, action strin
|
|||||||
ExpectWithOffset(1, resp.StatusCode).To(Equal(200))
|
ExpectWithOffset(1, resp.StatusCode).To(Equal(200))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (env *testEnvironment) SendWorkflowJobEvent(org, repo, statusAndAction string, labels []string) {
|
||||||
|
resp, err := sendWebhook(env.webhookServer, "workflow_job", &github.WorkflowJobEvent{
|
||||||
|
WorkflowJob: &github.WorkflowJob{
|
||||||
|
Status: &statusAndAction,
|
||||||
|
Labels: labels,
|
||||||
|
},
|
||||||
|
Org: &github.Organization{
|
||||||
|
Login: github.String(org),
|
||||||
|
},
|
||||||
|
Repo: &github.Repository{
|
||||||
|
Name: github.String(repo),
|
||||||
|
Owner: &github.User{
|
||||||
|
Login: github.String(org),
|
||||||
|
Type: github.String("Organization"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: github.String(statusAndAction),
|
||||||
|
})
|
||||||
|
|
||||||
|
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "failed to send workflow_job event")
|
||||||
|
|
||||||
|
ExpectWithOffset(1, resp.StatusCode).To(Equal(200))
|
||||||
|
}
|
||||||
|
|
||||||
func (env *testEnvironment) SendUserPullRequestEvent(owner, repo, branch, action string) {
|
func (env *testEnvironment) SendUserPullRequestEvent(owner, repo, branch, action string) {
|
||||||
resp, err := sendWebhook(env.webhookServer, "pull_request", &github.PullRequestEvent{
|
resp, err := sendWebhook(env.webhookServer, "pull_request", &github.PullRequestEvent{
|
||||||
PullRequest: &github.PullRequest{
|
PullRequest: &github.PullRequest{
|
||||||
|
|||||||
1122
controllers/new_runner_pod_test.go
Normal file
1122
controllers/new_runner_pod_test.go
Normal file
File diff suppressed because it is too large
Load Diff
74
controllers/persistent_volume_claim_controller.go
Normal file
74
controllers/persistent_volume_claim_controller.go
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The actions-runner-controller authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/go-logr/logr"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/client-go/tools/record"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RunnerPersistentVolumeClaimReconciler reconciles a PersistentVolume object
|
||||||
|
type RunnerPersistentVolumeClaimReconciler struct {
|
||||||
|
client.Client
|
||||||
|
Log logr.Logger
|
||||||
|
Recorder record.EventRecorder
|
||||||
|
Scheme *runtime.Scheme
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:rbac:groups=core,resources=persistentvolumeclaims,verbs=get;list;watch;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=core,resources=persistentvolumes,verbs=get;list;watch;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=core,resources=events,verbs=create;patch
|
||||||
|
|
||||||
|
func (r *RunnerPersistentVolumeClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||||
|
log := r.Log.WithValues("pvc", req.NamespacedName)
|
||||||
|
|
||||||
|
var pvc corev1.PersistentVolumeClaim
|
||||||
|
if err := r.Get(ctx, req.NamespacedName, &pvc); err != nil {
|
||||||
|
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := syncPVC(ctx, r.Client, log, req.Namespace, &pvc)
|
||||||
|
|
||||||
|
if res == nil {
|
||||||
|
res = &ctrl.Result{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RunnerPersistentVolumeClaimReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
|
name := "runnerpersistentvolumeclaim-controller"
|
||||||
|
if r.Name != "" {
|
||||||
|
name = r.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Recorder = mgr.GetEventRecorderFor(name)
|
||||||
|
|
||||||
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
|
For(&corev1.PersistentVolumeClaim{}).
|
||||||
|
Named(name).
|
||||||
|
Complete(r)
|
||||||
|
}
|
||||||
72
controllers/persistent_volume_controller.go
Normal file
72
controllers/persistent_volume_controller.go
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The actions-runner-controller authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/go-logr/logr"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/client-go/tools/record"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RunnerPersistentVolumeReconciler reconciles a PersistentVolume object
|
||||||
|
type RunnerPersistentVolumeReconciler struct {
|
||||||
|
client.Client
|
||||||
|
Log logr.Logger
|
||||||
|
Recorder record.EventRecorder
|
||||||
|
Scheme *runtime.Scheme
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
// +kubebuilder:rbac:groups=core,resources=persistentvolumes,verbs=get;list;watch;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=core,resources=events,verbs=create;patch
|
||||||
|
|
||||||
|
func (r *RunnerPersistentVolumeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||||
|
log := r.Log.WithValues("pv", req.NamespacedName)
|
||||||
|
|
||||||
|
var pv corev1.PersistentVolume
|
||||||
|
if err := r.Get(ctx, req.NamespacedName, &pv); err != nil {
|
||||||
|
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := syncPV(ctx, r.Client, log, req.Namespace, &pv)
|
||||||
|
if res == nil {
|
||||||
|
res = &ctrl.Result{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RunnerPersistentVolumeReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
|
name := "runnerpersistentvolume-controller"
|
||||||
|
if r.Name != "" {
|
||||||
|
name = r.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Recorder = mgr.GetEventRecorderFor(name)
|
||||||
|
|
||||||
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
|
For(&corev1.PersistentVolume{}).
|
||||||
|
Named(name).
|
||||||
|
Complete(r)
|
||||||
|
}
|
||||||
@@ -59,9 +59,9 @@ func (t *PodRunnerTokenInjector) Handle(ctx context.Context, req admission.Reque
|
|||||||
return newEmptyResponse()
|
return newEmptyResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
enterprise, okEnterprise := getEnv(runnerContainer, "RUNNER_ENTERPRISE")
|
enterprise, okEnterprise := getEnv(runnerContainer, EnvVarEnterprise)
|
||||||
repo, okRepo := getEnv(runnerContainer, "RUNNER_REPO")
|
repo, okRepo := getEnv(runnerContainer, EnvVarRepo)
|
||||||
org, okOrg := getEnv(runnerContainer, "RUNNER_ORG")
|
org, okOrg := getEnv(runnerContainer, EnvVarOrg)
|
||||||
if !okRepo || !okOrg || !okEnterprise {
|
if !okRepo || !okOrg || !okEnterprise {
|
||||||
return newEmptyResponse()
|
return newEmptyResponse()
|
||||||
}
|
}
|
||||||
@@ -78,9 +78,7 @@ func (t *PodRunnerTokenInjector) Handle(ctx context.Context, req admission.Reque
|
|||||||
|
|
||||||
updated.Annotations[AnnotationKeyTokenExpirationDate] = ts
|
updated.Annotations[AnnotationKeyTokenExpirationDate] = ts
|
||||||
|
|
||||||
if pod.Spec.RestartPolicy != corev1.RestartPolicyOnFailure {
|
forceRunnerPodRestartPolicyNever(updated)
|
||||||
updated.Spec.RestartPolicy = corev1.RestartPolicyOnFailure
|
|
||||||
}
|
|
||||||
|
|
||||||
buf, err := json.Marshal(updated)
|
buf, err := json.Marshal(updated)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -18,21 +18,19 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/hash"
|
"github.com/actions-runner-controller/actions-runner-controller/hash"
|
||||||
gogithub "github.com/google/go-github/v37/github"
|
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
|
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
|
|
||||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -49,12 +47,11 @@ const (
|
|||||||
|
|
||||||
retryDelayOnGitHubAPIRateLimitError = 30 * time.Second
|
retryDelayOnGitHubAPIRateLimitError = 30 * time.Second
|
||||||
|
|
||||||
// This is an annotation internal to actions-runner-controller and can change in backward-incompatible ways
|
|
||||||
annotationKeyRegistrationOnly = "actions-runner-controller/registration-only"
|
|
||||||
|
|
||||||
EnvVarOrg = "RUNNER_ORG"
|
EnvVarOrg = "RUNNER_ORG"
|
||||||
EnvVarRepo = "RUNNER_REPO"
|
EnvVarRepo = "RUNNER_REPO"
|
||||||
EnvVarEnterprise = "RUNNER_ENTERPRISE"
|
EnvVarEnterprise = "RUNNER_ENTERPRISE"
|
||||||
|
EnvVarEphemeral = "RUNNER_EPHEMERAL"
|
||||||
|
EnvVarTrue = "true"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunnerReconciler reconciles a Runner object
|
// RunnerReconciler reconciles a Runner object
|
||||||
@@ -65,11 +62,14 @@ type RunnerReconciler struct {
|
|||||||
Scheme *runtime.Scheme
|
Scheme *runtime.Scheme
|
||||||
GitHubClient *github.Client
|
GitHubClient *github.Client
|
||||||
RunnerImage string
|
RunnerImage string
|
||||||
|
RunnerImagePullSecrets []string
|
||||||
DockerImage string
|
DockerImage string
|
||||||
DockerRegistryMirror string
|
DockerRegistryMirror string
|
||||||
Name string
|
Name string
|
||||||
RegistrationRecheckInterval time.Duration
|
RegistrationRecheckInterval time.Duration
|
||||||
RegistrationRecheckJitter time.Duration
|
RegistrationRecheckJitter time.Duration
|
||||||
|
|
||||||
|
UnregistrationRetryDelay time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runners,verbs=get;list;watch;create;update;patch;delete
|
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runners,verbs=get;list;watch;create;update;patch;delete
|
||||||
@@ -87,12 +87,6 @@ func (r *RunnerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
|
|||||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := runner.Validate()
|
|
||||||
if err != nil {
|
|
||||||
log.Info("Failed to validate runner spec", "error", err.Error())
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if runner.ObjectMeta.DeletionTimestamp.IsZero() {
|
if runner.ObjectMeta.DeletionTimestamp.IsZero() {
|
||||||
finalizers, added := addFinalizer(runner.ObjectMeta.Finalizers, finalizerName)
|
finalizers, added := addFinalizer(runner.ObjectMeta.Finalizers, finalizerName)
|
||||||
|
|
||||||
@@ -108,428 +102,176 @@ func (r *RunnerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
|
|||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
finalizers, removed := removeFinalizer(runner.ObjectMeta.Finalizers, finalizerName)
|
// Request to remove a runner. DeletionTimestamp was set in the runner - we need to unregister runner
|
||||||
|
|
||||||
if removed {
|
|
||||||
if len(runner.Status.Registration.Token) > 0 {
|
|
||||||
ok, err := r.unregisterRunner(ctx, runner.Spec.Enterprise, runner.Spec.Organization, runner.Spec.Repository, runner.Name)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, &gogithub.RateLimitError{}) {
|
|
||||||
// We log the underlying error when we failed calling GitHub API to list or unregisters,
|
|
||||||
// or the runner is still busy.
|
|
||||||
log.Error(
|
|
||||||
err,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"Failed to unregister runner due to GitHub API rate limits. Delaying retry for %s to avoid excessive GitHub API calls",
|
|
||||||
retryDelayOnGitHubAPIRateLimitError,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
return ctrl.Result{RequeueAfter: retryDelayOnGitHubAPIRateLimitError}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
log.V(1).Info("Runner no longer exists on GitHub")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.V(1).Info("Runner was never registered on GitHub")
|
|
||||||
}
|
|
||||||
|
|
||||||
newRunner := runner.DeepCopy()
|
|
||||||
newRunner.ObjectMeta.Finalizers = finalizers
|
|
||||||
|
|
||||||
if err := r.Patch(ctx, newRunner, client.MergeFrom(&runner)); err != nil {
|
|
||||||
log.Error(err, "Failed to update runner for finalizer removal")
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("Removed runner from GitHub", "repository", runner.Spec.Repository, "organization", runner.Spec.Organization)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
registrationOnly := metav1.HasAnnotation(runner.ObjectMeta, annotationKeyRegistrationOnly)
|
|
||||||
if registrationOnly && runner.Status.Phase != "" {
|
|
||||||
// At this point we are sure that the registration-only runner has successfully configured and
|
|
||||||
// is of `offline` status, because we set runner.Status.Phase to that of the runner pod only after
|
|
||||||
// successful registration.
|
|
||||||
|
|
||||||
var pod corev1.Pod
|
var pod corev1.Pod
|
||||||
if err := r.Get(ctx, req.NamespacedName, &pod); err != nil {
|
if err := r.Get(ctx, req.NamespacedName, &pod); err != nil {
|
||||||
if !kerrors.IsNotFound(err) {
|
if !kerrors.IsNotFound(err) {
|
||||||
log.Info(fmt.Sprintf("Retrying soon as we failed to get registration-only runner pod: %v", err))
|
log.Info(fmt.Sprintf("Retrying soon as we failed to get runner pod: %v", err))
|
||||||
|
|
||||||
return ctrl.Result{Requeue: true}, nil
|
|
||||||
}
|
|
||||||
} else if err := r.Delete(ctx, &pod); err != nil {
|
|
||||||
if !kerrors.IsNotFound(err) {
|
|
||||||
log.Info(fmt.Sprintf("Retrying soon as we failed to delete registration-only runner pod: %v", err))
|
|
||||||
|
|
||||||
return ctrl.Result{Requeue: true}, nil
|
return ctrl.Result{Requeue: true}, nil
|
||||||
}
|
}
|
||||||
|
// Pod was not found
|
||||||
|
return r.processRunnerDeletion(runner, ctx, log, nil)
|
||||||
}
|
}
|
||||||
|
return r.processRunnerDeletion(runner, ctx, log, &pod)
|
||||||
log.Info("Successfully deleted registration-only runner pod to free node and cluster resource")
|
|
||||||
|
|
||||||
// Return here to not recreate the deleted pod, because recreating it is the waste of cluster and node resource,
|
|
||||||
// and also defeats the original purpose of scale-from/to-zero we're trying to implement by using the registration-only runner.
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var pod corev1.Pod
|
var pod corev1.Pod
|
||||||
if err := r.Get(ctx, req.NamespacedName, &pod); err != nil {
|
if err := r.Get(ctx, req.NamespacedName, &pod); err != nil {
|
||||||
if !kerrors.IsNotFound(err) {
|
if !kerrors.IsNotFound(err) {
|
||||||
|
// An error ocurred
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
return r.processRunnerCreation(ctx, runner, log)
|
||||||
|
}
|
||||||
|
|
||||||
if updated, err := r.updateRegistrationToken(ctx, runner); err != nil {
|
phase := string(pod.Status.Phase)
|
||||||
return ctrl.Result{}, err
|
if phase == "" {
|
||||||
} else if updated {
|
phase = "Created"
|
||||||
return ctrl.Result{Requeue: true}, nil
|
}
|
||||||
}
|
|
||||||
|
|
||||||
newPod, err := r.newPod(runner)
|
ready := runnerPodReady(&pod)
|
||||||
if err != nil {
|
|
||||||
log.Error(err, "Could not create pod")
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := r.Create(ctx, &newPod); err != nil {
|
if runner.Status.Phase != phase || runner.Status.Ready != ready {
|
||||||
if kerrors.IsAlreadyExists(err) {
|
if pod.Status.Phase == corev1.PodRunning {
|
||||||
// Gracefully handle pod-already-exists errors due to informer cache delay.
|
// Seeing this message, you can expect the runner to become `Running` soon.
|
||||||
// Without this we got a few errors like the below on new runner pod:
|
log.V(1).Info(
|
||||||
// 2021-03-16T00:23:10.116Z ERROR controller-runtime.controller Reconciler error {"controller": "runner-controller", "request": "default/example-runnerdeploy-b2g2g-j4mcp", "error": "pods \"example-runnerdeploy-b2g2g-j4mcp\" already exists"}
|
"Runner appears to have been registered and running.",
|
||||||
log.Info(
|
"podCreationTimestamp", pod.CreationTimestamp,
|
||||||
"Failed to create pod due to AlreadyExists error. Probably this pod has been already created in previous reconcilation but is still not in the informer cache. Will retry on pod created. If it doesn't repeat, there's no problem",
|
|
||||||
)
|
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Error(err, "Failed to create pod resource")
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Recorder.Event(&runner, corev1.EventTypeNormal, "PodCreated", fmt.Sprintf("Created pod '%s'", newPod.Name))
|
|
||||||
log.Info("Created runner pod", "repository", runner.Spec.Repository)
|
|
||||||
} else {
|
|
||||||
if !pod.ObjectMeta.DeletionTimestamp.IsZero() {
|
|
||||||
deletionTimeout := 1 * time.Minute
|
|
||||||
currentTime := time.Now()
|
|
||||||
deletionDidTimeout := currentTime.Sub(pod.DeletionTimestamp.Add(deletionTimeout)) > 0
|
|
||||||
|
|
||||||
if deletionDidTimeout {
|
|
||||||
log.Info(
|
|
||||||
fmt.Sprintf("Failed to delete pod within %s. ", deletionTimeout)+
|
|
||||||
"This is typically the case when a Kubernetes node became unreachable "+
|
|
||||||
"and the kube controller started evicting nodes. Forcefully deleting the pod to not get stuck.",
|
|
||||||
"podDeletionTimestamp", pod.DeletionTimestamp,
|
|
||||||
"currentTime", currentTime,
|
|
||||||
"configuredDeletionTimeout", deletionTimeout,
|
|
||||||
)
|
|
||||||
|
|
||||||
var force int64 = 0
|
|
||||||
// forcefully delete runner as we would otherwise get stuck if the node stays unreachable
|
|
||||||
if err := r.Delete(ctx, &pod, &client.DeleteOptions{GracePeriodSeconds: &force}); err != nil {
|
|
||||||
// probably
|
|
||||||
if !kerrors.IsNotFound(err) {
|
|
||||||
log.Error(err, "Failed to forcefully delete pod resource ...")
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
// forceful deletion finally succeeded
|
|
||||||
return ctrl.Result{Requeue: true}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Recorder.Event(&runner, corev1.EventTypeNormal, "PodDeleted", fmt.Sprintf("Forcefully deleted pod '%s'", pod.Name))
|
|
||||||
log.Info("Forcefully deleted runner pod", "repository", runner.Spec.Repository)
|
|
||||||
// give kube manager a little time to forcefully delete the stuck pod
|
|
||||||
return ctrl.Result{RequeueAfter: 3 * time.Second}, err
|
|
||||||
} else {
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If pod has ended up succeeded we need to restart it
|
|
||||||
// Happens e.g. when dind is in runner and run completes
|
|
||||||
stopped := pod.Status.Phase == corev1.PodSucceeded
|
|
||||||
|
|
||||||
if !stopped {
|
|
||||||
if pod.Status.Phase == corev1.PodRunning {
|
|
||||||
for _, status := range pod.Status.ContainerStatuses {
|
|
||||||
if status.Name != containerName {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if status.State.Terminated != nil && status.State.Terminated.ExitCode == 0 {
|
|
||||||
stopped = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
restart := stopped
|
|
||||||
|
|
||||||
if registrationOnly && stopped {
|
|
||||||
restart = false
|
|
||||||
|
|
||||||
log.Info(
|
|
||||||
"Observed that registration-only runner for scaling-from-zero has successfully stopped. " +
|
|
||||||
"Unlike other pods, this one will be recreated only when runner spec changes.",
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if updated, err := r.updateRegistrationToken(ctx, runner); err != nil {
|
updated := runner.DeepCopy()
|
||||||
return ctrl.Result{}, err
|
updated.Status.Phase = phase
|
||||||
} else if updated {
|
updated.Status.Ready = ready
|
||||||
return ctrl.Result{Requeue: true}, nil
|
updated.Status.Reason = pod.Status.Reason
|
||||||
}
|
updated.Status.Message = pod.Status.Message
|
||||||
|
|
||||||
newPod, err := r.newPod(runner)
|
if err := r.Status().Patch(ctx, updated, client.MergeFrom(&runner)); err != nil {
|
||||||
if err != nil {
|
log.Error(err, "Failed to update runner status for Phase/Reason/Message")
|
||||||
log.Error(err, "Could not create pod")
|
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if registrationOnly {
|
|
||||||
newPod.Spec.Containers[0].Env = append(
|
|
||||||
newPod.Spec.Containers[0].Env,
|
|
||||||
corev1.EnvVar{
|
|
||||||
Name: "RUNNER_REGISTRATION_ONLY",
|
|
||||||
Value: "true",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
var registrationRecheckDelay time.Duration
|
|
||||||
|
|
||||||
// all checks done below only decide whether a restart is needed
|
|
||||||
// if a restart was already decided before, there is no need for the checks
|
|
||||||
// saving API calls and scary log messages
|
|
||||||
if !restart {
|
|
||||||
registrationCheckInterval := time.Minute
|
|
||||||
if r.RegistrationRecheckInterval > 0 {
|
|
||||||
registrationCheckInterval = r.RegistrationRecheckInterval
|
|
||||||
}
|
|
||||||
|
|
||||||
// We want to call ListRunners GitHub Actions API only once per runner per minute.
|
|
||||||
// This if block, in conjunction with:
|
|
||||||
// return ctrl.Result{RequeueAfter: registrationRecheckDelay}, nil
|
|
||||||
// achieves that.
|
|
||||||
if lastCheckTime := runner.Status.LastRegistrationCheckTime; lastCheckTime != nil {
|
|
||||||
nextCheckTime := lastCheckTime.Add(registrationCheckInterval)
|
|
||||||
now := time.Now()
|
|
||||||
|
|
||||||
// Requeue scheduled by RequeueAfter can happen a bit earlier (like dozens of milliseconds)
|
|
||||||
// so to avoid excessive, in-effective retry, we heuristically ignore the remaining delay in case it is
|
|
||||||
// shorter than 1s
|
|
||||||
requeueAfter := nextCheckTime.Sub(now) - time.Second
|
|
||||||
if requeueAfter > 0 {
|
|
||||||
log.Info(
|
|
||||||
fmt.Sprintf("Skipped registration check because it's deferred until %s. Retrying in %s at latest", nextCheckTime, requeueAfter),
|
|
||||||
"lastRegistrationCheckTime", lastCheckTime,
|
|
||||||
"registrationCheckInterval", registrationCheckInterval,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Without RequeueAfter, the controller may not retry on scheduled. Instead, it must wait until the
|
|
||||||
// next sync period passes, which can be too much later than nextCheckTime.
|
|
||||||
//
|
|
||||||
// We need to requeue on this reconcilation even though we have already scheduled the initial
|
|
||||||
// requeue previously with `return ctrl.Result{RequeueAfter: registrationRecheckDelay}, nil`.
|
|
||||||
// Apparently, the workqueue used by controller-runtime seems to deduplicate and resets the delay on
|
|
||||||
// other requeues- so the initial scheduled requeue may have been reset due to requeue on
|
|
||||||
// spec/status change.
|
|
||||||
return ctrl.Result{RequeueAfter: requeueAfter}, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notFound := false
|
|
||||||
offline := false
|
|
||||||
|
|
||||||
runnerBusy, err := r.GitHubClient.IsRunnerBusy(ctx, runner.Spec.Enterprise, runner.Spec.Organization, runner.Spec.Repository, runner.Name)
|
|
||||||
|
|
||||||
currentTime := time.Now()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
var notFoundException *github.RunnerNotFound
|
|
||||||
var offlineException *github.RunnerOffline
|
|
||||||
if errors.As(err, ¬FoundException) {
|
|
||||||
notFound = true
|
|
||||||
} else if errors.As(err, &offlineException) {
|
|
||||||
offline = true
|
|
||||||
} else {
|
|
||||||
var e *gogithub.RateLimitError
|
|
||||||
if errors.As(err, &e) {
|
|
||||||
// We log the underlying error when we failed calling GitHub API to list or unregisters,
|
|
||||||
// or the runner is still busy.
|
|
||||||
log.Error(
|
|
||||||
err,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"Failed to check if runner is busy due to Github API rate limit. Retrying in %s to avoid excessive GitHub API calls",
|
|
||||||
retryDelayOnGitHubAPIRateLimitError,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
return ctrl.Result{RequeueAfter: retryDelayOnGitHubAPIRateLimitError}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// See the `newPod` function called above for more information
|
|
||||||
// about when this hash changes.
|
|
||||||
curHash := pod.Labels[LabelKeyPodTemplateHash]
|
|
||||||
newHash := newPod.Labels[LabelKeyPodTemplateHash]
|
|
||||||
|
|
||||||
if !runnerBusy && curHash != newHash {
|
|
||||||
restart = true
|
|
||||||
}
|
|
||||||
|
|
||||||
registrationTimeout := 10 * time.Minute
|
|
||||||
durationAfterRegistrationTimeout := currentTime.Sub(pod.CreationTimestamp.Add(registrationTimeout))
|
|
||||||
registrationDidTimeout := durationAfterRegistrationTimeout > 0
|
|
||||||
|
|
||||||
if notFound {
|
|
||||||
if registrationDidTimeout {
|
|
||||||
log.Info(
|
|
||||||
"Runner failed to register itself to GitHub in timely manner. "+
|
|
||||||
"Recreating the pod to see if it resolves the issue. "+
|
|
||||||
"CAUTION: If you see this a lot, you should investigate the root cause. "+
|
|
||||||
"See https://github.com/actions-runner-controller/actions-runner-controller/issues/288",
|
|
||||||
"podCreationTimestamp", pod.CreationTimestamp,
|
|
||||||
"currentTime", currentTime,
|
|
||||||
"configuredRegistrationTimeout", registrationTimeout,
|
|
||||||
)
|
|
||||||
|
|
||||||
restart = true
|
|
||||||
} else {
|
|
||||||
log.V(1).Info(
|
|
||||||
"Runner pod exists but we failed to check if runner is busy. Apparently it still needs more time.",
|
|
||||||
"runnerName", runner.Name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else if offline {
|
|
||||||
if registrationOnly {
|
|
||||||
log.Info(
|
|
||||||
"Observed that registration-only runner for scaling-from-zero has successfully been registered.",
|
|
||||||
"podCreationTimestamp", pod.CreationTimestamp,
|
|
||||||
"currentTime", currentTime,
|
|
||||||
"configuredRegistrationTimeout", registrationTimeout,
|
|
||||||
)
|
|
||||||
} else if registrationDidTimeout {
|
|
||||||
log.Info(
|
|
||||||
"Already existing GitHub runner still appears offline . "+
|
|
||||||
"Recreating the pod to see if it resolves the issue. "+
|
|
||||||
"CAUTION: If you see this a lot, you should investigate the root cause. ",
|
|
||||||
"podCreationTimestamp", pod.CreationTimestamp,
|
|
||||||
"currentTime", currentTime,
|
|
||||||
"configuredRegistrationTimeout", registrationTimeout,
|
|
||||||
)
|
|
||||||
|
|
||||||
restart = true
|
|
||||||
} else {
|
|
||||||
log.V(1).Info(
|
|
||||||
"Runner pod exists but the GitHub runner appears to be still offline. Waiting for runner to get online ...",
|
|
||||||
"runnerName", runner.Name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notFound || (offline && !registrationOnly)) && !registrationDidTimeout {
|
|
||||||
registrationRecheckJitter := 10 * time.Second
|
|
||||||
if r.RegistrationRecheckJitter > 0 {
|
|
||||||
registrationRecheckJitter = r.RegistrationRecheckJitter
|
|
||||||
}
|
|
||||||
|
|
||||||
registrationRecheckDelay = registrationCheckInterval + wait.Jitter(registrationRecheckJitter, 0.1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't do anything if there's no need to restart the runner
|
|
||||||
if !restart {
|
|
||||||
// This guard enables us to update runner.Status.Phase to `Running` only after
|
|
||||||
// the runner is registered to GitHub.
|
|
||||||
if registrationRecheckDelay > 0 {
|
|
||||||
log.V(1).Info(fmt.Sprintf("Rechecking the runner registration in %s", registrationRecheckDelay))
|
|
||||||
|
|
||||||
updated := runner.DeepCopy()
|
|
||||||
updated.Status.LastRegistrationCheckTime = &metav1.Time{Time: time.Now()}
|
|
||||||
|
|
||||||
if err := r.Status().Patch(ctx, updated, client.MergeFrom(&runner)); err != nil {
|
|
||||||
log.Error(err, "Failed to update runner status for LastRegistrationCheckTime")
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{RequeueAfter: registrationRecheckDelay}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if runner.Status.Phase != string(pod.Status.Phase) {
|
|
||||||
if pod.Status.Phase == corev1.PodRunning {
|
|
||||||
// Seeing this message, you can expect the runner to become `Running` soon.
|
|
||||||
log.Info(
|
|
||||||
"Runner appears to have registered and running.",
|
|
||||||
"podCreationTimestamp", pod.CreationTimestamp,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
updated := runner.DeepCopy()
|
|
||||||
updated.Status.Phase = string(pod.Status.Phase)
|
|
||||||
updated.Status.Reason = pod.Status.Reason
|
|
||||||
updated.Status.Message = pod.Status.Message
|
|
||||||
|
|
||||||
if err := r.Status().Patch(ctx, updated, client.MergeFrom(&runner)); err != nil {
|
|
||||||
log.Error(err, "Failed to update runner status for Phase/Reason/Message")
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete current pod if recreation is needed
|
|
||||||
if err := r.Delete(ctx, &pod); err != nil {
|
|
||||||
log.Error(err, "Failed to delete pod resource")
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Recorder.Event(&runner, corev1.EventTypeNormal, "PodDeleted", fmt.Sprintf("Deleted pod '%s'", newPod.Name))
|
|
||||||
log.Info("Deleted runner pod", "repository", runner.Spec.Repository)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RunnerReconciler) unregisterRunner(ctx context.Context, enterprise, org, repo, name string) (bool, error) {
|
func runnerPodReady(pod *corev1.Pod) bool {
|
||||||
runners, err := r.GitHubClient.ListRunners(ctx, enterprise, org, repo)
|
for _, c := range pod.Status.Conditions {
|
||||||
if err != nil {
|
if c.Type != corev1.PodReady {
|
||||||
return false, err
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Status == corev1.ConditionTrue
|
||||||
}
|
}
|
||||||
|
|
||||||
id := int64(0)
|
return false
|
||||||
for _, runner := range runners {
|
}
|
||||||
if runner.GetName() == name {
|
|
||||||
if runner.GetBusy() {
|
func runnerContainerExitCode(pod *corev1.Pod) *int32 {
|
||||||
return false, fmt.Errorf("runner is busy")
|
for _, status := range pod.Status.ContainerStatuses {
|
||||||
}
|
if status.Name != containerName {
|
||||||
id = runner.GetID()
|
continue
|
||||||
break
|
}
|
||||||
|
|
||||||
|
if status.State.Terminated != nil {
|
||||||
|
return &status.State.Terminated.ExitCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if id == int64(0) {
|
return nil
|
||||||
return false, nil
|
}
|
||||||
|
|
||||||
|
func runnerPodOrContainerIsStopped(pod *corev1.Pod) bool {
|
||||||
|
// If pod has ended up succeeded we need to restart it
|
||||||
|
// Happens e.g. when dind is in runner and run completes
|
||||||
|
stopped := pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodFailed
|
||||||
|
|
||||||
|
if !stopped {
|
||||||
|
if pod.Status.Phase == corev1.PodRunning {
|
||||||
|
for _, status := range pod.Status.ContainerStatuses {
|
||||||
|
if status.Name != containerName {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if status.State.Terminated != nil {
|
||||||
|
stopped = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.GitHubClient.RemoveRunner(ctx, enterprise, org, repo, id); err != nil {
|
return stopped
|
||||||
return false, err
|
}
|
||||||
|
|
||||||
|
func ephemeralRunnerContainerStatus(pod *corev1.Pod) *corev1.ContainerStatus {
|
||||||
|
if getRunnerEnv(pod, "RUNNER_EPHEMERAL") != "true" {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
for _, status := range pod.Status.ContainerStatuses {
|
||||||
|
if status.Name != containerName {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
status := status
|
||||||
|
|
||||||
|
return &status
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RunnerReconciler) processRunnerDeletion(runner v1alpha1.Runner, ctx context.Context, log logr.Logger, pod *corev1.Pod) (reconcile.Result, error) {
|
||||||
|
finalizers, removed := removeFinalizer(runner.ObjectMeta.Finalizers, finalizerName)
|
||||||
|
|
||||||
|
if removed {
|
||||||
|
newRunner := runner.DeepCopy()
|
||||||
|
newRunner.ObjectMeta.Finalizers = finalizers
|
||||||
|
|
||||||
|
if err := r.Patch(ctx, newRunner, client.MergeFrom(&runner)); err != nil {
|
||||||
|
log.Error(err, "Unable to remove finalizer")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("Removed finalizer")
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RunnerReconciler) processRunnerCreation(ctx context.Context, runner v1alpha1.Runner, log logr.Logger) (reconcile.Result, error) {
|
||||||
|
if updated, err := r.updateRegistrationToken(ctx, runner); err != nil {
|
||||||
|
return ctrl.Result{RequeueAfter: RetryDelayOnCreateRegistrationError}, nil
|
||||||
|
} else if updated {
|
||||||
|
return ctrl.Result{Requeue: true}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
newPod, err := r.newPod(runner)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err, "Could not create pod")
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.Create(ctx, &newPod); err != nil {
|
||||||
|
if kerrors.IsAlreadyExists(err) {
|
||||||
|
// Gracefully handle pod-already-exists errors due to informer cache delay.
|
||||||
|
// Without this we got a few errors like the below on new runner pod:
|
||||||
|
// 2021-03-16T00:23:10.116Z ERROR controller-runtime.controller Reconciler error {"controller": "runner-controller", "request": "default/example-runnerdeploy-b2g2g-j4mcp", "error": "pods \"example-runnerdeploy-b2g2g-j4mcp\" already exists"}
|
||||||
|
log.Info(
|
||||||
|
"Failed to create pod due to AlreadyExists error. Probably this pod has been already created in previous reconcilation but is still not in the informer cache. Will retry on pod created. If it doesn't repeat, there's no problem",
|
||||||
|
)
|
||||||
|
return ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Error(err, "Failed to create pod resource")
|
||||||
|
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Recorder.Event(&runner, corev1.EventTypeNormal, "PodCreated", fmt.Sprintf("Created pod '%s'", newPod.Name))
|
||||||
|
log.Info("Created runner pod", "repository", runner.Spec.Repository)
|
||||||
|
|
||||||
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RunnerReconciler) updateRegistrationToken(ctx context.Context, runner v1alpha1.Runner) (bool, error) {
|
func (r *RunnerReconciler) updateRegistrationToken(ctx context.Context, runner v1alpha1.Runner) (bool, error) {
|
||||||
@@ -541,6 +283,10 @@ func (r *RunnerReconciler) updateRegistrationToken(ctx context.Context, runner v
|
|||||||
|
|
||||||
rt, err := r.GitHubClient.GetRegistrationToken(ctx, runner.Spec.Enterprise, runner.Spec.Organization, runner.Spec.Repository, runner.Name)
|
rt, err := r.GitHubClient.GetRegistrationToken(ctx, runner.Spec.Enterprise, runner.Spec.Organization, runner.Spec.Repository, runner.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// An error can be a permanent, permission issue like the below:
|
||||||
|
// POST https://api.github.com/enterprises/YOUR_ENTERPRISE/actions/runners/registration-token: 403 Resource not accessible by integration []
|
||||||
|
// In such case retrying in seconds might not make much sense.
|
||||||
|
|
||||||
r.Recorder.Event(&runner, corev1.EventTypeWarning, "FailedUpdateRegistrationToken", "Updating registration token failed")
|
r.Recorder.Event(&runner, corev1.EventTypeWarning, "FailedUpdateRegistrationToken", "Updating registration token failed")
|
||||||
log.Error(err, "Failed to get new registration token")
|
log.Error(err, "Failed to get new registration token")
|
||||||
return false, err
|
return false, err
|
||||||
@@ -599,6 +345,11 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
|
|||||||
runner.ObjectMeta.Annotations,
|
runner.ObjectMeta.Annotations,
|
||||||
runner.Spec,
|
runner.Spec,
|
||||||
r.GitHubClient.GithubBaseURL,
|
r.GitHubClient.GithubBaseURL,
|
||||||
|
// Token change should trigger replacement.
|
||||||
|
// We need to include this explicitly here because
|
||||||
|
// runner.Spec does not contain the possibly updated token stored in the
|
||||||
|
// runner status yet.
|
||||||
|
runner.Status.Registration.Token,
|
||||||
)
|
)
|
||||||
|
|
||||||
objectMeta := metav1.ObjectMeta{
|
objectMeta := metav1.ObjectMeta{
|
||||||
@@ -612,30 +363,56 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
|
|||||||
|
|
||||||
if len(runner.Spec.Containers) == 0 {
|
if len(runner.Spec.Containers) == 0 {
|
||||||
template.Spec.Containers = append(template.Spec.Containers, corev1.Container{
|
template.Spec.Containers = append(template.Spec.Containers, corev1.Container{
|
||||||
Name: "runner",
|
Name: "runner",
|
||||||
ImagePullPolicy: runner.Spec.ImagePullPolicy,
|
|
||||||
EnvFrom: runner.Spec.EnvFrom,
|
|
||||||
Env: runner.Spec.Env,
|
|
||||||
Resources: runner.Spec.Resources,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (runner.Spec.DockerEnabled == nil || *runner.Spec.DockerEnabled) && (runner.Spec.DockerdWithinRunnerContainer == nil || !*runner.Spec.DockerdWithinRunnerContainer) {
|
if (runner.Spec.DockerEnabled == nil || *runner.Spec.DockerEnabled) && (runner.Spec.DockerdWithinRunnerContainer == nil || !*runner.Spec.DockerdWithinRunnerContainer) {
|
||||||
template.Spec.Containers = append(template.Spec.Containers, corev1.Container{
|
template.Spec.Containers = append(template.Spec.Containers, corev1.Container{
|
||||||
Name: "docker",
|
Name: "docker",
|
||||||
VolumeMounts: runner.Spec.DockerVolumeMounts,
|
|
||||||
Resources: runner.Spec.DockerdContainerResources,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
template.Spec.Containers = runner.Spec.Containers
|
template.Spec.Containers = runner.Spec.Containers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i, c := range template.Spec.Containers {
|
||||||
|
switch c.Name {
|
||||||
|
case "runner":
|
||||||
|
if c.ImagePullPolicy == "" {
|
||||||
|
template.Spec.Containers[i].ImagePullPolicy = runner.Spec.ImagePullPolicy
|
||||||
|
}
|
||||||
|
if len(c.EnvFrom) == 0 {
|
||||||
|
template.Spec.Containers[i].EnvFrom = runner.Spec.EnvFrom
|
||||||
|
}
|
||||||
|
if len(c.Env) == 0 {
|
||||||
|
template.Spec.Containers[i].Env = runner.Spec.Env
|
||||||
|
}
|
||||||
|
if len(c.Resources.Requests) == 0 {
|
||||||
|
template.Spec.Containers[i].Resources.Requests = runner.Spec.Resources.Requests
|
||||||
|
}
|
||||||
|
if len(c.Resources.Limits) == 0 {
|
||||||
|
template.Spec.Containers[i].Resources.Limits = runner.Spec.Resources.Limits
|
||||||
|
}
|
||||||
|
case "docker":
|
||||||
|
if len(c.VolumeMounts) == 0 {
|
||||||
|
template.Spec.Containers[i].VolumeMounts = runner.Spec.DockerVolumeMounts
|
||||||
|
}
|
||||||
|
if len(c.Resources.Limits) == 0 {
|
||||||
|
template.Spec.Containers[i].Resources.Limits = runner.Spec.DockerdContainerResources.Limits
|
||||||
|
}
|
||||||
|
if len(c.Resources.Requests) == 0 {
|
||||||
|
template.Spec.Containers[i].Resources.Requests = runner.Spec.DockerdContainerResources.Requests
|
||||||
|
}
|
||||||
|
if len(c.Env) == 0 {
|
||||||
|
template.Spec.Containers[i].Env = runner.Spec.DockerEnv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template.Spec.SecurityContext = runner.Spec.SecurityContext
|
template.Spec.SecurityContext = runner.Spec.SecurityContext
|
||||||
template.Spec.EnableServiceLinks = runner.Spec.EnableServiceLinks
|
template.Spec.EnableServiceLinks = runner.Spec.EnableServiceLinks
|
||||||
|
|
||||||
registrationOnly := metav1.HasAnnotation(runner.ObjectMeta, annotationKeyRegistrationOnly)
|
pod, err := newRunnerPod(runner.Name, template, runner.Spec.RunnerConfig, r.RunnerImage, r.RunnerImagePullSecrets, r.DockerImage, r.DockerRegistryMirror, r.GitHubClient.GithubBaseURL)
|
||||||
|
|
||||||
pod, err := newRunnerPod(template, runner.Spec.RunnerConfig, r.RunnerImage, r.DockerImage, r.DockerRegistryMirror, r.GitHubClient.GithubBaseURL, registrationOnly)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pod, err
|
return pod, err
|
||||||
}
|
}
|
||||||
@@ -644,10 +421,29 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
|
|||||||
runnerSpec := runner.Spec
|
runnerSpec := runner.Spec
|
||||||
|
|
||||||
if len(runnerSpec.VolumeMounts) != 0 {
|
if len(runnerSpec.VolumeMounts) != 0 {
|
||||||
|
// if operater provides a work volume mount, use that
|
||||||
|
isPresent, _ := workVolumeMountPresent(runnerSpec.VolumeMounts)
|
||||||
|
if isPresent {
|
||||||
|
// remove work volume since it will be provided from runnerSpec.Volumes
|
||||||
|
// if we don't remove it here we would get a duplicate key error, i.e. two volumes named work
|
||||||
|
_, index := workVolumeMountPresent(pod.Spec.Containers[0].VolumeMounts)
|
||||||
|
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts[:index], pod.Spec.Containers[0].VolumeMounts[index+1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, runnerSpec.VolumeMounts...)
|
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, runnerSpec.VolumeMounts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(runnerSpec.Volumes) != 0 {
|
if len(runnerSpec.Volumes) != 0 {
|
||||||
|
// if operator provides a work volume. use that
|
||||||
|
isPresent, _ := workVolumePresent(runnerSpec.Volumes)
|
||||||
|
if isPresent {
|
||||||
|
_, index := workVolumePresent(pod.Spec.Volumes)
|
||||||
|
|
||||||
|
// remove work volume since it will be provided from runnerSpec.Volumes
|
||||||
|
// if we don't remove it here we would get a duplicate key error, i.e. two volumes named work
|
||||||
|
pod.Spec.Volumes = append(pod.Spec.Volumes[:index], pod.Spec.Volumes[index+1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
pod.Spec.Volumes = append(pod.Spec.Volumes, runnerSpec.Volumes...)
|
pod.Spec.Volumes = append(pod.Spec.Volumes, runnerSpec.Volumes...)
|
||||||
}
|
}
|
||||||
if len(runnerSpec.InitContainers) != 0 {
|
if len(runnerSpec.InitContainers) != 0 {
|
||||||
@@ -696,6 +492,10 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
|
|||||||
pod.Spec.HostAliases = runnerSpec.HostAliases
|
pod.Spec.HostAliases = runnerSpec.HostAliases
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if runnerSpec.DnsConfig != nil {
|
||||||
|
pod.Spec.DNSConfig = runnerSpec.DnsConfig
|
||||||
|
}
|
||||||
|
|
||||||
if runnerSpec.RuntimeClassName != nil {
|
if runnerSpec.RuntimeClassName != nil {
|
||||||
pod.Spec.RuntimeClassName = runnerSpec.RuntimeClassName
|
pod.Spec.RuntimeClassName = runnerSpec.RuntimeClassName
|
||||||
}
|
}
|
||||||
@@ -715,25 +515,18 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
|
|||||||
func mutatePod(pod *corev1.Pod, token string) *corev1.Pod {
|
func mutatePod(pod *corev1.Pod, token string) *corev1.Pod {
|
||||||
updated := pod.DeepCopy()
|
updated := pod.DeepCopy()
|
||||||
|
|
||||||
for i := range pod.Spec.Containers {
|
if getRunnerEnv(pod, EnvVarRunnerName) == "" {
|
||||||
if pod.Spec.Containers[i].Name == "runner" {
|
setRunnerEnv(updated, EnvVarRunnerName, pod.ObjectMeta.Name)
|
||||||
updated.Spec.Containers[i].Env = append(updated.Spec.Containers[i].Env,
|
}
|
||||||
corev1.EnvVar{
|
|
||||||
Name: "RUNNER_NAME",
|
if getRunnerEnv(pod, EnvVarRunnerToken) == "" {
|
||||||
Value: pod.ObjectMeta.Name,
|
setRunnerEnv(updated, EnvVarRunnerToken, token)
|
||||||
},
|
|
||||||
corev1.EnvVar{
|
|
||||||
Name: "RUNNER_TOKEN",
|
|
||||||
Value: token,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return updated
|
return updated
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, defaultRunnerImage, defaultDockerImage, defaultDockerRegistryMirror string, githubBaseURL string, registrationOnly bool) (corev1.Pod, error) {
|
func newRunnerPod(runnerName string, template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, defaultRunnerImage string, defaultRunnerImagePullSecrets []string, defaultDockerImage, defaultDockerRegistryMirror string, githubBaseURL string) (corev1.Pod, error) {
|
||||||
var (
|
var (
|
||||||
privileged bool = true
|
privileged bool = true
|
||||||
dockerdInRunner bool = runnerSpec.DockerdWithinRunnerContainer != nil && *runnerSpec.DockerdWithinRunnerContainer
|
dockerdInRunner bool = runnerSpec.DockerdWithinRunnerContainer != nil && *runnerSpec.DockerdWithinRunnerContainer
|
||||||
@@ -742,6 +535,12 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default
|
|||||||
dockerdInRunnerPrivileged bool = dockerdInRunner
|
dockerdInRunnerPrivileged bool = dockerdInRunner
|
||||||
)
|
)
|
||||||
|
|
||||||
|
template = *template.DeepCopy()
|
||||||
|
|
||||||
|
// This label selector is used by default when rd.Spec.Selector is empty.
|
||||||
|
template.ObjectMeta.Labels = CloneAndAddLabel(template.ObjectMeta.Labels, LabelKeyRunnerSetName, runnerName)
|
||||||
|
template.ObjectMeta.Labels = CloneAndAddLabel(template.ObjectMeta.Labels, LabelKeyPodMutation, LabelValuePodMutation)
|
||||||
|
|
||||||
workDir := runnerSpec.WorkDir
|
workDir := runnerSpec.WorkDir
|
||||||
if workDir == "" {
|
if workDir == "" {
|
||||||
workDir = "/runner/_work"
|
workDir = "/runner/_work"
|
||||||
@@ -754,6 +553,8 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default
|
|||||||
dockerRegistryMirror = *runnerSpec.DockerRegistryMirror
|
dockerRegistryMirror = *runnerSpec.DockerRegistryMirror
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Be aware some of the environment variables are used
|
||||||
|
// in the runner entrypoint script
|
||||||
env := []corev1.EnvVar{
|
env := []corev1.EnvVar{
|
||||||
{
|
{
|
||||||
Name: EnvVarOrg,
|
Name: EnvVarOrg,
|
||||||
@@ -775,6 +576,10 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default
|
|||||||
Name: "RUNNER_GROUP",
|
Name: "RUNNER_GROUP",
|
||||||
Value: runnerSpec.Group,
|
Value: runnerSpec.Group,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "DOCKER_ENABLED",
|
||||||
|
Value: fmt.Sprintf("%v", dockerEnabled || dockerdInRunner),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "DOCKERD_IN_RUNNER",
|
Name: "DOCKERD_IN_RUNNER",
|
||||||
Value: fmt.Sprintf("%v", dockerdInRunner),
|
Value: fmt.Sprintf("%v", dockerdInRunner),
|
||||||
@@ -788,19 +593,11 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default
|
|||||||
Value: workDir,
|
Value: workDir,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "RUNNER_EPHEMERAL",
|
Name: EnvVarEphemeral,
|
||||||
Value: fmt.Sprintf("%v", ephemeral),
|
Value: fmt.Sprintf("%v", ephemeral),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if registrationOnly {
|
|
||||||
env = append(env, corev1.EnvVar{
|
|
||||||
Name: "RUNNER_REGISTRATION_ONLY",
|
|
||||||
Value: "true",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
var seLinuxOptions *corev1.SELinuxOptions
|
var seLinuxOptions *corev1.SELinuxOptions
|
||||||
if template.Spec.SecurityContext != nil {
|
if template.Spec.SecurityContext != nil {
|
||||||
seLinuxOptions = template.Spec.SecurityContext.SELinuxOptions
|
seLinuxOptions = template.Spec.SecurityContext.SELinuxOptions
|
||||||
@@ -858,14 +655,15 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default
|
|||||||
if runnerContainer.SecurityContext == nil {
|
if runnerContainer.SecurityContext == nil {
|
||||||
runnerContainer.SecurityContext = &corev1.SecurityContext{}
|
runnerContainer.SecurityContext = &corev1.SecurityContext{}
|
||||||
}
|
}
|
||||||
// Runner need to run privileged if it contains DinD
|
|
||||||
runnerContainer.SecurityContext.Privileged = &dockerdInRunnerPrivileged
|
if runnerContainer.SecurityContext.Privileged == nil {
|
||||||
|
// Runner need to run privileged if it contains DinD
|
||||||
|
runnerContainer.SecurityContext.Privileged = &dockerdInRunnerPrivileged
|
||||||
|
}
|
||||||
|
|
||||||
pod := template.DeepCopy()
|
pod := template.DeepCopy()
|
||||||
|
|
||||||
if pod.Spec.RestartPolicy == "" {
|
forceRunnerPodRestartPolicyNever(pod)
|
||||||
pod.Spec.RestartPolicy = "OnFailure"
|
|
||||||
}
|
|
||||||
|
|
||||||
if mtu := runnerSpec.DockerMTU; mtu != nil && dockerdInRunner {
|
if mtu := runnerSpec.DockerMTU; mtu != nil && dockerdInRunner {
|
||||||
runnerContainer.Env = append(runnerContainer.Env, []corev1.EnvVar{
|
runnerContainer.Env = append(runnerContainer.Env, []corev1.EnvVar{
|
||||||
@@ -876,6 +674,15 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default
|
|||||||
}...)
|
}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(pod.Spec.ImagePullSecrets) == 0 && len(defaultRunnerImagePullSecrets) > 0 {
|
||||||
|
// runner spec didn't provide custom values and default image pull secrets are provided
|
||||||
|
for _, imagePullSecret := range defaultRunnerImagePullSecrets {
|
||||||
|
pod.Spec.ImagePullSecrets = append(pod.Spec.ImagePullSecrets, corev1.LocalObjectReference{
|
||||||
|
Name: imagePullSecret,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if dockerRegistryMirror != "" && dockerdInRunner {
|
if dockerRegistryMirror != "" && dockerdInRunner {
|
||||||
runnerContainer.Env = append(runnerContainer.Env, []corev1.EnvVar{
|
runnerContainer.Env = append(runnerContainer.Env, []corev1.EnvVar{
|
||||||
{
|
{
|
||||||
@@ -934,13 +741,18 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pod.Spec.Volumes = append(pod.Spec.Volumes,
|
if ok, _ := workVolumePresent(pod.Spec.Volumes); !ok {
|
||||||
corev1.Volume{
|
pod.Spec.Volumes = append(pod.Spec.Volumes,
|
||||||
Name: "work",
|
corev1.Volume{
|
||||||
VolumeSource: corev1.VolumeSource{
|
Name: "work",
|
||||||
EmptyDir: &corev1.EmptyDirVolumeSource{},
|
VolumeSource: corev1.VolumeSource{
|
||||||
|
EmptyDir: &corev1.EmptyDirVolumeSource{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pod.Spec.Volumes = append(pod.Spec.Volumes,
|
||||||
corev1.Volume{
|
corev1.Volume{
|
||||||
Name: "certs-client",
|
Name: "certs-client",
|
||||||
VolumeSource: corev1.VolumeSource{
|
VolumeSource: corev1.VolumeSource{
|
||||||
@@ -948,17 +760,24 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if ok, _ := workVolumeMountPresent(runnerContainer.VolumeMounts); !ok {
|
||||||
|
runnerContainer.VolumeMounts = append(runnerContainer.VolumeMounts,
|
||||||
|
corev1.VolumeMount{
|
||||||
|
Name: "work",
|
||||||
|
MountPath: workDir,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
runnerContainer.VolumeMounts = append(runnerContainer.VolumeMounts,
|
runnerContainer.VolumeMounts = append(runnerContainer.VolumeMounts,
|
||||||
corev1.VolumeMount{
|
|
||||||
Name: "work",
|
|
||||||
MountPath: workDir,
|
|
||||||
},
|
|
||||||
corev1.VolumeMount{
|
corev1.VolumeMount{
|
||||||
Name: "certs-client",
|
Name: "certs-client",
|
||||||
MountPath: "/certs/client",
|
MountPath: "/certs/client",
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
runnerContainer.Env = append(runnerContainer.Env, []corev1.EnvVar{
|
runnerContainer.Env = append(runnerContainer.Env, []corev1.EnvVar{
|
||||||
{
|
{
|
||||||
Name: "DOCKER_HOST",
|
Name: "DOCKER_HOST",
|
||||||
@@ -977,10 +796,6 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default
|
|||||||
// Determine the volume mounts assigned to the docker sidecar. In case extra mounts are included in the RunnerSpec, append them to the standard
|
// Determine the volume mounts assigned to the docker sidecar. In case extra mounts are included in the RunnerSpec, append them to the standard
|
||||||
// set of mounts. See https://github.com/actions-runner-controller/actions-runner-controller/issues/435 for context.
|
// set of mounts. See https://github.com/actions-runner-controller/actions-runner-controller/issues/435 for context.
|
||||||
dockerVolumeMounts := []corev1.VolumeMount{
|
dockerVolumeMounts := []corev1.VolumeMount{
|
||||||
{
|
|
||||||
Name: "work",
|
|
||||||
MountPath: workDir,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Name: runnerVolumeName,
|
Name: runnerVolumeName,
|
||||||
MountPath: runnerVolumeMountPath,
|
MountPath: runnerVolumeMountPath,
|
||||||
@@ -991,6 +806,14 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mountPresent, _ := workVolumeMountPresent(dockerdContainer.VolumeMounts)
|
||||||
|
if !mountPresent {
|
||||||
|
dockerVolumeMounts = append(dockerVolumeMounts, corev1.VolumeMount{
|
||||||
|
Name: "work",
|
||||||
|
MountPath: workDir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if dockerdContainer.Image == "" {
|
if dockerdContainer.Image == "" {
|
||||||
dockerdContainer.Image = defaultDockerImage
|
dockerdContainer.Image = defaultDockerImage
|
||||||
}
|
}
|
||||||
@@ -1096,3 +919,21 @@ func removeFinalizer(finalizers []string, finalizerName string) ([]string, bool)
|
|||||||
|
|
||||||
return result, removed
|
return result, removed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func workVolumePresent(items []corev1.Volume) (bool, int) {
|
||||||
|
for index, item := range items {
|
||||||
|
if item.Name == "work" {
|
||||||
|
return true, index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func workVolumeMountPresent(items []corev1.VolumeMount) (bool, int) {
|
||||||
|
for index, item := range items {
|
||||||
|
if item.Name == "work" {
|
||||||
|
return true, index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, 0
|
||||||
|
}
|
||||||
|
|||||||
414
controllers/runner_graceful_stop.go
Normal file
414
controllers/runner_graceful_stop.go
Normal file
@@ -0,0 +1,414 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/actions-runner-controller/actions-runner-controller/github"
|
||||||
|
"github.com/go-logr/logr"
|
||||||
|
gogithub "github.com/google/go-github/v39/github"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
// tickRunnerGracefulStop reconciles the runner and the runner pod in a way so that
|
||||||
|
// we can delete the runner pod without disrupting a workflow job.
|
||||||
|
//
|
||||||
|
// This function returns a non-nil pointer to corev1.Pod as the first return value
|
||||||
|
// if the runner is considered to have gracefully stopped, hence it's pod is safe for deletion.
|
||||||
|
//
|
||||||
|
// It's a "tick" operation so a graceful stop can take multiple calls to complete.
|
||||||
|
// This function is designed to complete a lengthy graceful stop process in a unblocking way.
|
||||||
|
// When it wants to be retried later, the function returns a non-nil *ctrl.Result as the second return value, may or may not populating the error in the second return value.
|
||||||
|
// The caller is expected to return the returned ctrl.Result and error to postpone the current reconcilation loop and trigger a scheduled retry.
|
||||||
|
func tickRunnerGracefulStop(ctx context.Context, retryDelay time.Duration, log logr.Logger, ghClient *github.Client, c client.Client, enterprise, organization, repository, runner string, pod *corev1.Pod) (*corev1.Pod, *ctrl.Result, error) {
|
||||||
|
pod, err := annotatePodOnce(ctx, c, log, pod, AnnotationKeyUnregistrationStartTimestamp, time.Now().Format(time.RFC3339))
|
||||||
|
if err != nil {
|
||||||
|
return nil, &ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if res, err := ensureRunnerUnregistration(ctx, retryDelay, log, ghClient, c, enterprise, organization, repository, runner, pod); res != nil {
|
||||||
|
return nil, res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pod, err = annotatePodOnce(ctx, c, log, pod, AnnotationKeyUnregistrationCompleteTimestamp, time.Now().Format(time.RFC3339))
|
||||||
|
if err != nil {
|
||||||
|
return nil, &ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return pod, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// annotatePodOnce annotates the pod if it wasn't.
|
||||||
|
// Returns the provided pod as-is if it was already annotated.
|
||||||
|
// Returns the updated pod if the pod was missing the annotation and the update to add the annotation succeeded.
|
||||||
|
func annotatePodOnce(ctx context.Context, c client.Client, log logr.Logger, pod *corev1.Pod, k, v string) (*corev1.Pod, error) {
|
||||||
|
if pod == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := getAnnotation(pod, k); ok {
|
||||||
|
return pod, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
updated := pod.DeepCopy()
|
||||||
|
setAnnotation(&updated.ObjectMeta, k, v)
|
||||||
|
if err := c.Patch(ctx, updated, client.MergeFrom(pod)); err != nil {
|
||||||
|
log.Error(err, fmt.Sprintf("Failed to patch pod to have %s annotation", k))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(2).Info("Annotated pod", "key", k, "value", v)
|
||||||
|
|
||||||
|
return updated, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the first return value is nil, it's safe to delete the runner pod.
|
||||||
|
func ensureRunnerUnregistration(ctx context.Context, retryDelay time.Duration, log logr.Logger, ghClient *github.Client, c client.Client, enterprise, organization, repository, runner string, pod *corev1.Pod) (*ctrl.Result, error) {
|
||||||
|
var runnerID *int64
|
||||||
|
|
||||||
|
if id, ok := getAnnotation(pod, AnnotationKeyRunnerID); ok {
|
||||||
|
v, err := strconv.ParseInt(id, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return &ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
runnerID = &v
|
||||||
|
}
|
||||||
|
|
||||||
|
if runnerID == nil {
|
||||||
|
runner, err := getRunner(ctx, ghClient, enterprise, organization, repository, runner)
|
||||||
|
if err != nil {
|
||||||
|
return &ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if runner != nil && runner.ID != nil {
|
||||||
|
runnerID = runner.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
code := runnerContainerExitCode(pod)
|
||||||
|
|
||||||
|
if pod != nil && pod.Annotations[AnnotationKeyUnregistrationCompleteTimestamp] != "" {
|
||||||
|
// If it's already unregistered in the previous reconcilation loop,
|
||||||
|
// you can safely assume that it won't get registered again so it's safe to delete the runner pod.
|
||||||
|
log.Info("Runner pod is marked as already unregistered.")
|
||||||
|
} else if runnerID == nil {
|
||||||
|
log.Info(
|
||||||
|
"Unregistration started before runner ID is assigned. " +
|
||||||
|
"Perhaps the runner pod was terminated by anyone other than ARC? Was it OOM killed? " +
|
||||||
|
"Marking unregistration as completed anyway because there's nothing ARC can do.",
|
||||||
|
)
|
||||||
|
} else if pod != nil && runnerPodOrContainerIsStopped(pod) {
|
||||||
|
// If it's an ephemeral runner with the actions/runner container exited with 0,
|
||||||
|
// we can safely assume that it has unregistered itself from GitHub Actions
|
||||||
|
// so it's natural that RemoveRunner fails due to 404.
|
||||||
|
|
||||||
|
// If pod has ended up succeeded we need to restart it
|
||||||
|
// Happens e.g. when dind is in runner and run completes
|
||||||
|
log.Info("Runner pod has been stopped with a successful status.")
|
||||||
|
} else if pod != nil && pod.Annotations[AnnotationKeyRunnerCompletionWaitStartTimestamp] != "" {
|
||||||
|
ct := ephemeralRunnerContainerStatus(pod)
|
||||||
|
if ct == nil {
|
||||||
|
log.Info("Runner pod is annotated to wait for completion, and the runner container is not ephemeral")
|
||||||
|
|
||||||
|
return &ctrl.Result{RequeueAfter: retryDelay}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
lts := ct.LastTerminationState.Terminated
|
||||||
|
if lts == nil {
|
||||||
|
log.Info("Runner pod is annotated to wait for completion, and the runner container is not restarting")
|
||||||
|
|
||||||
|
return &ctrl.Result{RequeueAfter: retryDelay}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent runner pod from stucking in Terminating.
|
||||||
|
// See https://github.com/actions-runner-controller/actions-runner-controller/issues/1369
|
||||||
|
log.Info("Deleting runner pod anyway because it has stopped prematurely. This may leave a dangling runner resource in GitHub Actions",
|
||||||
|
"lastState.exitCode", lts.ExitCode,
|
||||||
|
"lastState.message", lts.Message,
|
||||||
|
"pod.phase", pod.Status.Phase,
|
||||||
|
)
|
||||||
|
} else if ok, err := unregisterRunner(ctx, ghClient, enterprise, organization, repository, *runnerID); err != nil {
|
||||||
|
if errors.Is(err, &gogithub.RateLimitError{}) {
|
||||||
|
// We log the underlying error when we failed calling GitHub API to list or unregisters,
|
||||||
|
// or the runner is still busy.
|
||||||
|
log.Error(
|
||||||
|
err,
|
||||||
|
fmt.Sprintf(
|
||||||
|
"Failed to unregister runner due to GitHub API rate limits. Delaying retry for %s to avoid excessive GitHub API calls",
|
||||||
|
retryDelayOnGitHubAPIRateLimitError,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
return &ctrl.Result{RequeueAfter: retryDelayOnGitHubAPIRateLimitError}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(1).Info("Failed to unregister runner before deleting the pod.", "error", err)
|
||||||
|
|
||||||
|
var runnerBusy bool
|
||||||
|
|
||||||
|
errRes := &gogithub.ErrorResponse{}
|
||||||
|
if errors.As(err, &errRes) {
|
||||||
|
if errRes.Response.StatusCode == 403 {
|
||||||
|
log.Error(err, "Unable to unregister due to permission error. "+
|
||||||
|
"Perhaps you've changed the permissions of PAT or GitHub App, or you updated authentication method of ARC in a wrong way? "+
|
||||||
|
"ARC considers it as already unregistered and continue removing the pod. "+
|
||||||
|
"You may need to remove the runner on GitHub UI.")
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
runner, _ := getRunner(ctx, ghClient, enterprise, organization, repository, runner)
|
||||||
|
|
||||||
|
var runnerID int64
|
||||||
|
|
||||||
|
if runner != nil && runner.ID != nil {
|
||||||
|
runnerID = *runner.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
runnerBusy = errRes.Response.StatusCode == 422
|
||||||
|
|
||||||
|
if runnerBusy && code != nil {
|
||||||
|
log.V(2).Info("Runner container has already stopped but the unregistration attempt failed. "+
|
||||||
|
"This can happen when the runner container crashed due to an unhandled error, OOM, etc. "+
|
||||||
|
"ARC terminates the pod anyway. You'd probably need to manually delete the runner later by calling the GitHub API",
|
||||||
|
"runnerExitCode", *code,
|
||||||
|
"runnerID", runnerID,
|
||||||
|
)
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if runnerBusy {
|
||||||
|
// We want to prevent spamming the deletion attemps but returning ctrl.Result with RequeueAfter doesn't
|
||||||
|
// work as the reconcilation can happen earlier due to pod status update.
|
||||||
|
// For ephemeral runners, we can expect it to stop and unregister itself on completion.
|
||||||
|
// So we can just wait for the completion without actively retrying unregistration.
|
||||||
|
ephemeral := getRunnerEnv(pod, EnvVarEphemeral)
|
||||||
|
if ephemeral == "true" {
|
||||||
|
_, err = annotatePodOnce(ctx, c, log, pod, AnnotationKeyRunnerCompletionWaitStartTimestamp, time.Now().Format(time.RFC3339))
|
||||||
|
if err != nil {
|
||||||
|
return &ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(2).Info("Retrying runner unregistration because the static runner is still busy")
|
||||||
|
// Otherwise we may end up spamming 422 errors,
|
||||||
|
// each call consuming GitHub API rate limit
|
||||||
|
// https://github.com/actions-runner-controller/actions-runner-controller/pull/1167#issuecomment-1064213271
|
||||||
|
return &ctrl.Result{RequeueAfter: retryDelay}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ctrl.Result{}, err
|
||||||
|
} else if ok {
|
||||||
|
log.Info("Runner has just been unregistered.")
|
||||||
|
} else if pod == nil {
|
||||||
|
// `r.unregisterRunner()` will returns `false, nil` if the runner is not found on GitHub.
|
||||||
|
// However, that doesn't always mean the pod can be safely removed.
|
||||||
|
//
|
||||||
|
// If the pod does not exist for the runner,
|
||||||
|
// it may be due to that the runner pod has never been created.
|
||||||
|
// In that case we can safely assume that the runner will never be registered.
|
||||||
|
|
||||||
|
log.Info("Runner was not found on GitHub and the runner pod was not found on Kuberntes.")
|
||||||
|
} else if ts := pod.Annotations[AnnotationKeyUnregistrationStartTimestamp]; ts != "" {
|
||||||
|
log.Info("Runner unregistration is in-progress. It can take forever to complete if if it's a static runner constantly running jobs."+
|
||||||
|
" It can also take very long time if it's an ephemeral runner that is running a log-running job.", "error", err)
|
||||||
|
|
||||||
|
return &ctrl.Result{RequeueAfter: retryDelay}, nil
|
||||||
|
} else {
|
||||||
|
// A runner and a runner pod that is created by this version of ARC should match
|
||||||
|
// any of the above branches.
|
||||||
|
//
|
||||||
|
// But we leave this match all branch for potential backward-compatibility.
|
||||||
|
// The caller is expected to take appropriate actions, like annotating the pod as started the unregistration process,
|
||||||
|
// and retry later.
|
||||||
|
log.V(1).Info("Runner unregistration is being retried later.")
|
||||||
|
|
||||||
|
return &ctrl.Result{RequeueAfter: retryDelay}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ensureRunnerPodRegistered(ctx context.Context, log logr.Logger, ghClient *github.Client, c client.Client, enterprise, organization, repository, runner string, pod *corev1.Pod) (*corev1.Pod, *ctrl.Result, error) {
|
||||||
|
_, hasRunnerID := getAnnotation(pod, AnnotationKeyRunnerID)
|
||||||
|
if runnerPodOrContainerIsStopped(pod) || hasRunnerID {
|
||||||
|
return pod, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := getRunner(ctx, ghClient, enterprise, organization, repository, runner)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &ctrl.Result{RequeueAfter: 10 * time.Second}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if r == nil || r.ID == nil {
|
||||||
|
return nil, &ctrl.Result{RequeueAfter: 10 * time.Second}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
id := *r.ID
|
||||||
|
|
||||||
|
updated, err := annotatePodOnce(ctx, c, log, pod, AnnotationKeyRunnerID, fmt.Sprintf("%d", id))
|
||||||
|
if err != nil {
|
||||||
|
return nil, &ctrl.Result{RequeueAfter: 10 * time.Second}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return updated, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAnnotation(obj client.Object, key string) (string, bool) {
|
||||||
|
if obj.GetAnnotations() == nil {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
v, ok := obj.GetAnnotations()[key]
|
||||||
|
|
||||||
|
return v, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func setAnnotation(meta *metav1.ObjectMeta, key, value string) {
|
||||||
|
if meta.Annotations == nil {
|
||||||
|
meta.Annotations = map[string]string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
meta.Annotations[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
func podConditionTransitionTime(pod *corev1.Pod, tpe corev1.PodConditionType, v corev1.ConditionStatus) *metav1.Time {
|
||||||
|
for _, c := range pod.Status.Conditions {
|
||||||
|
if c.Type == tpe && c.Status == v {
|
||||||
|
return &c.LastTransitionTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func podConditionTransitionTimeAfter(pod *corev1.Pod, tpe corev1.PodConditionType, d time.Duration) bool {
|
||||||
|
c := podConditionTransitionTime(pod, tpe, corev1.ConditionTrue)
|
||||||
|
if c == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Add(d).Before(time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
|
func podRunnerID(pod *corev1.Pod) string {
|
||||||
|
id, _ := getAnnotation(pod, AnnotationKeyRunnerID)
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRunnerEnv(pod *corev1.Pod, key string) string {
|
||||||
|
for _, c := range pod.Spec.Containers {
|
||||||
|
if c.Name == containerName {
|
||||||
|
for _, e := range c.Env {
|
||||||
|
if e.Name == key {
|
||||||
|
return e.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func setRunnerEnv(pod *corev1.Pod, key, value string) {
|
||||||
|
for i := range pod.Spec.Containers {
|
||||||
|
c := pod.Spec.Containers[i]
|
||||||
|
if c.Name == containerName {
|
||||||
|
for j, env := range c.Env {
|
||||||
|
if env.Name == key {
|
||||||
|
pod.Spec.Containers[i].Env[j].Value = value
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pod.Spec.Containers[i].Env = append(c.Env, corev1.EnvVar{Name: key, Value: value})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unregisterRunner unregisters the runner from GitHub Actions by name.
|
||||||
|
//
|
||||||
|
// This function returns:
|
||||||
|
//
|
||||||
|
// Case 1. (true, nil) when it has successfully unregistered the runner.
|
||||||
|
// Case 2. (false, nil) when (2-1.) the runner has been already unregistered OR (2-2.) the runner will never be created OR (2-3.) the runner is not created yet and it is about to be registered(hence we couldn't see it's existence from GitHub Actions API yet)
|
||||||
|
// Case 3. (false, err) when it postponed unregistration due to the runner being busy, or it tried to unregister the runner but failed due to
|
||||||
|
// an error returned by GitHub API.
|
||||||
|
//
|
||||||
|
// When the returned values is "Case 2. (false, nil)", the caller must handle the three possible sub-cases appropriately.
|
||||||
|
// In other words, all those three sub-cases cannot be distinguished by this function alone.
|
||||||
|
//
|
||||||
|
// - Case "2-1." can happen when e.g. ARC has successfully unregistered in a previous reconcilation loop or it was an ephemeral runner that finished it's job run(an ephemeral runner is designed to stop after a job run).
|
||||||
|
// You'd need to maintain the runner state(i.e. if it's already unregistered or not) somewhere,
|
||||||
|
// so that you can either not call this function at all if the runner state says it's already unregistered, or determine that it's case "2-1." when you got (false, nil).
|
||||||
|
//
|
||||||
|
// - Case "2-2." can happen when e.g. the runner registration token was somehow broken so that `config.sh` within the runner container was never meant to succeed.
|
||||||
|
// Waiting and retrying forever on this case is not a solution, because `config.sh` won't succeed with a wrong token hence the runner gets stuck in this state forever.
|
||||||
|
// There isn't a perfect solution to this, but a practical workaround would be implement a "grace period" in the caller side.
|
||||||
|
//
|
||||||
|
// - Case "2-3." can happen when e.g. ARC recreated an ephemral runner pod in a previous reconcilation loop and then it was requested to delete the runner before the runner comes up.
|
||||||
|
// If handled inappropriately, this can cause a race condition betweeen a deletion of the runner pod and GitHub scheduling a workflow job onto the runner.
|
||||||
|
//
|
||||||
|
// Once successfully detected case "2-1." or "2-2.", you can safely delete the runner pod because you know that the runner won't come back
|
||||||
|
// as long as you recreate the runner pod.
|
||||||
|
//
|
||||||
|
// If it was "2-3.", you need a workaround to avoid the race condition.
|
||||||
|
//
|
||||||
|
// You shall introduce a "grace period" mechanism, similar or equal to that is required for "Case 2-2.", so that you ever
|
||||||
|
// start the runner pod deletion only after it's more and more likely that the runner pod is not coming up.
|
||||||
|
//
|
||||||
|
// Beware though, you need extra care to set an appropriate grace period depending on your environment.
|
||||||
|
// There isn't a single right grace period that works for everyone.
|
||||||
|
// The longer the grace period is, the earlier a cluster resource shortage can occur due to throttoled runner pod deletions,
|
||||||
|
// while the shorter the grace period is, the more likely you may encounter the race issue.
|
||||||
|
func unregisterRunner(ctx context.Context, client *github.Client, enterprise, org, repo string, id int64) (bool, error) {
|
||||||
|
// For the record, historically ARC did not try to call RemoveRunner on a busy runner, but it's no longer true.
|
||||||
|
// The reason ARC did so was to let a runner running a job to not stop prematurely.
|
||||||
|
//
|
||||||
|
// However, we learned that RemoveRunner already has an ability to prevent stopping a busy runner,
|
||||||
|
// so ARC doesn't need to do anything special for a graceful runner stop.
|
||||||
|
// It can just call RemoveRunner, and if it returned 200 you're guaranteed that the runner will not automatically come back and
|
||||||
|
// the runner pod is safe for deletion.
|
||||||
|
//
|
||||||
|
// Trying to remove a busy runner can result in errors like the following:
|
||||||
|
// failed to remove runner: DELETE https://api.github.com/repos/actions-runner-controller/mumoshu-actions-test/actions/runners/47: 422 Bad request - Runner \"example-runnerset-0\" is still running a job\" []
|
||||||
|
//
|
||||||
|
// # NOTES
|
||||||
|
//
|
||||||
|
// - It can be "status=offline" at the same time but that's another story.
|
||||||
|
// - After https://github.com/actions-runner-controller/actions-runner-controller/pull/1127, ListRunners responses that are used to
|
||||||
|
// determine if the runner is busy can be more outdated than before, as those responeses are now cached for 60 seconds.
|
||||||
|
// - Note that 60 seconds is controlled by the Cache-Control response header provided by GitHub so we don't have a strict control on it but we assume it won't
|
||||||
|
// change from 60 seconds.
|
||||||
|
//
|
||||||
|
// TODO: Probably we can just remove the runner by ID without seeing if the runner is busy, by treating it as busy when a remove-runner call failed with 422?
|
||||||
|
if err := client.RemoveRunner(ctx, enterprise, org, repo, id); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRunner(ctx context.Context, client *github.Client, enterprise, org, repo, name string) (*gogithub.Runner, error) {
|
||||||
|
runners, err := client.ListRunners(ctx, enterprise, org, repo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, runner := range runners {
|
||||||
|
if runner.GetName() == name {
|
||||||
|
return runner, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
22
controllers/runner_pod.go
Normal file
22
controllers/runner_pod.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import corev1 "k8s.io/api/core/v1"
|
||||||
|
|
||||||
|
// Force the runner pod managed by either RunnerDeployment and RunnerSet to have restartPolicy=Never.
|
||||||
|
// See https://github.com/actions-runner-controller/actions-runner-controller/issues/1369 for more context.
|
||||||
|
//
|
||||||
|
// This is to prevent runner pods from stucking in Terminating when a K8s node disappeared along with the runnr pod and the runner container within it.
|
||||||
|
//
|
||||||
|
// Previously, we used restartPolicy of OnFailure, it turned wrong later, and therefore we now set Never.
|
||||||
|
//
|
||||||
|
// When the restartPolicy is OnFailure and the node disappeared, runner pods on the node seem to stuck in state.terminated==nil, state.waiting!=nil, and state.lastTerminationState!=nil,
|
||||||
|
// and will ever become Running.
|
||||||
|
// It's probably due to that the node onto which the pods have been scheduled will ever come back, hence the container restart attempt swill ever succeed,
|
||||||
|
// the pods stuck waiting for successful restarts forever.
|
||||||
|
//
|
||||||
|
// By forcing runner pods to never restart, we hope there will be no chances of pods being stuck waiting.
|
||||||
|
func forceRunnerPodRestartPolicyNever(pod *corev1.Pod) {
|
||||||
|
if pod.Spec.RestartPolicy != corev1.RestartPolicyNever {
|
||||||
|
pod.Spec.RestartPolicy = corev1.RestartPolicyNever
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,10 +22,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
gogithub "github.com/google/go-github/v37/github"
|
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
|
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
|
|
||||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
@@ -47,16 +45,10 @@ type RunnerPodReconciler struct {
|
|||||||
Name string
|
Name string
|
||||||
RegistrationRecheckInterval time.Duration
|
RegistrationRecheckInterval time.Duration
|
||||||
RegistrationRecheckJitter time.Duration
|
RegistrationRecheckJitter time.Duration
|
||||||
|
|
||||||
|
UnregistrationRetryDelay time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
// This names requires at least one slash to work.
|
|
||||||
// See https://github.com/google/knative-gcp/issues/378
|
|
||||||
runnerPodFinalizerName = "actions.summerwind.dev/runner-pod"
|
|
||||||
|
|
||||||
AnnotationKeyLastRegistrationCheckTime = "actions-runner-controller/last-registration-check-time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;update;patch;delete
|
// +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;update;patch;delete
|
||||||
// +kubebuilder:rbac:groups=core,resources=events,verbs=create;patch
|
// +kubebuilder:rbac:groups=core,resources=events,verbs=create;patch
|
||||||
|
|
||||||
@@ -73,9 +65,19 @@ func (r *RunnerPodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
|
|||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var envvars []corev1.EnvVar
|
||||||
|
for _, container := range runnerPod.Spec.Containers {
|
||||||
|
if container.Name == "runner" {
|
||||||
|
envvars = container.Env
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(envvars) == 0 {
|
||||||
|
return ctrl.Result{}, errors.New("Could not determine env vars for runner Pod")
|
||||||
|
}
|
||||||
|
|
||||||
var enterprise, org, repo string
|
var enterprise, org, repo string
|
||||||
|
|
||||||
envvars := runnerPod.Spec.Containers[0].Env
|
|
||||||
for _, e := range envvars {
|
for _, e := range envvars {
|
||||||
switch e.Name {
|
switch e.Name {
|
||||||
case EnvVarEnterprise:
|
case EnvVarEnterprise:
|
||||||
@@ -99,44 +101,36 @@ func (r *RunnerPodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
|
|||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.V(2).Info("Added finalizer")
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
log.V(2).Info("Seen deletion-timestamp is already set")
|
||||||
|
|
||||||
finalizers, removed := removeFinalizer(runnerPod.ObjectMeta.Finalizers, runnerPodFinalizerName)
|
finalizers, removed := removeFinalizer(runnerPod.ObjectMeta.Finalizers, runnerPodFinalizerName)
|
||||||
|
|
||||||
if removed {
|
if removed {
|
||||||
ok, err := r.unregisterRunner(ctx, enterprise, org, repo, runnerPod.Name)
|
// In a standard scenario, the upstream controller, like runnerset-controller, ensures this runner to be gracefully stopped before the deletion timestamp is set.
|
||||||
if err != nil {
|
// But for the case that the user manually deleted it for whatever reason,
|
||||||
if errors.Is(err, &gogithub.RateLimitError{}) {
|
// we have to ensure it to gracefully stop now.
|
||||||
// We log the underlying error when we failed calling GitHub API to list or unregisters,
|
updatedPod, res, err := tickRunnerGracefulStop(ctx, r.unregistrationRetryDelay(), log, r.GitHubClient, r.Client, enterprise, org, repo, runnerPod.Name, &runnerPod)
|
||||||
// or the runner is still busy.
|
if res != nil {
|
||||||
log.Error(
|
return *res, err
|
||||||
err,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"Failed to unregister runner due to GitHub API rate limits. Delaying retry for %s to avoid excessive GitHub API calls",
|
|
||||||
retryDelayOnGitHubAPIRateLimitError,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
return ctrl.Result{RequeueAfter: retryDelayOnGitHubAPIRateLimitError}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
patchedPod := updatedPod.DeepCopy()
|
||||||
log.V(1).Info("Runner no longer exists on GitHub")
|
patchedPod.ObjectMeta.Finalizers = finalizers
|
||||||
}
|
|
||||||
|
|
||||||
newRunner := runnerPod.DeepCopy()
|
// We commit the removal of the finalizer so that Kuberenetes notices it and delete the pod resource from the cluster.
|
||||||
newRunner.ObjectMeta.Finalizers = finalizers
|
if err := r.Patch(ctx, patchedPod, client.MergeFrom(&runnerPod)); err != nil {
|
||||||
|
|
||||||
if err := r.Patch(ctx, newRunner, client.MergeFrom(&runnerPod)); err != nil {
|
|
||||||
log.Error(err, "Failed to update runner for finalizer removal")
|
log.Error(err, "Failed to update runner for finalizer removal")
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Removed runner from GitHub", "repository", repo, "organization", org)
|
log.V(2).Info("Removed finalizer")
|
||||||
|
|
||||||
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
deletionTimeout := 1 * time.Minute
|
deletionTimeout := 1 * time.Minute
|
||||||
@@ -174,246 +168,45 @@ func (r *RunnerPodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
|
|||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If pod has ended up succeeded we need to restart it
|
po, res, err := ensureRunnerPodRegistered(ctx, log, r.GitHubClient, r.Client, enterprise, org, repo, runnerPod.Name, &runnerPod)
|
||||||
// Happens e.g. when dind is in runner and run completes
|
if res != nil {
|
||||||
stopped := runnerPod.Status.Phase == corev1.PodSucceeded
|
return *res, err
|
||||||
|
|
||||||
if !stopped {
|
|
||||||
if runnerPod.Status.Phase == corev1.PodRunning {
|
|
||||||
for _, status := range runnerPod.Status.ContainerStatuses {
|
|
||||||
if status.Name != containerName {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if status.State.Terminated != nil && status.State.Terminated.ExitCode == 0 {
|
|
||||||
stopped = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
restart := stopped
|
runnerPod = *po
|
||||||
|
|
||||||
var registrationRecheckDelay time.Duration
|
if _, unregistrationRequested := getAnnotation(&runnerPod, AnnotationKeyUnregistrationRequestTimestamp); unregistrationRequested {
|
||||||
|
log.V(2).Info("Progressing unregistration because unregistration-request timestamp is set")
|
||||||
|
|
||||||
// all checks done below only decide whether a restart is needed
|
// At this point we're sure that DeletionTimestamp is not set yet, but the unregistration process is triggered by an upstream controller like runnerset-controller.
|
||||||
// if a restart was already decided before, there is no need for the checks
|
//
|
||||||
// saving API calls and scary log messages
|
// In a standard scenario, ARC starts the unregistration process before marking the pod for deletion at all,
|
||||||
if !restart {
|
// so that it isn't subject to terminationGracePeriod and can safely take hours to finish it's work.
|
||||||
registrationCheckInterval := time.Minute
|
_, res, err := tickRunnerGracefulStop(ctx, r.unregistrationRetryDelay(), log, r.GitHubClient, r.Client, enterprise, org, repo, runnerPod.Name, &runnerPod)
|
||||||
if r.RegistrationRecheckInterval > 0 {
|
if res != nil {
|
||||||
registrationCheckInterval = r.RegistrationRecheckInterval
|
return *res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
lastCheckTimeStr := runnerPod.Annotations[AnnotationKeyLastRegistrationCheckTime]
|
// At this point we are sure that the runner has successfully unregistered, hence is safe to be deleted.
|
||||||
|
// But we don't delete the pod here. Instead, let the upstream controller/parent object to delete this pod as
|
||||||
var lastCheckTime *time.Time
|
// a part of a cascade deletion.
|
||||||
|
// This is to avoid a parent object, like statefulset, to recreate the deleted pod.
|
||||||
if lastCheckTimeStr != "" {
|
// If the pod was recreated, it will start a registration process and that may race with the statefulset deleting the pod.
|
||||||
t, err := time.Parse(time.RFC3339, lastCheckTimeStr)
|
log.V(2).Info("Unregistration seems complete")
|
||||||
if err != nil {
|
|
||||||
log.Error(err, "failed to parase last check time %q", lastCheckTimeStr)
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
lastCheckTime = &t
|
|
||||||
}
|
|
||||||
|
|
||||||
// We want to call ListRunners GitHub Actions API only once per runner per minute.
|
|
||||||
// This if block, in conjunction with:
|
|
||||||
// return ctrl.Result{RequeueAfter: registrationRecheckDelay}, nil
|
|
||||||
// achieves that.
|
|
||||||
if lastCheckTime != nil {
|
|
||||||
nextCheckTime := lastCheckTime.Add(registrationCheckInterval)
|
|
||||||
now := time.Now()
|
|
||||||
|
|
||||||
// Requeue scheduled by RequeueAfter can happen a bit earlier (like dozens of milliseconds)
|
|
||||||
// so to avoid excessive, in-effective retry, we heuristically ignore the remaining delay in case it is
|
|
||||||
// shorter than 1s
|
|
||||||
requeueAfter := nextCheckTime.Sub(now) - time.Second
|
|
||||||
if requeueAfter > 0 {
|
|
||||||
log.Info(
|
|
||||||
fmt.Sprintf("Skipped registration check because it's deferred until %s. Retrying in %s at latest", nextCheckTime, requeueAfter),
|
|
||||||
"lastRegistrationCheckTime", lastCheckTime,
|
|
||||||
"registrationCheckInterval", registrationCheckInterval,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Without RequeueAfter, the controller may not retry on scheduled. Instead, it must wait until the
|
|
||||||
// next sync period passes, which can be too much later than nextCheckTime.
|
|
||||||
//
|
|
||||||
// We need to requeue on this reconcilation even though we have already scheduled the initial
|
|
||||||
// requeue previously with `return ctrl.Result{RequeueAfter: registrationRecheckDelay}, nil`.
|
|
||||||
// Apparently, the workqueue used by controller-runtime seems to deduplicate and resets the delay on
|
|
||||||
// other requeues- so the initial scheduled requeue may have been reset due to requeue on
|
|
||||||
// spec/status change.
|
|
||||||
return ctrl.Result{RequeueAfter: requeueAfter}, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notFound := false
|
|
||||||
offline := false
|
|
||||||
|
|
||||||
_, err := r.GitHubClient.IsRunnerBusy(ctx, enterprise, org, repo, runnerPod.Name)
|
|
||||||
|
|
||||||
currentTime := time.Now()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
var notFoundException *github.RunnerNotFound
|
|
||||||
var offlineException *github.RunnerOffline
|
|
||||||
if errors.As(err, ¬FoundException) {
|
|
||||||
notFound = true
|
|
||||||
} else if errors.As(err, &offlineException) {
|
|
||||||
offline = true
|
|
||||||
} else {
|
|
||||||
var e *gogithub.RateLimitError
|
|
||||||
if errors.As(err, &e) {
|
|
||||||
// We log the underlying error when we failed calling GitHub API to list or unregisters,
|
|
||||||
// or the runner is still busy.
|
|
||||||
log.Error(
|
|
||||||
err,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"Failed to check if runner is busy due to Github API rate limit. Retrying in %s to avoid excessive GitHub API calls",
|
|
||||||
retryDelayOnGitHubAPIRateLimitError,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
return ctrl.Result{RequeueAfter: retryDelayOnGitHubAPIRateLimitError}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
registrationTimeout := 10 * time.Minute
|
|
||||||
durationAfterRegistrationTimeout := currentTime.Sub(runnerPod.CreationTimestamp.Add(registrationTimeout))
|
|
||||||
registrationDidTimeout := durationAfterRegistrationTimeout > 0
|
|
||||||
|
|
||||||
if notFound {
|
|
||||||
if registrationDidTimeout {
|
|
||||||
log.Info(
|
|
||||||
"Runner failed to register itself to GitHub in timely manner. "+
|
|
||||||
"Recreating the pod to see if it resolves the issue. "+
|
|
||||||
"CAUTION: If you see this a lot, you should investigate the root cause. "+
|
|
||||||
"See https://github.com/actions-runner-controller/actions-runner-controller/issues/288",
|
|
||||||
"podCreationTimestamp", runnerPod.CreationTimestamp,
|
|
||||||
"currentTime", currentTime,
|
|
||||||
"configuredRegistrationTimeout", registrationTimeout,
|
|
||||||
)
|
|
||||||
|
|
||||||
restart = true
|
|
||||||
} else {
|
|
||||||
log.V(1).Info(
|
|
||||||
"Runner pod exists but we failed to check if runner is busy. Apparently it still needs more time.",
|
|
||||||
"runnerName", runnerPod.Name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else if offline {
|
|
||||||
if registrationDidTimeout {
|
|
||||||
log.Info(
|
|
||||||
"Already existing GitHub runner still appears offline . "+
|
|
||||||
"Recreating the pod to see if it resolves the issue. "+
|
|
||||||
"CAUTION: If you see this a lot, you should investigate the root cause. ",
|
|
||||||
"podCreationTimestamp", runnerPod.CreationTimestamp,
|
|
||||||
"currentTime", currentTime,
|
|
||||||
"configuredRegistrationTimeout", registrationTimeout,
|
|
||||||
)
|
|
||||||
|
|
||||||
restart = true
|
|
||||||
} else {
|
|
||||||
log.V(1).Info(
|
|
||||||
"Runner pod exists but the GitHub runner appears to be still offline. Waiting for runner to get online ...",
|
|
||||||
"runnerName", runnerPod.Name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notFound || offline) && !registrationDidTimeout {
|
|
||||||
registrationRecheckJitter := 10 * time.Second
|
|
||||||
if r.RegistrationRecheckJitter > 0 {
|
|
||||||
registrationRecheckJitter = r.RegistrationRecheckJitter
|
|
||||||
}
|
|
||||||
|
|
||||||
registrationRecheckDelay = registrationCheckInterval + wait.Jitter(registrationRecheckJitter, 0.1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't do anything if there's no need to restart the runner
|
|
||||||
if !restart {
|
|
||||||
// This guard enables us to update runner.Status.Phase to `Running` only after
|
|
||||||
// the runner is registered to GitHub.
|
|
||||||
if registrationRecheckDelay > 0 {
|
|
||||||
log.V(1).Info(fmt.Sprintf("Rechecking the runner registration in %s", registrationRecheckDelay))
|
|
||||||
|
|
||||||
updated := runnerPod.DeepCopy()
|
|
||||||
t := time.Now().Format(time.RFC3339)
|
|
||||||
updated.Annotations[AnnotationKeyLastRegistrationCheckTime] = t
|
|
||||||
|
|
||||||
if err := r.Patch(ctx, updated, client.MergeFrom(&runnerPod)); err != nil {
|
|
||||||
log.Error(err, "Failed to update runner pod annotation for LastRegistrationCheckTime")
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{RequeueAfter: registrationRecheckDelay}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Seeing this message, you can expect the runner to become `Running` soon.
|
|
||||||
log.Info(
|
|
||||||
"Runner appears to have registered and running.",
|
|
||||||
"podCreationTimestamp", runnerPod.CreationTimestamp,
|
|
||||||
)
|
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete current pod if recreation is needed
|
|
||||||
if err := r.Delete(ctx, &runnerPod); err != nil {
|
|
||||||
log.Error(err, "Failed to delete pod resource")
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Recorder.Event(&runnerPod, corev1.EventTypeNormal, "PodDeleted", fmt.Sprintf("Deleted pod '%s'", runnerPod.Name))
|
|
||||||
log.Info("Deleted runner pod", "name", runnerPod.Name)
|
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RunnerPodReconciler) unregisterRunner(ctx context.Context, enterprise, org, repo, name string) (bool, error) {
|
func (r *RunnerPodReconciler) unregistrationRetryDelay() time.Duration {
|
||||||
runners, err := r.GitHubClient.ListRunners(ctx, enterprise, org, repo)
|
retryDelay := DefaultUnregistrationRetryDelay
|
||||||
if err != nil {
|
|
||||||
return false, err
|
if r.UnregistrationRetryDelay > 0 {
|
||||||
|
retryDelay = r.UnregistrationRetryDelay
|
||||||
}
|
}
|
||||||
|
return retryDelay
|
||||||
var busy bool
|
|
||||||
|
|
||||||
id := int64(0)
|
|
||||||
for _, runner := range runners {
|
|
||||||
if runner.GetName() == name {
|
|
||||||
// Sometimes a runner can stuck "busy" even though it is already "offline".
|
|
||||||
// Thus removing the condition on status can block the runner pod from being terminated forever.
|
|
||||||
busy = runner.GetBusy()
|
|
||||||
if runner.GetStatus() != "offline" && busy {
|
|
||||||
r.Log.Info("This runner will delay the runner pod deletion and the runner deregistration until it becomes either offline or non-busy", "name", runner.GetName(), "status", runner.GetStatus(), "busy", runner.GetBusy())
|
|
||||||
return false, fmt.Errorf("runner is busy")
|
|
||||||
}
|
|
||||||
id = runner.GetID()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if id == int64(0) {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sometimes a runner can stuck "busy" even though it is already "offline".
|
|
||||||
// Trying to remove the offline but busy runner can result in errors like the following:
|
|
||||||
// failed to remove runner: DELETE https://api.github.com/repos/actions-runner-controller/mumoshu-actions-test/actions/runners/47: 422 Bad request - Runner \"example-runnerset-0\" is still running a job\" []
|
|
||||||
if !busy {
|
|
||||||
if err := r.GitHubClient.RemoveRunner(ctx, enterprise, org, repo, id); err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RunnerPodReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
func (r *RunnerPodReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
|
|||||||
600
controllers/runner_pod_owner.go
Normal file
600
controllers/runner_pod_owner.go
Normal file
@@ -0,0 +1,600 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
||||||
|
"github.com/go-logr/logr"
|
||||||
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
type podsForOwner struct {
|
||||||
|
total int
|
||||||
|
completed int
|
||||||
|
running int
|
||||||
|
terminating int
|
||||||
|
regTimeout int
|
||||||
|
pending int
|
||||||
|
templateHash string
|
||||||
|
runner *v1alpha1.Runner
|
||||||
|
statefulSet *appsv1.StatefulSet
|
||||||
|
owner owner
|
||||||
|
object client.Object
|
||||||
|
synced bool
|
||||||
|
pods []corev1.Pod
|
||||||
|
}
|
||||||
|
|
||||||
|
type owner interface {
|
||||||
|
client.Object
|
||||||
|
|
||||||
|
pods(context.Context, client.Client) ([]corev1.Pod, error)
|
||||||
|
templateHash() (string, bool)
|
||||||
|
withAnnotation(k, v string) client.Object
|
||||||
|
synced() bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type ownerRunner struct {
|
||||||
|
client.Object
|
||||||
|
|
||||||
|
Log logr.Logger
|
||||||
|
Runner *v1alpha1.Runner
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ owner = (*ownerRunner)(nil)
|
||||||
|
|
||||||
|
func (r *ownerRunner) pods(ctx context.Context, c client.Client) ([]corev1.Pod, error) {
|
||||||
|
var pod corev1.Pod
|
||||||
|
|
||||||
|
if err := c.Get(ctx, types.NamespacedName{Namespace: r.Runner.Namespace, Name: r.Runner.Name}, &pod); err != nil {
|
||||||
|
if errors.IsNotFound(err) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
r.Log.Error(err, "Failed to get pod managed by runner")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return []corev1.Pod{pod}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ownerRunner) templateHash() (string, bool) {
|
||||||
|
return getRunnerTemplateHash(r.Runner)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ownerRunner) withAnnotation(k, v string) client.Object {
|
||||||
|
copy := r.Runner.DeepCopy()
|
||||||
|
setAnnotation(©.ObjectMeta, k, v)
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ownerRunner) synced() bool {
|
||||||
|
return r.Runner.Status.Phase != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type ownerStatefulSet struct {
|
||||||
|
client.Object
|
||||||
|
|
||||||
|
Log logr.Logger
|
||||||
|
StatefulSet *appsv1.StatefulSet
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ owner = (*ownerStatefulSet)(nil)
|
||||||
|
|
||||||
|
func (s *ownerStatefulSet) pods(ctx context.Context, c client.Client) ([]corev1.Pod, error) {
|
||||||
|
var podList corev1.PodList
|
||||||
|
|
||||||
|
if err := c.List(ctx, &podList, client.MatchingLabels(s.StatefulSet.Spec.Template.ObjectMeta.Labels)); err != nil {
|
||||||
|
s.Log.Error(err, "Failed to list pods managed by statefulset")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var pods []corev1.Pod
|
||||||
|
|
||||||
|
for _, pod := range podList.Items {
|
||||||
|
if owner := metav1.GetControllerOf(&pod); owner == nil || owner.Kind != "StatefulSet" || owner.Name != s.StatefulSet.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
pods = append(pods, pod)
|
||||||
|
}
|
||||||
|
|
||||||
|
return pods, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ownerStatefulSet) templateHash() (string, bool) {
|
||||||
|
return getRunnerTemplateHash(s.StatefulSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ownerStatefulSet) withAnnotation(k, v string) client.Object {
|
||||||
|
copy := s.StatefulSet.DeepCopy()
|
||||||
|
setAnnotation(©.ObjectMeta, k, v)
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ownerStatefulSet) synced() bool {
|
||||||
|
var replicas int32 = 1
|
||||||
|
if s.StatefulSet.Spec.Replicas != nil {
|
||||||
|
replicas = *s.StatefulSet.Spec.Replicas
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.StatefulSet.Status.Replicas != replicas {
|
||||||
|
s.Log.V(2).Info("Waiting for statefulset to sync", "desiredReplicas", replicas, "currentReplicas", s.StatefulSet.Status.Replicas)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPodsForOwner(ctx context.Context, c client.Client, log logr.Logger, o client.Object) (*podsForOwner, error) {
|
||||||
|
var (
|
||||||
|
owner owner
|
||||||
|
runner *v1alpha1.Runner
|
||||||
|
statefulSet *appsv1.StatefulSet
|
||||||
|
object client.Object
|
||||||
|
)
|
||||||
|
|
||||||
|
switch v := o.(type) {
|
||||||
|
case *v1alpha1.Runner:
|
||||||
|
owner = &ownerRunner{
|
||||||
|
Log: log,
|
||||||
|
Runner: v,
|
||||||
|
Object: v,
|
||||||
|
}
|
||||||
|
runner = v
|
||||||
|
object = v
|
||||||
|
case *appsv1.StatefulSet:
|
||||||
|
owner = &ownerStatefulSet{
|
||||||
|
Log: log,
|
||||||
|
StatefulSet: v,
|
||||||
|
Object: v,
|
||||||
|
}
|
||||||
|
statefulSet = v
|
||||||
|
object = v
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("BUG: Unsupported runner pods owner %v(%T)", v, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
pods, err := owner.pods(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var completed, running, terminating, regTimeout, pending, total int
|
||||||
|
|
||||||
|
for _, pod := range pods {
|
||||||
|
total++
|
||||||
|
|
||||||
|
if runnerPodOrContainerIsStopped(&pod) {
|
||||||
|
completed++
|
||||||
|
} else if pod.Status.Phase == corev1.PodRunning {
|
||||||
|
if podRunnerID(&pod) == "" && podConditionTransitionTimeAfter(&pod, corev1.PodReady, registrationTimeout) {
|
||||||
|
log.Info(
|
||||||
|
"Runner failed to register itself to GitHub in timely manner. "+
|
||||||
|
"Recreating the pod to see if it resolves the issue. "+
|
||||||
|
"CAUTION: If you see this a lot, you should investigate the root cause. "+
|
||||||
|
"See https://github.com/actions-runner-controller/actions-runner-controller/issues/288",
|
||||||
|
"creationTimestamp", pod.CreationTimestamp,
|
||||||
|
"readyTransitionTime", podConditionTransitionTime(&pod, corev1.PodReady, corev1.ConditionTrue),
|
||||||
|
"configuredRegistrationTimeout", registrationTimeout,
|
||||||
|
)
|
||||||
|
|
||||||
|
regTimeout++
|
||||||
|
} else {
|
||||||
|
running++
|
||||||
|
}
|
||||||
|
} else if !pod.DeletionTimestamp.IsZero() {
|
||||||
|
terminating++
|
||||||
|
} else {
|
||||||
|
// pending includes running but timedout runner's pod too
|
||||||
|
pending++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
templateHash, ok := owner.templateHash()
|
||||||
|
if !ok {
|
||||||
|
log.Info("Failed to get template hash of statefulset. It must be in an invalid state. Please manually delete the statefulset so that it is recreated")
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
synced := owner.synced()
|
||||||
|
|
||||||
|
return &podsForOwner{
|
||||||
|
total: total,
|
||||||
|
completed: completed,
|
||||||
|
running: running,
|
||||||
|
terminating: terminating,
|
||||||
|
regTimeout: regTimeout,
|
||||||
|
pending: pending,
|
||||||
|
templateHash: templateHash,
|
||||||
|
runner: runner,
|
||||||
|
statefulSet: statefulSet,
|
||||||
|
owner: owner,
|
||||||
|
object: object,
|
||||||
|
synced: synced,
|
||||||
|
pods: pods,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRunnerTemplateHash(r client.Object) (string, bool) {
|
||||||
|
hash, ok := r.GetLabels()[LabelKeyRunnerTemplateHash]
|
||||||
|
|
||||||
|
return hash, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
type state struct {
|
||||||
|
podsForOwners map[string][]*podsForOwner
|
||||||
|
lastSyncTime *time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type result struct {
|
||||||
|
currentObjects []*podsForOwner
|
||||||
|
}
|
||||||
|
|
||||||
|
// Why `create` must be a function rather than a client.Object? That's becase we use it to create one or more objects on scale up.
|
||||||
|
//
|
||||||
|
// We use client.Create to create a necessary number of client.Object. client.Create mutates the passed object on a successful creation.
|
||||||
|
// It seems to set .Revision at least, and the existence of .Revision let client.Create fail due to K8s restriction that an object being just created
|
||||||
|
// can't have .Revision.
|
||||||
|
// Now, imagine that you are to add 2 runner replicas on scale up.
|
||||||
|
// We create one resource object per a replica that ends up calling 2 client.Create calls.
|
||||||
|
// If we were reusing client.Object to be passed to client.Create calls, only the first call suceeeds.
|
||||||
|
// The second call fails due to the first call mutated the client.Object to have .Revision.
|
||||||
|
// Passing a factory function of client.Object and creating a brand-new client.Object per a client.Create call resolves this issue,
|
||||||
|
// allowing us to create two or more replicas in one reconcilation loop without being rejected by K8s.
|
||||||
|
func syncRunnerPodsOwners(ctx context.Context, c client.Client, log logr.Logger, effectiveTime *metav1.Time, newDesiredReplicas int, create func() client.Object, ephemeral bool, owners []client.Object) (*result, error) {
|
||||||
|
state, err := collectPodsForOwners(ctx, c, log, owners)
|
||||||
|
if err != nil || state == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
podsForOwnersPerTemplateHash, lastSyncTime := state.podsForOwners, state.lastSyncTime
|
||||||
|
|
||||||
|
// # Why do we recreate statefulsets instead of updating their desired replicas?
|
||||||
|
//
|
||||||
|
// A statefulset cannot add more pods when not all the pods are running.
|
||||||
|
// Our ephemeral runners' pods that have finished running become Completed(Phase=Succeeded).
|
||||||
|
// So creating one statefulset per a batch of ephemeral runners is the only way for us to add more replicas.
|
||||||
|
//
|
||||||
|
// # Why do we recreate statefulsets instead of updating fields other than replicas?
|
||||||
|
//
|
||||||
|
// That's because Kubernetes doesn't allow updating anything other than replicas, template, and updateStrategy.
|
||||||
|
// And the nature of ephemeral runner pods requires you to create a statefulset per a batch of new runner pods so
|
||||||
|
// we have really no other choice.
|
||||||
|
//
|
||||||
|
// If you're curious, the below is the error message you will get when you tried to update forbidden StatefulSet field(s):
|
||||||
|
//
|
||||||
|
// 2021-06-13T07:19:52.760Z ERROR actions-runner-controller.runnerset Failed to patch statefulset
|
||||||
|
// {"runnerset": "default/example-runnerset", "error": "StatefulSet.apps \"example-runnerset\" is invalid: s
|
||||||
|
// pec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy'
|
||||||
|
// are forbidden"}
|
||||||
|
//
|
||||||
|
// Even though the error message includes "Forbidden", this error's reason is "Invalid".
|
||||||
|
// So we used to match these errors by using errors.IsInvalid. But that's another story...
|
||||||
|
|
||||||
|
desiredTemplateHash, ok := getRunnerTemplateHash(create())
|
||||||
|
if !ok {
|
||||||
|
log.Info("Failed to get template hash of desired owner resource. It must be in an invalid state. Please manually delete the owner so that it is recreated")
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
currentObjects := podsForOwnersPerTemplateHash[desiredTemplateHash]
|
||||||
|
|
||||||
|
sort.SliceStable(currentObjects, func(i, j int) bool {
|
||||||
|
return currentObjects[i].owner.GetCreationTimestamp().Time.Before(currentObjects[j].owner.GetCreationTimestamp().Time)
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(currentObjects) > 0 {
|
||||||
|
timestampFirst := currentObjects[0].owner.GetCreationTimestamp()
|
||||||
|
timestampLast := currentObjects[len(currentObjects)-1].owner.GetCreationTimestamp()
|
||||||
|
var names []string
|
||||||
|
for _, ss := range currentObjects {
|
||||||
|
names = append(names, ss.owner.GetName())
|
||||||
|
}
|
||||||
|
log.V(2).Info("Detected some current object(s)", "creationTimestampFirst", timestampFirst, "creationTimestampLast", timestampLast, "names", names)
|
||||||
|
}
|
||||||
|
|
||||||
|
var total, terminating, pending, running, regTimeout int
|
||||||
|
|
||||||
|
for _, ss := range currentObjects {
|
||||||
|
total += ss.total
|
||||||
|
terminating += ss.terminating
|
||||||
|
pending += ss.pending
|
||||||
|
running += ss.running
|
||||||
|
regTimeout += ss.regTimeout
|
||||||
|
}
|
||||||
|
|
||||||
|
numOwners := len(owners)
|
||||||
|
|
||||||
|
var hashes []string
|
||||||
|
for h, _ := range state.podsForOwners {
|
||||||
|
hashes = append(hashes, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(2).Info(
|
||||||
|
"Found some pods across owner(s)",
|
||||||
|
"total", total,
|
||||||
|
"terminating", terminating,
|
||||||
|
"pending", pending,
|
||||||
|
"running", running,
|
||||||
|
"regTimeout", regTimeout,
|
||||||
|
"desired", newDesiredReplicas,
|
||||||
|
"owners", numOwners,
|
||||||
|
)
|
||||||
|
|
||||||
|
maybeRunning := pending + running
|
||||||
|
|
||||||
|
wantMoreRunners := newDesiredReplicas > maybeRunning
|
||||||
|
alreadySyncedAfterEffectiveTime := ephemeral && lastSyncTime != nil && effectiveTime != nil && lastSyncTime.After(effectiveTime.Time)
|
||||||
|
runnerPodRecreationDelayAfterWebhookScale := lastSyncTime != nil && time.Now().Before(lastSyncTime.Add(DefaultRunnerPodRecreationDelayAfterWebhookScale))
|
||||||
|
|
||||||
|
log = log.WithValues(
|
||||||
|
"lastSyncTime", lastSyncTime,
|
||||||
|
"effectiveTime", effectiveTime,
|
||||||
|
"templateHashDesired", desiredTemplateHash,
|
||||||
|
"replicasDesired", newDesiredReplicas,
|
||||||
|
"replicasPending", pending,
|
||||||
|
"replicasRunning", running,
|
||||||
|
"replicasMaybeRunning", maybeRunning,
|
||||||
|
"templateHashObserved", hashes,
|
||||||
|
)
|
||||||
|
|
||||||
|
if wantMoreRunners && alreadySyncedAfterEffectiveTime && runnerPodRecreationDelayAfterWebhookScale {
|
||||||
|
// This is our special handling of the situation for ephemeral runners only.
|
||||||
|
//
|
||||||
|
// Handling static runners this way results in scale-up to not work at all,
|
||||||
|
// because then any scale up attempts for static runenrs fall within this condition, for two reasons.
|
||||||
|
// First, static(persistent) runners will never restart on their own.
|
||||||
|
// Second, we don't update EffectiveTime for static runners.
|
||||||
|
//
|
||||||
|
// We do need to skip this condition for static runners, and that's why we take the `ephemeral` flag into account when
|
||||||
|
// computing `alreadySyncedAfterEffectiveTime``.
|
||||||
|
|
||||||
|
log.V(2).Info(
|
||||||
|
"Detected that some ephemeral runners have disappeared. " +
|
||||||
|
"Usually this is due to that ephemeral runner completions " +
|
||||||
|
"so ARC does not create new runners until EffectiveTime is updated, or DefaultRunnerPodRecreationDelayAfterWebhookScale is elapsed.")
|
||||||
|
} else if wantMoreRunners {
|
||||||
|
if alreadySyncedAfterEffectiveTime && !runnerPodRecreationDelayAfterWebhookScale {
|
||||||
|
log.V(2).Info("Adding more replicas because DefaultRunnerPodRecreationDelayAfterWebhookScale has been passed")
|
||||||
|
}
|
||||||
|
|
||||||
|
num := newDesiredReplicas - maybeRunning
|
||||||
|
|
||||||
|
for i := 0; i < num; i++ {
|
||||||
|
// Add more replicas
|
||||||
|
if err := c.Create(ctx, create()); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(1).Info("Created replica(s)",
|
||||||
|
"created", num,
|
||||||
|
)
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
} else if newDesiredReplicas <= running {
|
||||||
|
// If you use ephemeral runners with webhook-based autoscaler and the runner controller is working normally,
|
||||||
|
// you're unlikely to fall into this branch.
|
||||||
|
//
|
||||||
|
// That's because all the stakeholders work like this:
|
||||||
|
//
|
||||||
|
// 1. A runner pod completes with the runner container exiting with code 0
|
||||||
|
// 2. ARC runner controller detects the pod completion, marks the owner(runner or statefulset) resource on k8s for deletion (=Runner.DeletionTimestamp becomes non-zero)
|
||||||
|
// 3. GitHub triggers a corresponding workflow_job "complete" webhook event
|
||||||
|
// 4. ARC github-webhook-server (webhook-based autoscaler) receives the webhook event updates HRA with removing the oldest capacity reservation
|
||||||
|
// 5. ARC horizontalrunnerautoscaler updates RunnerDeployment's desired replicas based on capacity reservations
|
||||||
|
// 6. ARC runnerdeployment controller updates RunnerReplicaSet's desired replicas
|
||||||
|
// 7. (We're here) ARC runnerset or runnerreplicaset controller starts reconciling the owner resource (statefulset or runner)
|
||||||
|
//
|
||||||
|
// In a normally working ARC installation, the runner that was used to run the workflow job should already have been
|
||||||
|
// marked for deletion by the runner controller.
|
||||||
|
// This runnerreplicaset controller doesn't count marked runners into the `running` value, hence you're unlikely to
|
||||||
|
// fall into this branch when you're using ephemeral runners with webhook-based-autoscaler.
|
||||||
|
|
||||||
|
var retained int
|
||||||
|
|
||||||
|
var delete []*podsForOwner
|
||||||
|
for i := len(currentObjects) - 1; i >= 0; i-- {
|
||||||
|
ss := currentObjects[i]
|
||||||
|
|
||||||
|
if ss.running == 0 || retained >= newDesiredReplicas {
|
||||||
|
// In case the desired replicas is satisfied until i-1, or this owner has no running pods,
|
||||||
|
// this owner can be considered safe for deletion.
|
||||||
|
// Note that we already waited on this owner to create pods by waiting for
|
||||||
|
// `.Status.Replicas`(=total number of pods managed by owner, regardless of the runner is Running or Completed) to match the desired replicas in a previous step.
|
||||||
|
// So `.running == 0` means "the owner has created the desired number of pods before, and all of them are completed now".
|
||||||
|
delete = append(delete, ss)
|
||||||
|
} else if retained < newDesiredReplicas {
|
||||||
|
retained += ss.running
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if retained == newDesiredReplicas {
|
||||||
|
for _, ss := range delete {
|
||||||
|
log := log.WithValues("owner", types.NamespacedName{Namespace: ss.owner.GetNamespace(), Name: ss.owner.GetName()})
|
||||||
|
// Statefulset termination process 1/4: Set unregistrationRequestTimestamp only after all the pods managed by the statefulset have
|
||||||
|
// started unregistreation process.
|
||||||
|
//
|
||||||
|
// NOTE: We just mark it instead of immediately starting the deletion process.
|
||||||
|
// Otherwise, the runner pod may hit termiationGracePeriod before the unregistration completes(the max terminationGracePeriod is limited to 1h by K8s and a job can be run for more than that),
|
||||||
|
// or actions/runner may potentially misbehave on SIGTERM immediately sent by K8s.
|
||||||
|
// We'd better unregister first and then start a pod deletion process.
|
||||||
|
// The annotation works as a mark to start the pod unregistration and deletion process of ours.
|
||||||
|
|
||||||
|
if _, ok := getAnnotation(ss.owner, AnnotationKeyUnregistrationRequestTimestamp); ok {
|
||||||
|
log.V(2).Info("Still waiting for runner pod(s) unregistration to complete")
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, po := range ss.pods {
|
||||||
|
if _, err := annotatePodOnce(ctx, c, log, &po, AnnotationKeyUnregistrationRequestTimestamp, time.Now().Format(time.RFC3339)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updated := ss.owner.withAnnotation(AnnotationKeyUnregistrationRequestTimestamp, time.Now().Format(time.RFC3339))
|
||||||
|
if err := c.Patch(ctx, updated, client.MergeFrom(ss.owner)); err != nil {
|
||||||
|
log.Error(err, fmt.Sprintf("Failed to patch owner to have %s annotation", AnnotationKeyUnregistrationRequestTimestamp))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(2).Info("Redundant owner has been annotated to start the unregistration before deletion")
|
||||||
|
}
|
||||||
|
} else if retained > newDesiredReplicas {
|
||||||
|
log.V(2).Info("Waiting sync before scale down", "retained", retained, "newDesiredReplicas", newDesiredReplicas)
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
} else {
|
||||||
|
log.Info("Invalid state", "retained", retained, "newDesiredReplicas", newDesiredReplicas)
|
||||||
|
panic("crashed due to invalid state")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, sss := range podsForOwnersPerTemplateHash {
|
||||||
|
for _, ss := range sss {
|
||||||
|
if ss.templateHash != desiredTemplateHash {
|
||||||
|
if ss.owner.GetDeletionTimestamp().IsZero() {
|
||||||
|
if err := c.Delete(ctx, ss.object); err != nil {
|
||||||
|
log.Error(err, "Unable to delete object")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(2).Info("Deleted redundant and outdated object")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &result{
|
||||||
|
currentObjects: currentObjects,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func collectPodsForOwners(ctx context.Context, c client.Client, log logr.Logger, owners []client.Object) (*state, error) {
|
||||||
|
podsForOwnerPerTemplateHash := map[string][]*podsForOwner{}
|
||||||
|
|
||||||
|
// lastSyncTime becomes non-nil only when there are one or more owner(s) hence there are same number of runner pods.
|
||||||
|
// It's used to prevent runnerset-controller from recreating "completed ephemeral runners".
|
||||||
|
// This is needed to prevent runners from being terminated prematurely.
|
||||||
|
// See https://github.com/actions-runner-controller/actions-runner-controller/issues/911 for more context.
|
||||||
|
//
|
||||||
|
// This becomes nil when there are zero statefulset(s). That's fine because then there should be zero stateful(s) to be recreated either hence
|
||||||
|
// we don't need to guard with lastSyncTime.
|
||||||
|
var lastSyncTime *time.Time
|
||||||
|
|
||||||
|
for _, ss := range owners {
|
||||||
|
log := log.WithValues("owner", types.NamespacedName{Namespace: ss.GetNamespace(), Name: ss.GetName()})
|
||||||
|
|
||||||
|
res, err := getPodsForOwner(ctx, c, log, ss)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.templateHash == "" {
|
||||||
|
log.Info("validation error: runner pod owner must have template hash", "object", res.object)
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Statefulset termination process 4/4: Let Kubernetes cascade-delete the statefulset and the pods.
|
||||||
|
//
|
||||||
|
// If the runner is already marked for deletion(=has a non-zero deletion timestamp) by the runner controller (can be caused by an ephemeral runner completion)
|
||||||
|
// or by this controller (in case it was deleted in the previous reconcilation loop),
|
||||||
|
// we don't need to bother calling GitHub API to re-mark the runner for deletion.
|
||||||
|
// Just hold on, and runners will disappear as long as the runner controller is up and running.
|
||||||
|
if !res.owner.GetDeletionTimestamp().IsZero() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Statefulset termination process 3/4: Set the deletionTimestamp to let Kubernetes start a cascade deletion of the statefulset and the pods.
|
||||||
|
if _, ok := getAnnotation(res.owner, AnnotationKeyUnregistrationCompleteTimestamp); ok {
|
||||||
|
if err := c.Delete(ctx, res.object); err != nil {
|
||||||
|
log.Error(err, "Failed to delete owner")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(2).Info("Started deletion of owner")
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Statefulset termination process 2/4: Set unregistrationCompleteTimestamp only if all the pods managed by the statefulset
|
||||||
|
// have either unregistered or being deleted.
|
||||||
|
if _, ok := getAnnotation(res.owner, AnnotationKeyUnregistrationRequestTimestamp); ok {
|
||||||
|
var deletionSafe int
|
||||||
|
for _, po := range res.pods {
|
||||||
|
if _, ok := getAnnotation(&po, AnnotationKeyUnregistrationCompleteTimestamp); ok {
|
||||||
|
deletionSafe++
|
||||||
|
} else if !po.DeletionTimestamp.IsZero() {
|
||||||
|
deletionSafe++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if deletionSafe == res.total {
|
||||||
|
log.V(2).Info("Marking owner for unregistration completion", "deletionSafe", deletionSafe, "total", res.total)
|
||||||
|
|
||||||
|
if _, ok := getAnnotation(res.owner, AnnotationKeyUnregistrationCompleteTimestamp); !ok {
|
||||||
|
updated := res.owner.withAnnotation(AnnotationKeyUnregistrationCompleteTimestamp, time.Now().Format(time.RFC3339))
|
||||||
|
|
||||||
|
if err := c.Patch(ctx, updated, client.MergeFrom(res.owner)); err != nil {
|
||||||
|
log.Error(err, fmt.Sprintf("Failed to patch owner to have %s annotation", AnnotationKeyUnregistrationCompleteTimestamp))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(2).Info("Redundant owner has been annotated to start the deletion")
|
||||||
|
} else {
|
||||||
|
log.V(2).Info("BUG: Redundant owner was already annotated to start the deletion")
|
||||||
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if annotations := res.owner.GetAnnotations(); annotations != nil {
|
||||||
|
if a, ok := annotations[SyncTimeAnnotationKey]; ok {
|
||||||
|
t, err := time.Parse(time.RFC3339, a)
|
||||||
|
if err == nil {
|
||||||
|
if lastSyncTime == nil || lastSyncTime.Before(t) {
|
||||||
|
lastSyncTime = &t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A completed owner and a completed runner pod can safely be deleted without
|
||||||
|
// a race condition so delete it here,
|
||||||
|
// so that the later process can be a bit simpler.
|
||||||
|
if res.total > 0 && res.total == res.completed {
|
||||||
|
if err := c.Delete(ctx, ss); err != nil {
|
||||||
|
log.Error(err, "Unable to delete owner")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.V(2).Info("Deleted completed owner")
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if !res.synced {
|
||||||
|
log.V(1).Info("Skipped reconcilation because owner is not synced yet", "pods", res.pods)
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
podsForOwnerPerTemplateHash[res.templateHash] = append(podsForOwnerPerTemplateHash[res.templateHash], res)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &state{podsForOwnerPerTemplateHash, lastSyncTime}, nil
|
||||||
|
}
|
||||||
@@ -118,6 +118,8 @@ func (r *RunnerDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
|
|||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Info("Created runnerreplicaset", "runnerreplicaset", desiredRS.Name)
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +144,8 @@ func (r *RunnerDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
|
|||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Info("Created runnerreplicaset", "runnerreplicaset", desiredRS.Name)
|
||||||
|
|
||||||
// We requeue in order to clean up old runner replica sets later.
|
// We requeue in order to clean up old runner replica sets later.
|
||||||
// Otherwise, they aren't cleaned up until the next re-sync interval.
|
// Otherwise, they aren't cleaned up until the next re-sync interval.
|
||||||
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
|
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
|
||||||
@@ -177,6 +181,7 @@ func (r *RunnerDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
|
|||||||
// Please add more conditions that we can in-place update the newest runnerreplicaset without disruption
|
// Please add more conditions that we can in-place update the newest runnerreplicaset without disruption
|
||||||
if currentDesiredReplicas != newDesiredReplicas {
|
if currentDesiredReplicas != newDesiredReplicas {
|
||||||
newestSet.Spec.Replicas = &newDesiredReplicas
|
newestSet.Spec.Replicas = &newDesiredReplicas
|
||||||
|
newestSet.Spec.EffectiveTime = rd.Spec.EffectiveTime
|
||||||
|
|
||||||
if err := r.Client.Update(ctx, newestSet); err != nil {
|
if err := r.Client.Update(ctx, newestSet); err != nil {
|
||||||
log.Error(err, "Failed to update runnerreplicaset resource")
|
log.Error(err, "Failed to update runnerreplicaset resource")
|
||||||
@@ -221,15 +226,38 @@ func (r *RunnerDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
|
|||||||
for i := range oldSets {
|
for i := range oldSets {
|
||||||
rs := oldSets[i]
|
rs := oldSets[i]
|
||||||
|
|
||||||
|
rslog := log.WithValues("runnerreplicaset", rs.Name)
|
||||||
|
|
||||||
|
if rs.Status.Replicas != nil && *rs.Status.Replicas > 0 {
|
||||||
|
if rs.Spec.Replicas != nil && *rs.Spec.Replicas == 0 {
|
||||||
|
rslog.V(2).Info("Waiting for runnerreplicaset to scale to zero")
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
updated := rs.DeepCopy()
|
||||||
|
zero := 0
|
||||||
|
updated.Spec.Replicas = &zero
|
||||||
|
if err := r.Client.Update(ctx, updated); err != nil {
|
||||||
|
rslog.Error(err, "Failed to scale runnerreplicaset to zero")
|
||||||
|
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rslog.Info("Scaled runnerreplicaset to zero")
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if err := r.Client.Delete(ctx, &rs); err != nil {
|
if err := r.Client.Delete(ctx, &rs); err != nil {
|
||||||
log.Error(err, "Failed to delete runnerreplicaset resource")
|
rslog.Error(err, "Failed to delete runnerreplicaset resource")
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Recorder.Event(&rd, corev1.EventTypeNormal, "RunnerReplicaSetDeleted", fmt.Sprintf("Deleted runnerreplicaset '%s'", rs.Name))
|
r.Recorder.Event(&rd, corev1.EventTypeNormal, "RunnerReplicaSetDeleted", fmt.Sprintf("Deleted runnerreplicaset '%s'", rs.Name))
|
||||||
|
|
||||||
log.Info("Deleted runnerreplicaset", "runnerdeployment", rd.ObjectMeta.Name, "runnerreplicaset", rs.Name)
|
rslog.Info("Deleted runnerreplicaset")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,9 +421,7 @@ func getSelector(rd *v1alpha1.RunnerDeployment) *metav1.LabelSelector {
|
|||||||
func newRunnerReplicaSet(rd *v1alpha1.RunnerDeployment, commonRunnerLabels []string, scheme *runtime.Scheme) (*v1alpha1.RunnerReplicaSet, error) {
|
func newRunnerReplicaSet(rd *v1alpha1.RunnerDeployment, commonRunnerLabels []string, scheme *runtime.Scheme) (*v1alpha1.RunnerReplicaSet, error) {
|
||||||
newRSTemplate := *rd.Spec.Template.DeepCopy()
|
newRSTemplate := *rd.Spec.Template.DeepCopy()
|
||||||
|
|
||||||
for _, l := range commonRunnerLabels {
|
newRSTemplate.Spec.Labels = append(newRSTemplate.Spec.Labels, commonRunnerLabels...)
|
||||||
newRSTemplate.Spec.Labels = append(newRSTemplate.Spec.Labels, l)
|
|
||||||
}
|
|
||||||
|
|
||||||
templateHash := ComputeHash(&newRSTemplate)
|
templateHash := ComputeHash(&newRSTemplate)
|
||||||
|
|
||||||
@@ -417,9 +443,10 @@ func newRunnerReplicaSet(rd *v1alpha1.RunnerDeployment, commonRunnerLabels []str
|
|||||||
Labels: newRSTemplate.ObjectMeta.Labels,
|
Labels: newRSTemplate.ObjectMeta.Labels,
|
||||||
},
|
},
|
||||||
Spec: v1alpha1.RunnerReplicaSetSpec{
|
Spec: v1alpha1.RunnerReplicaSetSpec{
|
||||||
Replicas: rd.Spec.Replicas,
|
Replicas: rd.Spec.Replicas,
|
||||||
Selector: newRSSelector,
|
Selector: newRSSelector,
|
||||||
Template: newRSTemplate,
|
Template: newRSTemplate,
|
||||||
|
EffectiveTime: rd.Spec.EffectiveTime,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,21 +18,17 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
gogithub "github.com/google/go-github/v37/github"
|
|
||||||
|
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
|
|
||||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
||||||
@@ -49,6 +45,10 @@ type RunnerReplicaSetReconciler struct {
|
|||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
SyncTimeAnnotationKey = "sync-time"
|
||||||
|
)
|
||||||
|
|
||||||
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runnerreplicasets,verbs=get;list;watch;create;update;patch;delete
|
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runnerreplicasets,verbs=get;list;watch;create;update;patch;delete
|
||||||
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runnerreplicasets/finalizers,verbs=get;list;watch;create;update;patch;delete
|
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runnerreplicasets/finalizers,verbs=get;list;watch;create;update;patch;delete
|
||||||
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runnerreplicasets/status,verbs=get;update;patch
|
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runnerreplicasets/status,verbs=get;update;patch
|
||||||
@@ -65,18 +65,42 @@ func (r *RunnerReplicaSetReconciler) Reconcile(ctx context.Context, req ctrl.Req
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !rs.ObjectMeta.DeletionTimestamp.IsZero() {
|
if !rs.ObjectMeta.DeletionTimestamp.IsZero() {
|
||||||
|
// RunnerReplicaSet cannot be gracefuly removed.
|
||||||
|
// That means any runner that is running a job can be prematurely terminated.
|
||||||
|
// To gracefully remove a RunnerReplicaSet, scale it down to zero first, observe RunnerReplicaSet's status replicas,
|
||||||
|
// and remove it only after the status replicas becomes zero.
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rs.ObjectMeta.Labels == nil {
|
||||||
|
rs.ObjectMeta.Labels = map[string]string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Template hash is usually set by the upstream controller(RunnerDeplloyment controller) on authoring
|
||||||
|
// RunerReplicaset resource, but it may be missing when the user directly created RunnerReplicaSet.
|
||||||
|
// As a template hash is required by by the runner replica management, we dynamically add it here without ever persisting it.
|
||||||
|
if rs.ObjectMeta.Labels[LabelKeyRunnerTemplateHash] == "" {
|
||||||
|
template := rs.Spec.DeepCopy()
|
||||||
|
template.Replicas = nil
|
||||||
|
template.EffectiveTime = nil
|
||||||
|
templateHash := ComputeHash(template)
|
||||||
|
|
||||||
|
log.Info("Using auto-generated template hash", "value", templateHash)
|
||||||
|
|
||||||
|
rs.ObjectMeta.Labels = CloneAndAddLabel(rs.ObjectMeta.Labels, LabelKeyRunnerTemplateHash, templateHash)
|
||||||
|
rs.Spec.Template.ObjectMeta.Labels = CloneAndAddLabel(rs.Spec.Template.ObjectMeta.Labels, LabelKeyRunnerTemplateHash, templateHash)
|
||||||
|
}
|
||||||
|
|
||||||
selector, err := metav1.LabelSelectorAsSelector(rs.Spec.Selector)
|
selector, err := metav1.LabelSelectorAsSelector(rs.Spec.Selector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Runners managed by the target RunnerReplicaSet
|
// Get the Runners managed by the target RunnerReplicaSet
|
||||||
var allRunners v1alpha1.RunnerList
|
var runnerList v1alpha1.RunnerList
|
||||||
if err := r.List(
|
if err := r.List(
|
||||||
ctx,
|
ctx,
|
||||||
&allRunners,
|
&runnerList,
|
||||||
client.InNamespace(req.Namespace),
|
client.InNamespace(req.Namespace),
|
||||||
client.MatchingLabelsSelector{Selector: selector},
|
client.MatchingLabelsSelector{Selector: selector},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
@@ -85,209 +109,44 @@ func (r *RunnerReplicaSetReconciler) Reconcile(ctx context.Context, req ctrl.Req
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var myRunners []v1alpha1.Runner
|
replicas := 1
|
||||||
|
if rs.Spec.Replicas != nil {
|
||||||
|
replicas = *rs.Spec.Replicas
|
||||||
|
}
|
||||||
|
|
||||||
|
effectiveTime := rs.Spec.EffectiveTime
|
||||||
|
ephemeral := rs.Spec.Template.Spec.Ephemeral == nil || *rs.Spec.Template.Spec.Ephemeral
|
||||||
|
|
||||||
|
desired, err := r.newRunner(rs)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err, "Could not create runner")
|
||||||
|
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var live []client.Object
|
||||||
|
for _, r := range runnerList.Items {
|
||||||
|
r := r
|
||||||
|
live = append(live, &r)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := syncRunnerPodsOwners(ctx, r.Client, log, effectiveTime, replicas, func() client.Object { return desired.DeepCopy() }, ephemeral, live)
|
||||||
|
if err != nil || res == nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
current int
|
status v1alpha1.RunnerReplicaSetStatus
|
||||||
ready int
|
|
||||||
available int
|
current, available, ready int
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, r := range allRunners.Items {
|
for _, o := range res.currentObjects {
|
||||||
// This guard is required to avoid the RunnerReplicaSet created by the controller v0.17.0 or before
|
current += o.total
|
||||||
// to not treat all the runners in the namespace as its children.
|
available += o.running
|
||||||
if metav1.IsControlledBy(&r, &rs) && !metav1.HasAnnotation(r.ObjectMeta, annotationKeyRegistrationOnly) {
|
ready += o.running
|
||||||
myRunners = append(myRunners, r)
|
|
||||||
|
|
||||||
current += 1
|
|
||||||
|
|
||||||
if r.Status.Phase == string(corev1.PodRunning) {
|
|
||||||
ready += 1
|
|
||||||
// available is currently the same as ready, as we don't yet have minReadySeconds for runners
|
|
||||||
available += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var desired int
|
|
||||||
|
|
||||||
if rs.Spec.Replicas != nil {
|
|
||||||
desired = *rs.Spec.Replicas
|
|
||||||
} else {
|
|
||||||
desired = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
registrationOnlyRunnerNsName := req.NamespacedName
|
|
||||||
registrationOnlyRunnerNsName.Name = registrationOnlyRunnerNameFor(rs.Name)
|
|
||||||
registrationOnlyRunner := v1alpha1.Runner{}
|
|
||||||
registrationOnlyRunnerExists := false
|
|
||||||
if err := r.Get(
|
|
||||||
ctx,
|
|
||||||
registrationOnlyRunnerNsName,
|
|
||||||
®istrationOnlyRunner,
|
|
||||||
); err != nil {
|
|
||||||
if !kerrors.IsNotFound(err) {
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
registrationOnlyRunnerExists = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// On scale to zero, we must have fully registered registration-only runner before we start deleting other runners, hence `desired == 0`
|
|
||||||
// On scale from zero, we must retain the registratoin-only runner until one or more other runners get registered, hence `registrationOnlyRunnerExists && available == 0`.
|
|
||||||
// On RunnerReplicaSet creation, it have always 0 replics and no registration-only runner.
|
|
||||||
// In this case We don't need to bother creating a registration-only runner which gets deleted soon after we have 1 or more available repolicas,
|
|
||||||
// hence it's not `available == 0`, but `registrationOnlyRunnerExists && available == 0`.
|
|
||||||
// See https://github.com/actions-runner-controller/actions-runner-controller/issues/516
|
|
||||||
registrationOnlyRunnerNeeded := desired == 0 || (registrationOnlyRunnerExists && current == 0)
|
|
||||||
|
|
||||||
if registrationOnlyRunnerNeeded {
|
|
||||||
if registrationOnlyRunnerExists {
|
|
||||||
if registrationOnlyRunner.Status.Phase == "" {
|
|
||||||
log.Info("Still waiting for the registration-only runner to be registered")
|
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// A registration-only runner does not exist and is needed, hence create it.
|
|
||||||
|
|
||||||
runnerForScaleFromToZero, err := r.newRunner(rs)
|
|
||||||
if err != nil {
|
|
||||||
return ctrl.Result{}, fmt.Errorf("failed to create runner for scale from/to zero: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
runnerForScaleFromToZero.ObjectMeta.Name = registrationOnlyRunnerNsName.Name
|
|
||||||
runnerForScaleFromToZero.ObjectMeta.GenerateName = ""
|
|
||||||
runnerForScaleFromToZero.ObjectMeta.Labels = nil
|
|
||||||
metav1.SetMetaDataAnnotation(&runnerForScaleFromToZero.ObjectMeta, annotationKeyRegistrationOnly, "true")
|
|
||||||
|
|
||||||
if err := r.Client.Create(ctx, &runnerForScaleFromToZero); err != nil {
|
|
||||||
log.Error(err, "Failed to create runner for scale from/to zero")
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// We can continue to deleting runner pods only after the
|
|
||||||
// registration-only runner gets registered.
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// A registration-only runner exists and is not needed, hence delete it.
|
|
||||||
if registrationOnlyRunnerExists {
|
|
||||||
if err := r.Client.Delete(ctx, ®istrationOnlyRunner); err != nil {
|
|
||||||
log.Error(err, "Retrying soon because we failed to delete registration-only runner")
|
|
||||||
|
|
||||||
return ctrl.Result{Requeue: true}, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if current > desired {
|
|
||||||
n := current - desired
|
|
||||||
|
|
||||||
log.V(0).Info(fmt.Sprintf("Deleting %d runners", n), "desired", desired, "current", current, "ready", ready)
|
|
||||||
|
|
||||||
// get runners that are currently offline/not busy/timed-out to register
|
|
||||||
var deletionCandidates []v1alpha1.Runner
|
|
||||||
|
|
||||||
for _, runner := range allRunners.Items {
|
|
||||||
busy, err := r.GitHubClient.IsRunnerBusy(ctx, runner.Spec.Enterprise, runner.Spec.Organization, runner.Spec.Repository, runner.Name)
|
|
||||||
if err != nil {
|
|
||||||
notRegistered := false
|
|
||||||
offline := false
|
|
||||||
|
|
||||||
var notFoundException *github.RunnerNotFound
|
|
||||||
var offlineException *github.RunnerOffline
|
|
||||||
if errors.As(err, ¬FoundException) {
|
|
||||||
log.V(1).Info("Failed to check if runner is busy. Either this runner has never been successfully registered to GitHub or it still needs more time.", "runnerName", runner.Name)
|
|
||||||
notRegistered = true
|
|
||||||
} else if errors.As(err, &offlineException) {
|
|
||||||
offline = true
|
|
||||||
} else {
|
|
||||||
var e *gogithub.RateLimitError
|
|
||||||
if errors.As(err, &e) {
|
|
||||||
// We log the underlying error when we failed calling GitHub API to list or unregisters,
|
|
||||||
// or the runner is still busy.
|
|
||||||
log.Error(
|
|
||||||
err,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"Failed to check if runner is busy due to GitHub API rate limit. Retrying in %s to avoid excessive GitHub API calls",
|
|
||||||
retryDelayOnGitHubAPIRateLimitError,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
return ctrl.Result{RequeueAfter: retryDelayOnGitHubAPIRateLimitError}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
registrationTimeout := 15 * time.Minute
|
|
||||||
currentTime := time.Now()
|
|
||||||
registrationDidTimeout := currentTime.Sub(runner.CreationTimestamp.Add(registrationTimeout)) > 0
|
|
||||||
|
|
||||||
if notRegistered && registrationDidTimeout {
|
|
||||||
log.Info(
|
|
||||||
"Runner failed to register itself to GitHub in timely manner. "+
|
|
||||||
"Marking the runner for scale down. "+
|
|
||||||
"CAUTION: If you see this a lot, you should investigate the root cause. "+
|
|
||||||
"See https://github.com/actions-runner-controller/actions-runner-controller/issues/288",
|
|
||||||
"runnerCreationTimestamp", runner.CreationTimestamp,
|
|
||||||
"currentTime", currentTime,
|
|
||||||
"configuredRegistrationTimeout", registrationTimeout,
|
|
||||||
)
|
|
||||||
|
|
||||||
deletionCandidates = append(deletionCandidates, runner)
|
|
||||||
}
|
|
||||||
|
|
||||||
// offline runners should always be a great target for scale down
|
|
||||||
if offline {
|
|
||||||
deletionCandidates = append(deletionCandidates, runner)
|
|
||||||
}
|
|
||||||
} else if !busy {
|
|
||||||
deletionCandidates = append(deletionCandidates, runner)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(deletionCandidates) < n {
|
|
||||||
n = len(deletionCandidates)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.V(0).Info(fmt.Sprintf("Deleting %d runner(s)", n), "desired", desired, "current", current, "ready", ready)
|
|
||||||
|
|
||||||
for i := 0; i < n; i++ {
|
|
||||||
if err := r.Client.Delete(ctx, &deletionCandidates[i]); client.IgnoreNotFound(err) != nil {
|
|
||||||
log.Error(err, "Failed to delete runner resource")
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Recorder.Event(&rs, corev1.EventTypeNormal, "RunnerDeleted", fmt.Sprintf("Deleted runner '%s'", deletionCandidates[i].Name))
|
|
||||||
log.Info("Deleted runner")
|
|
||||||
}
|
|
||||||
} else if desired > current {
|
|
||||||
n := desired - current
|
|
||||||
|
|
||||||
log.V(0).Info(fmt.Sprintf("Creating %d runner(s)", n), "desired", desired, "available", current, "ready", ready)
|
|
||||||
|
|
||||||
for i := 0; i < n; i++ {
|
|
||||||
newRunner, err := r.newRunner(rs)
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err, "Could not create runner")
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := r.Client.Create(ctx, &newRunner); err != nil {
|
|
||||||
log.Error(err, "Failed to create runner resource")
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var status v1alpha1.RunnerReplicaSetStatus
|
|
||||||
|
|
||||||
status.Replicas = ¤t
|
status.Replicas = ¤t
|
||||||
status.AvailableReplicas = &available
|
status.AvailableReplicas = &available
|
||||||
status.ReadyReplicas = &ready
|
status.ReadyReplicas = &ready
|
||||||
@@ -308,10 +167,16 @@ func (r *RunnerReplicaSetReconciler) Reconcile(ctx context.Context, req ctrl.Req
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RunnerReplicaSetReconciler) newRunner(rs v1alpha1.RunnerReplicaSet) (v1alpha1.Runner, error) {
|
func (r *RunnerReplicaSetReconciler) newRunner(rs v1alpha1.RunnerReplicaSet) (v1alpha1.Runner, error) {
|
||||||
|
// Note that the upstream controller (runnerdeployment) is expected to add
|
||||||
|
// the "runner template hash" label to the template.meta which is necessary to make this controller work correctly
|
||||||
objectMeta := rs.Spec.Template.ObjectMeta.DeepCopy()
|
objectMeta := rs.Spec.Template.ObjectMeta.DeepCopy()
|
||||||
|
|
||||||
objectMeta.GenerateName = rs.ObjectMeta.Name + "-"
|
objectMeta.GenerateName = rs.ObjectMeta.Name + "-"
|
||||||
objectMeta.Namespace = rs.ObjectMeta.Namespace
|
objectMeta.Namespace = rs.ObjectMeta.Namespace
|
||||||
|
if objectMeta.Annotations == nil {
|
||||||
|
objectMeta.Annotations = map[string]string{}
|
||||||
|
}
|
||||||
|
objectMeta.Annotations[SyncTimeAnnotationKey] = time.Now().Format(time.RFC3339)
|
||||||
|
|
||||||
runner := v1alpha1.Runner{
|
runner := v1alpha1.Runner{
|
||||||
TypeMeta: metav1.TypeMeta{},
|
TypeMeta: metav1.TypeMeta{},
|
||||||
@@ -340,7 +205,3 @@ func (r *RunnerReplicaSetReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
|||||||
Named(name).
|
Named(name).
|
||||||
Complete(r)
|
Complete(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func registrationOnlyRunnerNameFor(rsName string) string {
|
|
||||||
return rsName + "-registration-only"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,13 +2,11 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
|
||||||
"k8s.io/client-go/kubernetes/scheme"
|
"k8s.io/client-go/kubernetes/scheme"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
@@ -103,12 +101,40 @@ func intPtr(v int) *int {
|
|||||||
var _ = Context("Inside of a new namespace", func() {
|
var _ = Context("Inside of a new namespace", func() {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
ns := SetupTest(ctx)
|
ns := SetupTest(ctx)
|
||||||
|
name := "example-runnerreplicaset"
|
||||||
|
|
||||||
Describe("when no existing resources exist", func() {
|
getRunnerCount := func() int {
|
||||||
|
runners := actionsv1alpha1.RunnerList{Items: []actionsv1alpha1.Runner{}}
|
||||||
|
|
||||||
It("should create a new Runner resource from the specified template, add a another Runner on replicas increased, and removes all the replicas when set to 0", func() {
|
selector, err := metav1.LabelSelectorAsSelector(
|
||||||
name := "example-runnerreplicaset"
|
&metav1.LabelSelector{
|
||||||
|
MatchLabels: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
logf.Log.Error(err, "failed to create labelselector")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
err = k8sClient.List(
|
||||||
|
ctx,
|
||||||
|
&runners,
|
||||||
|
client.InNamespace(ns.Name),
|
||||||
|
client.MatchingLabelsSelector{Selector: selector},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
logf.Log.Error(err, "list runners")
|
||||||
|
}
|
||||||
|
|
||||||
|
runnersList.Sync(runners.Items)
|
||||||
|
|
||||||
|
return len(runners.Items)
|
||||||
|
}
|
||||||
|
|
||||||
|
Describe("RunnerReplicaSet", func() {
|
||||||
|
It("should create a new Runner resource from the specified template", func() {
|
||||||
{
|
{
|
||||||
rs := &actionsv1alpha1.RunnerReplicaSet{
|
rs := &actionsv1alpha1.RunnerReplicaSet{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
@@ -147,142 +173,99 @@ var _ = Context("Inside of a new namespace", func() {
|
|||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred(), "failed to create test RunnerReplicaSet resource")
|
Expect(err).NotTo(HaveOccurred(), "failed to create test RunnerReplicaSet resource")
|
||||||
|
|
||||||
runners := actionsv1alpha1.RunnerList{Items: []actionsv1alpha1.Runner{}}
|
|
||||||
|
|
||||||
Eventually(
|
Eventually(
|
||||||
func() int {
|
getRunnerCount,
|
||||||
selector, err := metav1.LabelSelectorAsSelector(
|
time.Second*5, time.Second).Should(BeEquivalentTo(1))
|
||||||
&metav1.LabelSelector{
|
|
||||||
MatchLabels: map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
logf.Log.Error(err, "failed to create labelselector")
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
err = k8sClient.List(
|
|
||||||
ctx,
|
|
||||||
&runners,
|
|
||||||
client.InNamespace(ns.Name),
|
|
||||||
client.MatchingLabelsSelector{Selector: selector},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
logf.Log.Error(err, "list runners")
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
runnersList.Sync(runners.Items)
|
|
||||||
|
|
||||||
return len(runners.Items)
|
|
||||||
},
|
|
||||||
time.Second*5, time.Millisecond*500).Should(BeEquivalentTo(1))
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should create 2 runners when specified 2 replicas", func() {
|
||||||
{
|
{
|
||||||
// We wrap the update in the Eventually block to avoid the below error that occurs due to concurrent modification
|
rs := &actionsv1alpha1.RunnerReplicaSet{
|
||||||
// made by the controller to update .Status.AvailableReplicas and .Status.ReadyReplicas
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
// Operation cannot be fulfilled on runnerreplicasets.actions.summerwind.dev "example-runnerreplicaset": the object has been modified; please apply your changes to the latest version and try again
|
Name: name,
|
||||||
Eventually(func() error {
|
Namespace: ns.Name,
|
||||||
var rs actionsv1alpha1.RunnerReplicaSet
|
|
||||||
|
|
||||||
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns.Name, Name: name}, &rs)
|
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred(), "failed to get test RunnerReplicaSet resource")
|
|
||||||
|
|
||||||
rs.Spec.Replicas = intPtr(2)
|
|
||||||
|
|
||||||
return k8sClient.Update(ctx, &rs)
|
|
||||||
},
|
|
||||||
time.Second*1, time.Millisecond*500).Should(BeNil())
|
|
||||||
|
|
||||||
runners := actionsv1alpha1.RunnerList{Items: []actionsv1alpha1.Runner{}}
|
|
||||||
|
|
||||||
Eventually(
|
|
||||||
func() int {
|
|
||||||
selector, err := metav1.LabelSelectorAsSelector(
|
|
||||||
&metav1.LabelSelector{
|
|
||||||
MatchLabels: map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
logf.Log.Error(err, "failed to create labelselector")
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
err = k8sClient.List(
|
|
||||||
ctx,
|
|
||||||
&runners,
|
|
||||||
client.InNamespace(ns.Name),
|
|
||||||
client.MatchingLabelsSelector{Selector: selector},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
logf.Log.Error(err, "list runners")
|
|
||||||
}
|
|
||||||
|
|
||||||
runnersList.Sync(runners.Items)
|
|
||||||
|
|
||||||
return len(runners.Items)
|
|
||||||
},
|
},
|
||||||
time.Second*5, time.Millisecond*500).Should(BeEquivalentTo(2))
|
Spec: actionsv1alpha1.RunnerReplicaSetSpec{
|
||||||
}
|
Replicas: intPtr(2),
|
||||||
|
Selector: &metav1.LabelSelector{
|
||||||
{
|
|
||||||
// We wrap the update in the Eventually block to avoid the below error that occurs due to concurrent modification
|
|
||||||
// made by the controller to update .Status.AvailableReplicas and .Status.ReadyReplicas
|
|
||||||
// Operation cannot be fulfilled on runnersets.actions.summerwind.dev "example-runnerset": the object has been modified; please apply your changes to the latest version and try again
|
|
||||||
Eventually(func() error {
|
|
||||||
var rs actionsv1alpha1.RunnerReplicaSet
|
|
||||||
|
|
||||||
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns.Name, Name: name}, &rs)
|
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred(), "failed to get test RunnerReplicaSet resource")
|
|
||||||
|
|
||||||
rs.Spec.Replicas = intPtr(0)
|
|
||||||
|
|
||||||
return k8sClient.Update(ctx, &rs)
|
|
||||||
},
|
|
||||||
time.Second*1, time.Millisecond*500).Should(BeNil())
|
|
||||||
|
|
||||||
runners := actionsv1alpha1.RunnerList{Items: []actionsv1alpha1.Runner{}}
|
|
||||||
|
|
||||||
Eventually(
|
|
||||||
func() int {
|
|
||||||
selector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
|
|
||||||
MatchLabels: map[string]string{
|
MatchLabels: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
},
|
},
|
||||||
})
|
},
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Template: actionsv1alpha1.RunnerTemplate{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
var regOnly actionsv1alpha1.Runner
|
Labels: map[string]string{
|
||||||
if err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns.Name, Name: registrationOnlyRunnerNameFor(name)}, ®Only); err != nil {
|
"foo": "bar",
|
||||||
logf.Log.Info(fmt.Sprintf("Failed getting registration-only runner in test: %v", err))
|
},
|
||||||
return -1
|
},
|
||||||
} else {
|
Spec: actionsv1alpha1.RunnerSpec{
|
||||||
updated := regOnly.DeepCopy()
|
RunnerConfig: actionsv1alpha1.RunnerConfig{
|
||||||
updated.Status.Phase = "Completed"
|
Repository: "test/valid",
|
||||||
|
Image: "bar",
|
||||||
if err := k8sClient.Status().Patch(ctx, updated, client.MergeFrom(®Only)); err != nil {
|
},
|
||||||
logf.Log.Info(fmt.Sprintf("Failed updating registration-only runner in test: %v", err))
|
RunnerPodSpec: actionsv1alpha1.RunnerPodSpec{
|
||||||
return -1
|
Env: []corev1.EnvVar{
|
||||||
}
|
{Name: "FOO", Value: "FOOVALUE"},
|
||||||
|
},
|
||||||
runnersList.AddOffline([]actionsv1alpha1.Runner{*updated})
|
},
|
||||||
}
|
},
|
||||||
|
},
|
||||||
if err := k8sClient.List(ctx, &runners, client.InNamespace(ns.Name), client.MatchingLabelsSelector{Selector: selector}); err != nil {
|
|
||||||
logf.Log.Error(err, "list runners")
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
runnersList.Sync(runners.Items)
|
|
||||||
|
|
||||||
return len(runners.Items)
|
|
||||||
},
|
},
|
||||||
time.Second*5, time.Millisecond*500).Should(BeEquivalentTo(0))
|
}
|
||||||
|
|
||||||
|
err := k8sClient.Create(ctx, rs)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to create test RunnerReplicaSet resource")
|
||||||
|
|
||||||
|
Eventually(
|
||||||
|
getRunnerCount,
|
||||||
|
time.Second*5, time.Second).Should(BeEquivalentTo(2))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should not create any runners when specified 0 replicas", func() {
|
||||||
|
{
|
||||||
|
rs := &actionsv1alpha1.RunnerReplicaSet{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Namespace: ns.Name,
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerReplicaSetSpec{
|
||||||
|
Replicas: intPtr(0),
|
||||||
|
Selector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Template: actionsv1alpha1.RunnerTemplate{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Spec: actionsv1alpha1.RunnerSpec{
|
||||||
|
RunnerConfig: actionsv1alpha1.RunnerConfig{
|
||||||
|
Repository: "test/valid",
|
||||||
|
Image: "bar",
|
||||||
|
},
|
||||||
|
RunnerPodSpec: actionsv1alpha1.RunnerPodSpec{
|
||||||
|
Env: []corev1.EnvVar{
|
||||||
|
{Name: "FOO", Value: "FOOVALUE"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := k8sClient.Create(ctx, rs)
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to create test RunnerReplicaSet resource")
|
||||||
|
|
||||||
|
Consistently(
|
||||||
|
getRunnerCount,
|
||||||
|
time.Second*5, time.Second).Should(BeEquivalentTo(0))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
|
||||||
"k8s.io/apimachinery/pkg/types"
|
|
||||||
|
|
||||||
"github.com/go-logr/logr"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
@@ -36,10 +33,7 @@ import (
|
|||||||
|
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
"github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"
|
||||||
"github.com/actions-runner-controller/actions-runner-controller/controllers/metrics"
|
"github.com/actions-runner-controller/actions-runner-controller/controllers/metrics"
|
||||||
)
|
"github.com/go-logr/logr"
|
||||||
|
|
||||||
const (
|
|
||||||
LabelKeyRunnerSetName = "runnerset-name"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunnerSetReconciler reconciles a Runner object
|
// RunnerSetReconciler reconciles a Runner object
|
||||||
@@ -51,11 +45,12 @@ type RunnerSetReconciler struct {
|
|||||||
Recorder record.EventRecorder
|
Recorder record.EventRecorder
|
||||||
Scheme *runtime.Scheme
|
Scheme *runtime.Scheme
|
||||||
|
|
||||||
CommonRunnerLabels []string
|
CommonRunnerLabels []string
|
||||||
GitHubBaseURL string
|
GitHubBaseURL string
|
||||||
RunnerImage string
|
RunnerImage string
|
||||||
DockerImage string
|
RunnerImagePullSecrets []string
|
||||||
DockerRegistryMirror string
|
DockerImage string
|
||||||
|
DockerRegistryMirror string
|
||||||
}
|
}
|
||||||
|
|
||||||
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runnersets,verbs=get;list;watch;create;update;patch;delete
|
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runnersets,verbs=get;list;watch;create;update;patch;delete
|
||||||
@@ -63,6 +58,7 @@ type RunnerSetReconciler struct {
|
|||||||
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runnersets/status,verbs=get;update;patch
|
// +kubebuilder:rbac:groups=actions.summerwind.dev,resources=runnersets/status,verbs=get;update;patch
|
||||||
// +kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=get;list;watch;create;update;patch;delete
|
// +kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=get;list;watch;create;update;patch;delete
|
||||||
// +kubebuilder:rbac:groups=apps,resources=statefulsets/status,verbs=get;update;patch
|
// +kubebuilder:rbac:groups=apps,resources=statefulsets/status,verbs=get;update;patch
|
||||||
|
// +kubebuilder:rbac:groups=core,resources=persistentvolumeclaims,verbs=get;list;watch;create;update;patch;delete
|
||||||
// +kubebuilder:rbac:groups=core,resources=events,verbs=create;patch
|
// +kubebuilder:rbac:groups=core,resources=events,verbs=create;patch
|
||||||
// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;create;update
|
// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;create;update
|
||||||
|
|
||||||
@@ -89,6 +85,18 @@ func (r *RunnerSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
|
|||||||
|
|
||||||
metrics.SetRunnerSet(*runnerSet)
|
metrics.SetRunnerSet(*runnerSet)
|
||||||
|
|
||||||
|
var statefulsetList appsv1.StatefulSetList
|
||||||
|
if err := r.List(ctx, &statefulsetList, client.InNamespace(req.Namespace), client.MatchingFields{runnerSetOwnerKey: req.Name}); err != nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
statefulsets := statefulsetList.Items
|
||||||
|
|
||||||
|
if len(statefulsets) > 1000 {
|
||||||
|
log.Info("Postponed reconcilation to prevent potential infinite loop. If you're really scaling more than 1000 statefulsets, do change this hard-coded threshold!")
|
||||||
|
return ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
desiredStatefulSet, err := r.newStatefulSet(runnerSet)
|
desiredStatefulSet, err := r.newStatefulSet(runnerSet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Recorder.Event(runnerSet, corev1.EventTypeNormal, "RunnerAutoscalingFailure", err.Error())
|
r.Recorder.Event(runnerSet, corev1.EventTypeNormal, "RunnerAutoscalingFailure", err.Error())
|
||||||
@@ -98,108 +106,49 @@ func (r *RunnerSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
|
|||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
liveStatefulSet := &appsv1.StatefulSet{}
|
addedReplicas := int32(1)
|
||||||
if err := r.Get(ctx, types.NamespacedName{Namespace: runnerSet.Namespace, Name: runnerSet.Name}, liveStatefulSet); err != nil {
|
create := desiredStatefulSet.DeepCopy()
|
||||||
if !errors.IsNotFound(err) {
|
create.Spec.Replicas = &addedReplicas
|
||||||
log.Error(err, "Failed to get live statefulset")
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := r.Client.Create(ctx, desiredStatefulSet); err != nil {
|
|
||||||
log.Error(err, "Failed to create statefulset resource")
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
liveTemplateHash, ok := getStatefulSetTemplateHash(liveStatefulSet)
|
|
||||||
if !ok {
|
|
||||||
log.Info("Failed to get template hash of newest statefulset resource. It must be in an invalid state. Please manually delete the statefulset so that it is recreated")
|
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
desiredTemplateHash, ok := getStatefulSetTemplateHash(desiredStatefulSet)
|
|
||||||
if !ok {
|
|
||||||
log.Info("Failed to get template hash of desired statefulset. It must be in an invalid state. Please manually delete the statefulset so that it is recreated")
|
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if liveTemplateHash != desiredTemplateHash {
|
|
||||||
copy := liveStatefulSet.DeepCopy()
|
|
||||||
copy.Spec = desiredStatefulSet.Spec
|
|
||||||
|
|
||||||
if err := r.Client.Patch(ctx, copy, client.MergeFrom(liveStatefulSet)); err != nil {
|
|
||||||
log.Error(err, "Failed to patch statefulset", "reason", errors.ReasonForError(err))
|
|
||||||
|
|
||||||
if errors.IsInvalid(err) {
|
|
||||||
// NOTE: This might not be ideal but deal the forbidden error by recreating the statefulset
|
|
||||||
// Probably we'd better create a registration-only runner to prevent queued jobs from immediately failing.
|
|
||||||
//
|
|
||||||
// 2021-06-13T07:19:52.760Z ERROR actions-runner-controller.runnerset Failed to patch statefulset
|
|
||||||
// {"runnerset": "default/example-runnerset", "error": "StatefulSet.apps \"example-runnerset\" is invalid: s
|
|
||||||
// pec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy'
|
|
||||||
// are forbidden"}
|
|
||||||
//
|
|
||||||
// Even though the error message includes "Forbidden", this error's reason is "Invalid".
|
|
||||||
// That's why we're using errors.IsInvalid above.
|
|
||||||
|
|
||||||
if err := r.Client.Delete(ctx, liveStatefulSet); err != nil {
|
|
||||||
log.Error(err, "Failed to delete statefulset for force-update")
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
log.Info("Deleted statefulset for force-update")
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// We requeue in order to clean up old runner replica sets later.
|
|
||||||
// Otherwise, they aren't cleaned up until the next re-sync interval.
|
|
||||||
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultReplicas = 1
|
const defaultReplicas = 1
|
||||||
|
|
||||||
var replicasOfLiveStatefulSet *int
|
|
||||||
if liveStatefulSet.Spec.Replicas != nil {
|
|
||||||
v := int(*liveStatefulSet.Spec.Replicas)
|
|
||||||
replicasOfLiveStatefulSet = &v
|
|
||||||
}
|
|
||||||
|
|
||||||
var replicasOfDesiredStatefulSet *int
|
var replicasOfDesiredStatefulSet *int
|
||||||
if desiredStatefulSet.Spec.Replicas != nil {
|
if desiredStatefulSet.Spec.Replicas != nil {
|
||||||
v := int(*desiredStatefulSet.Spec.Replicas)
|
v := int(*desiredStatefulSet.Spec.Replicas)
|
||||||
replicasOfDesiredStatefulSet = &v
|
replicasOfDesiredStatefulSet = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
currentDesiredReplicas := getIntOrDefault(replicasOfLiveStatefulSet, defaultReplicas)
|
|
||||||
newDesiredReplicas := getIntOrDefault(replicasOfDesiredStatefulSet, defaultReplicas)
|
newDesiredReplicas := getIntOrDefault(replicasOfDesiredStatefulSet, defaultReplicas)
|
||||||
|
|
||||||
// Please add more conditions that we can in-place update the newest runnerreplicaset without disruption
|
effectiveTime := runnerSet.Spec.EffectiveTime
|
||||||
if currentDesiredReplicas != newDesiredReplicas {
|
ephemeral := runnerSet.Spec.Ephemeral == nil || *runnerSet.Spec.Ephemeral
|
||||||
v := int32(newDesiredReplicas)
|
|
||||||
|
|
||||||
updated := liveStatefulSet.DeepCopy()
|
var owners []client.Object
|
||||||
updated.Spec.Replicas = &v
|
|
||||||
|
|
||||||
if err := r.Client.Patch(ctx, updated, client.MergeFrom(liveStatefulSet)); err != nil {
|
for _, ss := range statefulsets {
|
||||||
log.Error(err, "Failed to update statefulset")
|
ss := ss
|
||||||
|
owners = append(owners, &ss)
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
statusReplicas := int(liveStatefulSet.Status.Replicas)
|
if res, err := syncVolumes(ctx, r.Client, log, req.Namespace, runnerSet, statefulsets); err != nil {
|
||||||
statusReadyReplicas := int(liveStatefulSet.Status.ReadyReplicas)
|
return ctrl.Result{}, err
|
||||||
totalCurrentReplicas := int(liveStatefulSet.Status.CurrentReplicas)
|
} else if res != nil {
|
||||||
updatedReplicas := int(liveStatefulSet.Status.UpdatedReplicas)
|
return *res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := syncRunnerPodsOwners(ctx, r.Client, log, effectiveTime, newDesiredReplicas, func() client.Object { return create.DeepCopy() }, ephemeral, owners)
|
||||||
|
if err != nil || res == nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var statusReplicas, statusReadyReplicas, totalCurrentReplicas, updatedReplicas int
|
||||||
|
|
||||||
|
for _, ss := range res.currentObjects {
|
||||||
|
statusReplicas += int(ss.statefulSet.Status.Replicas)
|
||||||
|
statusReadyReplicas += int(ss.statefulSet.Status.ReadyReplicas)
|
||||||
|
totalCurrentReplicas += int(ss.statefulSet.Status.CurrentReplicas)
|
||||||
|
updatedReplicas += int(ss.statefulSet.Status.UpdatedReplicas)
|
||||||
|
}
|
||||||
|
|
||||||
status := runnerSet.Status.DeepCopy()
|
status := runnerSet.Status.DeepCopy()
|
||||||
|
|
||||||
@@ -224,12 +173,6 @@ func (r *RunnerSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
|
|||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStatefulSetTemplateHash(rs *appsv1.StatefulSet) (string, bool) {
|
|
||||||
hash, ok := rs.Labels[LabelKeyRunnerTemplateHash]
|
|
||||||
|
|
||||||
return hash, ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func getRunnerSetSelector(runnerSet *v1alpha1.RunnerSet) *metav1.LabelSelector {
|
func getRunnerSetSelector(runnerSet *v1alpha1.RunnerSet) *metav1.LabelSelector {
|
||||||
selector := runnerSet.Spec.Selector
|
selector := runnerSet.Spec.Selector
|
||||||
if selector == nil {
|
if selector == nil {
|
||||||
@@ -245,21 +188,14 @@ var LabelValuePodMutation = "true"
|
|||||||
func (r *RunnerSetReconciler) newStatefulSet(runnerSet *v1alpha1.RunnerSet) (*appsv1.StatefulSet, error) {
|
func (r *RunnerSetReconciler) newStatefulSet(runnerSet *v1alpha1.RunnerSet) (*appsv1.StatefulSet, error) {
|
||||||
runnerSetWithOverrides := *runnerSet.Spec.DeepCopy()
|
runnerSetWithOverrides := *runnerSet.Spec.DeepCopy()
|
||||||
|
|
||||||
for _, l := range r.CommonRunnerLabels {
|
runnerSetWithOverrides.Labels = append(runnerSetWithOverrides.Labels, r.CommonRunnerLabels...)
|
||||||
runnerSetWithOverrides.Labels = append(runnerSetWithOverrides.Labels, l)
|
|
||||||
}
|
|
||||||
|
|
||||||
// This label selector is used by default when rd.Spec.Selector is empty.
|
|
||||||
runnerSetWithOverrides.Template.ObjectMeta.Labels = CloneAndAddLabel(runnerSetWithOverrides.Template.ObjectMeta.Labels, LabelKeyRunnerSetName, runnerSet.Name)
|
|
||||||
|
|
||||||
runnerSetWithOverrides.Template.ObjectMeta.Labels = CloneAndAddLabel(runnerSetWithOverrides.Template.ObjectMeta.Labels, LabelKeyPodMutation, LabelValuePodMutation)
|
|
||||||
|
|
||||||
template := corev1.Pod{
|
template := corev1.Pod{
|
||||||
ObjectMeta: runnerSetWithOverrides.StatefulSetSpec.Template.ObjectMeta,
|
ObjectMeta: runnerSetWithOverrides.StatefulSetSpec.Template.ObjectMeta,
|
||||||
Spec: runnerSetWithOverrides.StatefulSetSpec.Template.Spec,
|
Spec: runnerSetWithOverrides.StatefulSetSpec.Template.Spec,
|
||||||
}
|
}
|
||||||
|
|
||||||
pod, err := newRunnerPod(template, runnerSet.Spec.RunnerConfig, r.RunnerImage, r.DockerImage, r.DockerRegistryMirror, r.GitHubBaseURL, false)
|
pod, err := newRunnerPod(runnerSet.Name, template, runnerSet.Spec.RunnerConfig, r.RunnerImage, r.RunnerImagePullSecrets, r.DockerImage, r.DockerRegistryMirror, r.GitHubBaseURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -288,9 +224,12 @@ func (r *RunnerSetReconciler) newStatefulSet(runnerSet *v1alpha1.RunnerSet) (*ap
|
|||||||
rs := appsv1.StatefulSet{
|
rs := appsv1.StatefulSet{
|
||||||
TypeMeta: metav1.TypeMeta{},
|
TypeMeta: metav1.TypeMeta{},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: runnerSet.ObjectMeta.Name,
|
GenerateName: runnerSet.ObjectMeta.Name + "-",
|
||||||
Namespace: runnerSet.ObjectMeta.Namespace,
|
Namespace: runnerSet.ObjectMeta.Namespace,
|
||||||
Labels: CloneAndAddLabel(runnerSet.ObjectMeta.Labels, LabelKeyRunnerTemplateHash, templateHash),
|
Labels: CloneAndAddLabel(runnerSet.ObjectMeta.Labels, LabelKeyRunnerTemplateHash, templateHash),
|
||||||
|
Annotations: map[string]string{
|
||||||
|
SyncTimeAnnotationKey: time.Now().Format(time.RFC3339),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Spec: runnerSetWithOverrides.StatefulSetSpec,
|
Spec: runnerSetWithOverrides.StatefulSetSpec,
|
||||||
}
|
}
|
||||||
@@ -310,6 +249,22 @@ func (r *RunnerSetReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
|||||||
|
|
||||||
r.Recorder = mgr.GetEventRecorderFor(name)
|
r.Recorder = mgr.GetEventRecorderFor(name)
|
||||||
|
|
||||||
|
if err := mgr.GetFieldIndexer().IndexField(context.TODO(), &appsv1.StatefulSet{}, runnerSetOwnerKey, func(rawObj client.Object) []string {
|
||||||
|
set := rawObj.(*appsv1.StatefulSet)
|
||||||
|
owner := metav1.GetControllerOf(set)
|
||||||
|
if owner == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if owner.APIVersion != v1alpha1.GroupVersion.String() || owner.Kind != "RunnerSet" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return []string{owner.Name}
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return ctrl.NewControllerManagedBy(mgr).
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
For(&v1alpha1.RunnerSet{}).
|
For(&v1alpha1.RunnerSet{}).
|
||||||
Owns(&appsv1.StatefulSet{}).
|
Owns(&appsv1.StatefulSet{}).
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user