MCPcopy Create free account
hub / github.com/cloudbase/garm / AddRunner

Method AddRunner

runner/pool/pool.go:936–997  ·  view source on GitHub ↗
(ctx context.Context, poolID string, aditionalLabels []string)

Source from the content-addressed store, hash-verified

934}
935
936func (r *basePoolManager) AddRunner(ctx context.Context, poolID string, aditionalLabels []string) (err error) {
937 pool, err := r.store.GetEntityPool(r.ctx, r.entity, poolID)
938 if err != nil {
939 return fmt.Errorf("error fetching pool: %w", err)
940 }
941
942 provider, ok := r.providers[pool.ProviderName]
943 if !ok {
944 return fmt.Errorf("unknown provider %s for pool %s", pool.ProviderName, pool.ID)
945 }
946
947 name := strings.ToLower(fmt.Sprintf("%s-%s", pool.GetRunnerPrefix(), util.NewID()))
948 labels := r.getLabelsForInstance(pool)
949
950 jitConfig := make(map[string]string)
951 var runner *github.Runner
952
953 if !provider.DisableJITConfig() && r.entity.Credentials.ForgeType != params.GiteaEndpointType {
954 jitConfig, runner, err = r.ghcli.GetEntityJITConfig(ctx, name, pool, labels)
955 if err != nil {
956 return fmt.Errorf("failed to generate JIT config: %w", err)
957 }
958 }
959
960 defer func() {
961 if err != nil {
962 if runner != nil {
963 runnerCleanupErr := r.ghcli.RemoveEntityRunner(r.ctx, runner.GetID())
964 if err != nil {
965 slog.With(slog.Any("error", runnerCleanupErr)).ErrorContext(
966 ctx, "failed to remove runner",
967 "gh_runner_id", runner.GetID())
968 }
969 }
970 }
971 }()
972
973 createParams := params.CreateInstanceParams{
974 Name: name,
975 Status: commonParams.InstancePendingCreate,
976 RunnerStatus: params.RunnerPending,
977 OSArch: pool.OSArch,
978 OSType: pool.OSType,
979 CallbackURL: r.controllerInfo.CallbackURL,
980 MetadataURL: r.controllerInfo.MetadataURL,
981 CreateAttempt: 1,
982 GitHubRunnerGroup: pool.GitHubRunnerGroup,
983 AditionalLabels: aditionalLabels,
984 JitConfiguration: jitConfig,
985 Generation: pool.Generation,
986 }
987
988 if runner != nil {
989 createParams.AgentID = runner.GetID()
990 }
991
992 if _, err := r.store.CreateInstance(r.ctx, poolID, createParams); err != nil {
993 return fmt.Errorf("error creating instance: %w", err)

Callers 2

addRunnerToPoolMethod · 0.95

Calls 8

getLabelsForInstanceMethod · 0.95
GetRunnerPrefixMethod · 0.80
GetEntityPoolMethod · 0.65
DisableJITConfigMethod · 0.65
GetEntityJITConfigMethod · 0.65
RemoveEntityRunnerMethod · 0.65
GetIDMethod · 0.65
CreateInstanceMethod · 0.65

Tested by

no test coverage detected