feat: Organization RunnerDeployment with webhook-based autoscaling only for certain repositories (#766)
Resolves #765 Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
parent
d9df455781
commit
7008b0c257
24
README.md
24
README.md
|
|
@ -577,6 +577,30 @@ spec:
|
||||||
duration: "5m"
|
duration: "5m"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To scale up replicas of the runners for `myorg` organization by 1 for 5 minutes on each `check_run`, you write manifests like the below:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kind: RunnerDeployment
|
||||||
|
metadata:
|
||||||
|
name: myrunners
|
||||||
|
spec:
|
||||||
|
organization: myorg
|
||||||
|
---
|
||||||
|
kind: HorizontalRunnerAutoscaler
|
||||||
|
spec:
|
||||||
|
scaleTargetRef:
|
||||||
|
name: myrunners
|
||||||
|
scaleUpTriggers:
|
||||||
|
- githubEvent:
|
||||||
|
checkRun:
|
||||||
|
types: ["created"]
|
||||||
|
status: "queued"
|
||||||
|
# allow only certain repositories within your organization to trigger autoscaling
|
||||||
|
# repositories: ["myrepo", "myanotherrepo"]
|
||||||
|
amount: 1
|
||||||
|
duration: "5m"
|
||||||
|
```
|
||||||
|
|
||||||
###### Example 2: Scale on each `pull_request` event against `develop` or `main` branches
|
###### Example 2: Scale on each `pull_request` event against `develop` or `main` branches
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,10 @@ type CheckRunSpec struct {
|
||||||
// Note that check_run name seem to equal to the job name you've defined in your actions workflow yaml file.
|
// Note that check_run name seem to equal to the job name you've defined in your actions workflow yaml file.
|
||||||
// So it is very likely that you can utilize this to trigger depending on the job.
|
// So it is very likely that you can utilize this to trigger depending on the job.
|
||||||
Names []string `json:"names,omitempty"`
|
Names []string `json:"names,omitempty"`
|
||||||
|
|
||||||
|
// Repositories is a list of GitHub repositories.
|
||||||
|
// Any check_run event whose repository matches one of repositories in the list can trigger autoscaling.
|
||||||
|
Repositories []string `json:"repositories,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,11 @@ func (in *CheckRunSpec) DeepCopyInto(out *CheckRunSpec) {
|
||||||
*out = make([]string, len(*in))
|
*out = make([]string, len(*in))
|
||||||
copy(*out, *in)
|
copy(*out, *in)
|
||||||
}
|
}
|
||||||
|
if in.Repositories != nil {
|
||||||
|
in, out := &in.Repositories, &out.Repositories
|
||||||
|
*out = make([]string, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CheckRunSpec.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CheckRunSpec.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ 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.12.7
|
version: 0.12.8
|
||||||
|
|
||||||
# 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.19.0
|
appVersion: 0.19.0
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,13 @@ spec:
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
type: array
|
type: array
|
||||||
|
repositories:
|
||||||
|
description: Repositories is a list of GitHub repositories.
|
||||||
|
Any check_run event whose repository matches one of
|
||||||
|
repositories in the list can trigger autoscaling.
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
status:
|
status:
|
||||||
type: string
|
type: string
|
||||||
types:
|
types:
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,13 @@ spec:
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
type: array
|
type: array
|
||||||
|
repositories:
|
||||||
|
description: Repositories is a list of GitHub repositories.
|
||||||
|
Any check_run event whose repository matches one of
|
||||||
|
repositories in the list can trigger autoscaling.
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
status:
|
status:
|
||||||
type: string
|
type: string
|
||||||
types:
|
types:
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,4 @@ kind: Kustomization
|
||||||
images:
|
images:
|
||||||
- name: controller
|
- name: controller
|
||||||
newName: summerwind/actions-runner-controller
|
newName: summerwind/actions-runner-controller
|
||||||
newTag: dnsconfig-9fe31ba8
|
newTag: latest
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,16 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) MatchCheckRunEvent(ev
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(scaleUpTrigger.GitHubEvent.CheckRun.Repositories) > 0 {
|
||||||
|
for _, repository := range scaleUpTrigger.GitHubEvent.CheckRun.Repositories {
|
||||||
|
if repository == *event.Repo.Name {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -486,8 +486,9 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
|
||||||
{
|
{
|
||||||
GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{
|
GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{
|
||||||
CheckRun: &actionsv1alpha1.CheckRunSpec{
|
CheckRun: &actionsv1alpha1.CheckRunSpec{
|
||||||
Types: []string{"created"},
|
Types: []string{"created"},
|
||||||
Status: "pending",
|
Status: "pending",
|
||||||
|
Repositories: []string{"valid", "foo", "bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Amount: 1,
|
Amount: 1,
|
||||||
|
|
@ -517,12 +518,23 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale-up to 5 replicas on second check_run create webhook event
|
// Scale-up to 5 replicas on second check_run create webhook event
|
||||||
|
replicasAfterSecondWebhook := 5
|
||||||
{
|
{
|
||||||
env.SendOrgCheckRunEvent("test", "valid", "pending", "created")
|
env.SendOrgCheckRunEvent("test", "valid", "pending", "created")
|
||||||
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 5, "runners after second webhook event")
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, replicasAfterSecondWebhook, "runners after second webhook event")
|
||||||
env.ExpectRegisteredNumberCountEventuallyEquals(5, "count of fake list runners")
|
env.ExpectRegisteredNumberCountEventuallyEquals(replicasAfterSecondWebhook, "count of fake list runners")
|
||||||
env.SyncRunnerRegistrations()
|
env.SyncRunnerRegistrations()
|
||||||
ExpectRunnerCountEventuallyEquals(ctx, ns.Name, 5)
|
ExpectRunnerCountEventuallyEquals(ctx, ns.Name, replicasAfterSecondWebhook)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not scale-up on third check_run create webhook event
|
||||||
|
// example repo is not in specified in actionsv1alpha1.CheckRunSpec.Repositories
|
||||||
|
{
|
||||||
|
env.SendOrgCheckRunEvent("test", "example", "pending", "created")
|
||||||
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, replicasAfterSecondWebhook, "runners after third webhook event")
|
||||||
|
env.ExpectRegisteredNumberCountEventuallyEquals(replicasAfterSecondWebhook, "count of fake list runners")
|
||||||
|
env.SyncRunnerRegistrations()
|
||||||
|
ExpectRunnerCountEventuallyEquals(ctx, ns.Name, replicasAfterSecondWebhook)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue