From 39f1be551287e0eb34f0c59bea94c5398198b049 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Mon, 25 Mar 2024 18:51:34 +0000 Subject: [PATCH] Fix JIT config with empty runner group name When no runner group is set, do not attempt to resolve the runner group. Looking for an empty runner group will just return a not found error, which will make GARM fall back to registration token. This change fixes that. Signed-off-by: Gabriel Adrian Samfira --- runner/pool/pool.go | 2 +- util/util.go | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/runner/pool/pool.go b/runner/pool/pool.go index a66bacf8..3fe1eb3e 100644 --- a/runner/pool/pool.go +++ b/runner/pool/pool.go @@ -96,7 +96,7 @@ type urls struct { } func NewEntityPoolManager(ctx context.Context, entity params.GithubEntity, cfgInternal params.Internal, providers map[string]common.Provider, store dbCommon.Store) (common.PoolManager, error) { - ctx = garmUtil.WithContext(ctx, slog.Any("pool_mgr", entity), slog.Any("pool_type", params.GithubEntityTypeRepository)) + ctx = garmUtil.WithContext(ctx, slog.Any("pool_mgr", entity.String()), slog.Any("pool_type", params.GithubEntityTypeRepository)) ghc, err := garmUtil.GithubClient(ctx, entity, cfgInternal.GithubCredentialsDetails) if err != nil { return nil, errors.Wrap(err, "getting github client") diff --git a/util/util.go b/util/util.go index 27d674ef..a75be33f 100644 --- a/util/util.go +++ b/util/util.go @@ -320,7 +320,7 @@ func (g *githubClient) getOrganizationRunnerGroupIDByName(ctx context.Context, e } opts.Page = ghResp.NextPage } - return 0, runnerErrors.NewNotFoundError("runner group not found") + return 0, runnerErrors.NewNotFoundError("runner group %s not found", rgName) } func (g *githubClient) getEnterpriseRunnerGroupIDByName(ctx context.Context, entity params.GithubEntity, rgName string) (int64, error) { @@ -360,19 +360,21 @@ func (g *githubClient) getEnterpriseRunnerGroupIDByName(ctx context.Context, ent } func (g *githubClient) GetEntityJITConfig(ctx context.Context, instance string, pool params.Pool, labels []string) (jitConfigMap map[string]string, runner *github.Runner, err error) { - var rgID int64 + // If no runner group is set, use the default runner group ID. This is also the default for + // repository level runners. + var rgID int64 = 1 - switch g.entity.EntityType { - case params.GithubEntityTypeRepository: - rgID = 1 - case params.GithubEntityTypeOrganization: - rgID, err = g.getOrganizationRunnerGroupIDByName(ctx, g.entity, pool.GitHubRunnerGroup) - case params.GithubEntityTypeEnterprise: - rgID, err = g.getEnterpriseRunnerGroupIDByName(ctx, g.entity, pool.GitHubRunnerGroup) - } + if pool.GitHubRunnerGroup != "" { + switch g.entity.EntityType { + case params.GithubEntityTypeOrganization: + rgID, err = g.getOrganizationRunnerGroupIDByName(ctx, g.entity, pool.GitHubRunnerGroup) + case params.GithubEntityTypeEnterprise: + rgID, err = g.getEnterpriseRunnerGroupIDByName(ctx, g.entity, pool.GitHubRunnerGroup) + } - if err != nil { - return nil, nil, fmt.Errorf("getting runner group ID: %w", err) + if err != nil { + return nil, nil, fmt.Errorf("getting runner group ID: %w", err) + } } req := github.GenerateJITConfigRequest{