Skip to content

Commit e10637c

Browse files
authored
Merge pull request #66 from summerwind/org-runner-autoscale
feat: Organizational RunnerDeployment Autoscaling
2 parents be0850a + ae30648 commit e10637c

12 files changed

+909
-176
lines changed

README.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,25 @@ In the below example, `actions-runner` checks for pending workflow runs for each
199199
apiVersion: actions.summerwind.dev/v1alpha1
200200
kind: RunnerDeployment
201201
metadata:
202-
name: summerwind-actions-runner-controller
202+
name: example-runner-deployment
203203
spec:
204-
minReplicas: 1
205-
maxReplicas: 3
206204
template:
207205
spec:
208206
repository: summerwind/actions-runner-controller
207+
---
208+
apiVersion: actions.summerwind.dev/v1alpha1
209+
kind: HorizontalRunnerAutoscaler
210+
metadata:
211+
name: example-runner-deployment-autoscaler
212+
spec:
213+
scaleTargetRef:
214+
name: example-runner-deployment
215+
minReplicas: 1
216+
maxReplicas: 3
217+
metrics:
218+
- type: TotalNumberOfQueuedAndInProgressWorkflowRuns
219+
repositoryNames:
220+
- summerwind/actions-runner-controller
209221
```
210222

211223
Please also note that the sync period is set to 10 minutes by default and it's configurable via `--sync-period` flag.
@@ -217,14 +229,26 @@ By default, it doesn't scale down until the grace period of 10 minutes passes af
217229
apiVersion: actions.summerwind.dev/v1alpha1
218230
kind: RunnerDeployment
219231
metadata:
220-
name: summerwind-actions-runner-controller
232+
name: example-runner-deployment
221233
spec:
222-
minReplicas: 1
223-
maxReplicas: 3
224-
scaleDownDelaySecondsAfterScaleUp: 1m
225234
template:
226235
spec:
227236
repository: summerwind/actions-runner-controller
237+
---
238+
apiVersion: actions.summerwind.dev/v1alpha1
239+
kind: HorizontalRunnerAutoscaler
240+
metadata:
241+
name: example-runner-deployment-autoscaler
242+
spec:
243+
scaleTargetRef:
244+
name: example-runner-deployment
245+
minReplicas: 1
246+
maxReplicas: 3
247+
scaleDownDelaySecondsAfterScaleOut: 60
248+
metrics:
249+
- type: TotalNumberOfQueuedAndInProgressWorkflowRuns
250+
repositoryNames:
251+
- summerwind/actions-runner-controller
228252
```
229253

