Option to consider runner group visibility on scale based on webhook (#1062)
This will work on GHES but GitHub Enterprise Cloud due to excessive GitHub API calls required. More work is needed, like adding a cache layer to the GitHub client, to make it usable on GitHub Enterprise Cloud. Fixes additional cases from https://github.com/actions-runner-controller/actions-runner-controller/pull/1012 If GitHub auth is provided in the webhooks controller then runner groups with custom visibility are supported. Otherwise, all runner groups will be assumed to be visible to all repositories `getScaleUpTargetWithFunction()` will check if there is an HRA available with the following flow: 1. Search for **repository** HRAs - if so it ends here 2. Get available HRAs in k8s 3. Compute visible runner groups a. If GitHub auth is provided - get all the runner groups that are visible to the repository of the incoming webhook using GitHub API calls. b. If GitHub auth is not provided - assume all runner groups are visible to all repositories 4. Search for **default organization** runners (a.k.a runners from organization's visible default runner group) with matching labels 5. Search for **default enterprise** runners (a.k.a runners from enterprise's visible default runner group) with matching labels 6. Search for **custom organization runner groups** with matching labels 7. Search for **custom enterprise runner groups** with matching labels Co-authored-by: Yusuke Kuoka <[email protected]>
This commit is contained in:
co-authored by
Yusuke Kuoka
parent
b509eb4388
commit
d0d316252e
@@ -0,0 +1,94 @@
|
||||
package simulator
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestVisibleRunnerGroupsInsert(t *testing.T) {
|
||||
g := NewVisibleRunnerGroups()
|
||||
|
||||
orgDefault := NewRunnerGroupFromProperties("", "myorg1", "")
|
||||
orgCustom := NewRunnerGroupFromProperties("", "myorg1", "myorg1group1")
|
||||
enterpriseDefault := NewRunnerGroupFromProperties("myenterprise1", "", "")
|
||||
|
||||
g.insert(orgCustom, 0)
|
||||
g.insert(orgDefault, 0)
|
||||
g.insert(enterpriseDefault, 1)
|
||||
|
||||
var got []RunnerGroup
|
||||
|
||||
err := g.Traverse(func(rg RunnerGroup) (bool, error) {
|
||||
got = append(got, rg)
|
||||
return false, nil
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []RunnerGroup{orgDefault, enterpriseDefault, orgCustom}, got, "Unexpected result")
|
||||
}
|
||||
|
||||
func TestVisibleRunnerGroups(t *testing.T) {
|
||||
v := NewVisibleRunnerGroups()
|
||||
|
||||
requireGroups := func(t *testing.T, included, notIncluded []RunnerGroup) {
|
||||
t.Helper()
|
||||
|
||||
for _, rg := range included {
|
||||
if !v.Includes(rg) {
|
||||
t.Errorf("%v must be included", rg)
|
||||
}
|
||||
}
|
||||
|
||||
for _, rg := range notIncluded {
|
||||
if v.Includes(rg) {
|
||||
t.Errorf("%v must not be included", rg)
|
||||
}
|
||||
}
|
||||
|
||||
var got []RunnerGroup
|
||||
|
||||
err := v.Traverse(func(rg RunnerGroup) (bool, error) {
|
||||
got = append(got, rg)
|
||||
|
||||
return false, nil
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, included, got)
|
||||
}
|
||||
|
||||
orgDefault := NewRunnerGroupFromProperties("", "myorg1", "")
|
||||
orgCustom := NewRunnerGroupFromProperties("", "myorg1", "myorg1group1")
|
||||
enterpriseDefault := NewRunnerGroupFromProperties("myenterprise1", "", "")
|
||||
enterpriseCustom := NewRunnerGroupFromProperties("myenterprise1", "", "myenterprise1group1")
|
||||
|
||||
requireGroups(t, nil, []RunnerGroup{orgDefault, enterpriseDefault, orgCustom, enterpriseCustom})
|
||||
|
||||
v.Add(orgCustom)
|
||||
|
||||
requireGroups(t, []RunnerGroup{orgCustom}, []RunnerGroup{orgDefault, enterpriseDefault, enterpriseCustom})
|
||||
|
||||
v.Add(orgDefault)
|
||||
|
||||
requireGroups(t, []RunnerGroup{orgDefault, orgCustom}, []RunnerGroup{enterpriseDefault, enterpriseCustom})
|
||||
|
||||
v.Add(enterpriseCustom)
|
||||
|
||||
requireGroups(t, []RunnerGroup{orgDefault, orgCustom, enterpriseCustom}, []RunnerGroup{enterpriseDefault})
|
||||
|
||||
v.Add(enterpriseDefault)
|
||||
|
||||
requireGroups(t, []RunnerGroup{orgDefault, enterpriseDefault, orgCustom, enterpriseCustom}, nil)
|
||||
|
||||
var first []RunnerGroup
|
||||
|
||||
err := v.Traverse(func(rg RunnerGroup) (bool, error) {
|
||||
first = append(first, rg)
|
||||
|
||||
return true, nil
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []RunnerGroup{orgDefault}, first)
|
||||
}
|
||||
Reference in New Issue
Block a user