Skip to content

Commit 40811eb

Browse files
authored
Support the controller to watching a single namespace. (#2374)
1 parent 3417c5a commit 40811eb

14 files changed

Lines changed: 666 additions & 35 deletions

.github/workflows/e2e-test-linux-vm.yaml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,108 @@ jobs:
120120
helm uninstall ${{ steps.install_arc.outputs.ARC_NAME }} --namespace arc-runners
121121
kubectl wait --timeout=10s --for=delete AutoScalingRunnerSet -n demo -l app.kubernetes.io/instance=${{ steps.install_arc.outputs.ARC_NAME }}
122122
123+
- name: Dump gha-runner-scale-set-controller logs
124+
if: always() && steps.install_arc_controller.outcome == 'success'
125+
run: |
126+
kubectl logs deployment/arc-gha-runner-scale-set-controller -n arc-systems
127+
128+
single-namespace-setup:
129+
runs-on: ubuntu-latest
130+
steps:
131+
- uses: actions/checkout@v3
132+
133+
- name: Resolve inputs
134+
id: resolved_inputs
135+
run: |
136+
TARGET_ORG="${{env.TARGET_ORG}}"
137+
TARGET_REPO="${{env.TARGET_REPO}}"
138+
if [ ! -z "${{inputs.target_org}}" ]; then
139+
TARGET_ORG="${{inputs.target_org}}"
140+
fi
141+
if [ ! -z "${{inputs.target_repo}}" ]; then
142+
TARGET_REPO="${{inputs.target_repo}}"
143+
fi
144+
echo "TARGET_ORG=$TARGET_ORG" >> $GITHUB_OUTPUT
145+
echo "TARGET_REPO=$TARGET_REPO" >> $GITHUB_OUTPUT
146+
147+
- uses: ./.github/actions/setup-arc-e2e
148+
id: setup
149+
with:
150+
github-app-id: ${{secrets.ACTIONS_ACCESS_APP_ID}}
151+
github-app-pk: ${{secrets.ACTIONS_ACCESS_PK}}
152+
github-app-org: ${{steps.resolved_inputs.outputs.TARGET_ORG}}
153+
docker-image-name: ${{env.IMAGE_NAME}}
154+
docker-image-tag: ${{env.IMAGE_VERSION}}
155+
156+
- name: Install gha-runner-scale-set-controller
157+
id: install_arc_controller
158+
run: |
159+
kubectl create namespace arc-runners
160+
helm install arc \
161+
--namespace "arc-systems" \
162+
--create-namespace \
163+
--set image.repository=${{ env.IMAGE_NAME }} \
164+
--set image.tag=${{ env.IMAGE_VERSION }} \
165+
--set flags.watchSingleNamespace=arc-runners \
166+
./charts/gha-runner-scale-set-controller \
167+
--debug
168+
count=0
169+
while true; do
170+
POD_NAME=$(kubectl get pods -n arc-systems -l app.kubernetes.io/name=gha-runner-scale-set-controller -o name)
171+
if [ -n "$POD_NAME" ]; then
172+
echo "Pod found: $POD_NAME"
173+
break
174+
fi
175+
if [ "$count" -ge 10 ]; then
176+
echo "Timeout waiting for controller pod with label app.kubernetes.io/name=gha-runner-scale-set-controller"
177+
exit 1
178+
fi
179+
sleep 1
180+
done
181+
kubectl wait --timeout=30s --for=condition=ready pod -n arc-systems -l app.kubernetes.io/name=gha-runner-scale-set-controller
182+
kubectl get pod -n arc-systems
183+
kubectl describe deployment arc-gha-runner-scale-set-controller -n arc-systems
184+
185+
- name: Install gha-runner-scale-set
186+
id: install_arc
187+
run: |
188+
ARC_NAME=arc-runner-${{github.job}}-$(date +'%M-%S')-$(($RANDOM % 100 + 1))
189+
helm install "$ARC_NAME" \
190+
--namespace "arc-runners" \
191+
--create-namespace \
192+
--set githubConfigUrl="https://github.com/${{ steps.resolved_inputs.outputs.TARGET_ORG }}/${{steps.resolved_inputs.outputs.TARGET_REPO}}" \
193+
--set githubConfigSecret.github_token="${{ steps.setup.outputs.token }}" \
194+
./charts/gha-runner-scale-set \
195+
--debug
196+
echo "ARC_NAME=$ARC_NAME" >> $GITHUB_OUTPUT
197+
count=0
198+
while true; do
199+
POD_NAME=$(kubectl get pods -n arc-systems -l auto-scaling-runner-set-name=$ARC_NAME -o name)
200+
if [ -n "$POD_NAME" ]; then
201+
echo "Pod found: $POD_NAME"
202+
break
203+
fi
204+
if [ "$count" -ge 10 ]; then
205+
echo "Timeout waiting for listener pod with label auto-scaling-runner-set-name=$ARC_NAME"
206+
exit 1
207+
fi
208+
sleep 1
209+
done
210+
kubectl wait --timeout=30s --for=condition=ready pod -n arc-systems -l auto-scaling-runner-set-name=$ARC_NAME
211+
kubectl get pod -n arc-systems
212+
213+
- name: Test ARC scales pods up and down
214+
run: |
215+
export GITHUB_TOKEN="${{ steps.setup.outputs.token }}"
216+
export ARC_NAME="${{ steps.install_arc.outputs.ARC_NAME }}"
217+
go test ./test_e2e_arc -v
218+
219+
- name: Uninstall gha-runner-scale-set
220+
if: always() && steps.install_arc.outcome == 'success'
221+
run: |
222+
helm uninstall ${{ steps.install_arc.outputs.ARC_NAME }} --namespace arc-runners
223+
kubectl wait --timeout=10s --for=delete AutoScalingRunnerSet -n demo -l app.kubernetes.io/instance=${{ steps.install_arc.outputs.ARC_NAME }}
224+
123225
- name: Dump gha-runner-scale-set-controller logs
124226
if: always() && steps.install_arc_controller.outcome == 'success'
125227
run: |

charts/gha-runner-scale-set-controller/templates/_helpers.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ Create the name of the service account to use
8080
{{- include "gha-runner-scale-set-controller.fullname" . }}-manager-cluster-rolebinding
8181
{{- end }}
8282

83+
{{- define "gha-runner-scale-set-controller.managerSingleNamespaceRoleName" -}}
84+
{{- include "gha-runner-scale-set-controller.fullname" . }}-manager-single-namespace-role
85+
{{- end }}
86+
87+
{{- define "gha-runner-scale-set-controller.managerSingleNamespaceRoleBinding" -}}
88+
{{- include "gha-runner-scale-set-controller.fullname" . }}-manager-single-namespace-rolebinding
89+
{{- end }}
90+
8391
{{- define "gha-runner-scale-set-controller.managerListenerRoleName" -}}
8492
{{- include "gha-runner-scale-set-controller.fullname" . }}-manager-listener-role
8593
{{- end }}

charts/gha-runner-scale-set-controller/templates/deployment.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ metadata:
77
{{- include "gha-runner-scale-set-controller.labels" . | nindent 4 }}
88
actions.github.com/controller-service-account-namespace: {{ .Release.Namespace }}
99
actions.github.com/controller-service-account-name: {{ include "gha-runner-scale-set-controller.serviceAccountName" . }}
10+
{{- if .Values.flags.watchSingleNamespace }}
11+
actions.github.com/controller-watch-single-namespace: {{ .Values.flags.watchSingleNamespace }}
12+
{{- end }}
1013
spec:
1114
replicas: {{ default 1 .Values.replicaCount }}
1215
selector:
@@ -53,6 +56,9 @@ spec:
5356
{{- with .Values.flags.logLevel }}
5457
- "--log-level={{ . }}"
5558
{{- end }}
59+
{{- with .Values.flags.watchSingleNamespace }}
60+
- "--watch-single-namespace={{ . }}"
61+
{{- end }}
5662
command:
5763
- "/manager"
5864
env:

charts/gha-runner-scale-set-controller/templates/manager_cluster_role.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if empty .Values.flags.watchSingleNamespace }}
12
apiVersion: rbac.authorization.k8s.io/v1
23
kind: ClusterRole
34
metadata:
@@ -20,6 +21,7 @@ rules:
2021
resources:
2122
- autoscalingrunnersets/finalizers
2223
verbs:
24+
- patch
2325
- update
2426
- apiGroups:
2527
- actions.github.com
@@ -54,6 +56,7 @@ rules:
5456
resources:
5557
- autoscalinglisteners/finalizers
5658
verbs:
59+
- patch
5760
- update
5861
- apiGroups:
5962
- actions.github.com
@@ -92,13 +95,8 @@ rules:
9295
resources:
9396
- ephemeralrunners/finalizers
9497
verbs:
95-
- create
96-
- delete
97-
- get
98-
- list
9998
- patch
10099
- update
101-
- watch
102100
- apiGroups:
103101
- actions.github.com
104102
resources:
@@ -135,3 +133,4 @@ rules:
135133
verbs:
136134
- list
137135
- watch
136+
{{- end }}

charts/gha-runner-scale-set-controller/templates/manager_cluster_role_binding.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if empty .Values.flags.watchSingleNamespace }}
12
apiVersion: rbac.authorization.k8s.io/v1
23
kind: ClusterRoleBinding
34
metadata:
@@ -9,4 +10,5 @@ roleRef:
910
subjects:
1011
- kind: ServiceAccount
1112
name: {{ include "gha-runner-scale-set-controller.serviceAccountName" . }}
12-
namespace: {{ .Release.Namespace }}
13+
namespace: {{ .Release.Namespace }}
14+
{{- end }}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{{- if .Values.flags.watchSingleNamespace }}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: Role
4+
metadata:
5+
name: {{ include "gha-runner-scale-set-controller.managerSingleNamespaceRoleName" . }}
6+
namespace: {{ .Release.Namespace }}
7+
rules:
8+
- apiGroups:
9+
- actions.github.com
10+
resources:
11+
- autoscalinglisteners
12+
verbs:
13+
- create
14+
- delete
15+
- get
16+
- list
17+
- patch
18+
- update
19+
- watch
20+
- apiGroups:
21+
- actions.github.com
22+
resources:
23+
- autoscalinglisteners/status
24+
verbs:
25+
- get
26+
- patch
27+
- update
28+
- apiGroups:
29+
- actions.github.com
30+
resources:
31+
- autoscalinglisteners/finalizers
32+
verbs:
33+
- patch
34+
- update
35+
- apiGroups:
36+
- ""
37+
resources:
38+
- pods
39+
verbs:
40+
- list
41+
- watch
42+
- apiGroups:
43+
- ""
44+
resources:
45+
- serviceaccounts
46+
verbs:
47+
- list
48+
- watch
49+
- apiGroups:
50+
- rbac.authorization.k8s.io
51+
resources:
52+
- rolebindings
53+
verbs:
54+
- list
55+
- watch
56+
- apiGroups:
57+
- rbac.authorization.k8s.io
58+
resources:
59+
- roles
60+
verbs:
61+
- list
62+
- watch
63+
- apiGroups:
64+
- actions.github.com
65+
resources:
66+
- autoscalingrunnersets
67+
verbs:
68+
- list
69+
- watch
70+
- apiGroups:
71+
- actions.github.com
72+
resources:
73+
- ephemeralrunnersets
74+
verbs:
75+
- list
76+
- watch
77+
- apiGroups:
78+
- actions.github.com
79+
resources:
80+
- ephemeralrunners
81+
verbs:
82+
- list
83+
- watch
84+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- if .Values.flags.watchSingleNamespace }}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: RoleBinding
4+
metadata:
5+
name: {{ include "gha-runner-scale-set-controller.managerSingleNamespaceRoleBinding" . }}
6+
namespace: {{ .Release.Namespace }}
7+
roleRef:
8+
apiGroup: rbac.authorization.k8s.io
9+
kind: Role
10+
name: {{ include "gha-runner-scale-set-controller.managerSingleNamespaceRoleName" . }}
11+
subjects:
12+
- kind: ServiceAccount
13+
name: {{ include "gha-runner-scale-set-controller.serviceAccountName" . }}
14+
namespace: {{ .Release.Namespace }}
15+
{{- end }}

0 commit comments

Comments
 (0)