Attempt to use the scalset API and caching

On github, attempt to use the scaleset API to list all runners without
pagination. This will avoid missing runners and accidentally removing them.

Fall back to paginated API if we can't use the scaleset API.

Add ability to retrieve all instances from cache, for an entity.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2025-08-24 22:36:44 +00:00
parent 5c703f310b
commit d05df36868
8 changed files with 333 additions and 209 deletions

View file

@ -422,12 +422,19 @@ func (g *githubClient) getEnterpriseRunnerGroupIDByName(ctx context.Context, ent
func (g *githubClient) GetEntityRunnerGroupIDByName(ctx context.Context, runnerGroupName string) (int64, error) {
var rgID int64 = 1
if g.entity.EntityType == params.ForgeEntityTypeRepository {
// This is a repository. Runner groups are supported at the org and
// enterprise levels. Return the default runner group id, early.
return rgID, nil
}
var ok bool
var err error
// attempt to get the runner group ID from cache. Cache will invalidate after 1 hour.
if runnerGroupName != "" && !strings.EqualFold(runnerGroupName, "default") {
rgID, ok = cache.GetEntityRunnerGroup(g.entity.ID, runnerGroupName)
if !ok {
if !ok || rgID == 0 {
switch g.entity.EntityType {
case params.ForgeEntityTypeOrganization:
rgID, err = g.getOrganizationRunnerGroupIDByName(ctx, g.entity, runnerGroupName)
@ -450,7 +457,7 @@ func (g *githubClient) GetEntityJITConfig(ctx context.Context, instance string,
if err != nil {
return nil, nil, fmt.Errorf("failed to get runner group: %w", err)
}
slog.DebugContext(ctx, "using runner group", "group_name", pool.GitHubRunnerGroup, "runner_group_id", rgID)
req := github.GenerateJITConfigRequest{
Name: instance,
RunnerGroupID: rgID,