(ctx context.Context, entityType params.ForgeEntityType, entityID string, param params.CreateScaleSetParams)
| 207 | } |
| 208 | |
| 209 | func (r *Runner) CreateEntityScaleSet(ctx context.Context, entityType params.ForgeEntityType, entityID string, param params.CreateScaleSetParams) (scaleSetRet params.ScaleSet, err error) { |
| 210 | if !auth.IsAdmin(ctx) { |
| 211 | return params.ScaleSet{}, runnerErrors.ErrUnauthorized |
| 212 | } |
| 213 | |
| 214 | if param.RunnerBootstrapTimeout == 0 { |
| 215 | param.RunnerBootstrapTimeout = appdefaults.DefaultRunnerBootstrapTimeout |
| 216 | } |
| 217 | |
| 218 | if param.GitHubRunnerGroup == "" { |
| 219 | param.GitHubRunnerGroup = "Default" |
| 220 | } |
| 221 | |
| 222 | entity, err := r.store.GetForgeEntity(ctx, entityType, entityID) |
| 223 | if err != nil { |
| 224 | return params.ScaleSet{}, fmt.Errorf("error getting entity: %w", err) |
| 225 | } |
| 226 | |
| 227 | if entity.Credentials.ForgeType != params.GithubEndpointType { |
| 228 | return params.ScaleSet{}, runnerErrors.NewBadRequestError("scale sets are only supported for github entities") |
| 229 | } |
| 230 | |
| 231 | template, err := r.findTemplate(ctx, entity, param.OSType, param.TemplateID) |
| 232 | if err != nil { |
| 233 | return params.ScaleSet{}, fmt.Errorf("failed to find suitable template: %w", err) |
| 234 | } |
| 235 | |
| 236 | param.TemplateID = &template.ID |
| 237 | |
| 238 | ghCli, err := github.Client(ctx, entity) |
| 239 | if err != nil { |
| 240 | return params.ScaleSet{}, fmt.Errorf("error creating github client: %w", err) |
| 241 | } |
| 242 | |
| 243 | scalesetCli, err := scalesets.NewClient(ghCli) |
| 244 | if err != nil { |
| 245 | return params.ScaleSet{}, fmt.Errorf("error getting scaleset client: %w", err) |
| 246 | } |
| 247 | |
| 248 | runnerGroupID, err := ghCli.GetEntityRunnerGroupIDByName(ctx, param.GitHubRunnerGroup) |
| 249 | if err != nil { |
| 250 | return params.ScaleSet{}, fmt.Errorf("failed to get github runner group for entity %s: %w", entity.ID, err) |
| 251 | } |
| 252 | |
| 253 | createParam := ¶ms.RunnerScaleSet{ |
| 254 | Name: param.Name, |
| 255 | RunnerGroupID: runnerGroupID, |
| 256 | Labels: param.GitHubLabels(), |
| 257 | RunnerSetting: params.RunnerSetting{ |
| 258 | Ephemeral: true, |
| 259 | DisableUpdate: param.DisableUpdate, |
| 260 | }, |
| 261 | Enabled: ¶m.Enabled, |
| 262 | } |
| 263 | |
| 264 | runnerScaleSet, err := scalesetCli.CreateRunnerScaleSet(ctx, createParam) |
| 265 | if err != nil { |
| 266 | return params.ScaleSet{}, fmt.Errorf("error creating runner scale set: %w", err) |
nothing calls this directly
no test coverage detected