230254
## Additional tweaks
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
Copyright 2020 The actions-runner-controller authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// HorizontalRunnerAutoscalerSpec defines the desired state of HorizontalRunnerAutoscaler
24+
type HorizontalRunnerAutoscalerSpec struct {
25+
// ScaleTargetRef sis the reference to scaled resource like RunnerDeployment
26+
ScaleTargetRef ScaleTargetRef `json:"scaleTargetRef,omitempty"`
27+
28+
// MinReplicas is the minimum number of replicas the deployment is allowed to scale
29+
// +optional
30+
MinReplicas *int `json:"minReplicas,omitempty"`
31+
32+
// MinReplicas is the maximum number of replicas the deployment is allowed to scale
33+
// +optional
34+
MaxReplicas *int `json:"maxReplicas,omitempty"`
35+
36+
// ScaleDownDelaySecondsAfterScaleUp is the approximate delay for a scale down followed by a scale up
37+
// Used to prevent flapping (down->up->down->... loop)
38+
// +optional
39+
ScaleDownDelaySecondsAfterScaleUp *int `json:"scaleDownDelaySecondsAfterScaleOut,omitempty"`
40+
41+
// Metrics is the collection of various metric targets to calculate desired number of runners
42+
// +optional
43+
Metrics []MetricSpec `json:"metrics,omitempty"`
44+
}
45+
46+
type ScaleTargetRef struct {
47+
Name string `json:"name,omitempty"`
48+
}
49+
50+
type MetricSpec struct {
51+
// Type is the type of metric to be used for autoscaling.
52+
// The only supported Type is TotalNumberOfQueuedAndInProgressWorkflowRuns
53+
Type string `json:"type,omitempty"`
54+
55+
// RepositoryNames is the list of repository names to be used for calculating the metric.
56+
// For example, a repository name is the REPO part of `github.com/USER/REPO`.
57+
// +optional
58+
RepositoryNames []string `json:"repositoryNames,omitempty"`
59+
}
60+
61+
type HorizontalRunnerAutoscalerStatus struct {
62+
// ObservedGeneration is the most recent generation observed for the target. It corresponds to e.g.
63+
// RunnerDeployment's generation, which is updated on mutation by the API Server.
64+
// +optional
65+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
66+
67+
// DesiredReplicas is the total number of desired, non-terminated and latest pods to be set for the primary RunnerSet
68+
// This doesn't include outdated pods while upgrading the deployment and replacing the runnerset.
69+
// +optional
70+
DesiredReplicas *int `json:"desiredReplicas,omitempty"`
71+
72+
// +optional
73+
LastSuccessfulScaleOutTime *metav1.Time `json:"lastSuccessfulScaleOutTime,omitempty"`
74+
}
75+
76+
// +kubebuilder:object:root=true
77+
// +kubebuilder:subresource:status
78+
// +kubebuilder:printcolumn:JSONPath=".spec.minReplicas",name=Min,type=number
79+
// +kubebuilder:printcolumn:JSONPath=".spec.maxReplicas",name=Max,type=number
80+
// +kubebuilder:printcolumn:JSONPath=".status.desiredReplicas",name=Desired,type=number
81+
82+
// HorizontalRunnerAutoscaler is the Schema for the horizontalrunnerautoscaler API
83+
type HorizontalRunnerAutoscaler struct {
84+
metav1.TypeMeta `json:",inline"`
85+
metav1.ObjectMeta `json:"metadata,omitempty"`
86+
87+
Spec HorizontalRunnerAutoscalerSpec `json:"spec,omitempty"`
88+
Status HorizontalRunnerAutoscalerStatus `json:"status,omitempty"`
89+
}
90+
91+
// +kubebuilder:object:root=true
92+
93+
// HorizontalRunnerAutoscalerList contains a list of HorizontalRunnerAutoscaler
94+
type HorizontalRunnerAutoscalerList struct {
95+
metav1.TypeMeta `json:",inline"`
96+
metav1.ListMeta `json:"metadata,omitempty"`
97+
Items []HorizontalRunnerAutoscaler `json:"items"`
98+
}
99+
100+
func init() {
101+
SchemeBuilder.Register(&HorizontalRunnerAutoscaler{}, &HorizontalRunnerAutoscalerList{})
102+
}

api/v1alpha1/runnerdeployment_types.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,15 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
)
2222

23+
const (
24+
AutoscalingMetricTypeTotalNumberOfQueuedAndInProgressWorkflowRuns = "TotalNumberOfQueuedAndInProgressWorkflowRuns"
25+
)
26+
2327
// RunnerReplicaSetSpec defines the desired state of RunnerDeployment
2428
type RunnerDeploymentSpec struct {
2529
// +optional
2630
Replicas *int `json:"replicas,omitempty"`
2731

28-
// MinReplicas is the minimum number of replicas the deployment is allowed to scale
29-
// +optional
30-
MinReplicas *int `json:"minReplicas,omitempty"`
31-
32-
// MinReplicas is the maximum number of replicas the deployment is allowed to scale
33-
// +optional
34-
MaxReplicas *int `json:"maxReplicas,omitempty"`
35-
36-
// ScaleDownDelaySecondsAfterScaleUp is the approximate delay for a scale down followed by a scale up
37-
// Used to prevent flapping (down->up->down->... loop)
38-
// +optional
39-
ScaleDownDelaySecondsAfterScaleUp *int `json:"scaleDownDelaySecondsAfterScaleOut,omitempty"`
40-
4132
Template RunnerTemplate `json:"template"`
4233
}
4334

@@ -49,9 +40,6 @@ type RunnerDeploymentStatus struct {
4940
// This doesn't include outdated pods while upgrading the deployment and replacing the runnerset.
5041
// +optional
5142
Replicas *int `json:"desiredReplicas,omitempty"`
52-
53-
// +optional
54-
LastSuccessfulScaleOutTime *metav1.Time `json:"lastSuccessfulScaleOutTime,omitempty"`
5543
}
5644

5745
// +kubebuilder:object:root=true

0 commit comments

Comments
 (0)