(instance params.Instance)
| 1042 | } |
| 1043 | |
| 1044 | func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error { |
| 1045 | pool, err := r.store.GetEntityPool(r.ctx, r.entity, instance.PoolID) |
| 1046 | if err != nil { |
| 1047 | return fmt.Errorf("error fetching pool: %w", err) |
| 1048 | } |
| 1049 | |
| 1050 | provider, ok := r.providers[pool.ProviderName] |
| 1051 | if !ok { |
| 1052 | return fmt.Errorf("unknown provider %s for pool %s", pool.ProviderName, pool.ID) |
| 1053 | } |
| 1054 | |
| 1055 | jwtValidity := pool.RunnerTimeout() |
| 1056 | jwtToken, err := r.instanceTokenGetter.NewInstanceJWTToken(instance, r.entity, jwtValidity) |
| 1057 | if err != nil { |
| 1058 | return fmt.Errorf("error fetching instance jwt token: %w", err) |
| 1059 | } |
| 1060 | |
| 1061 | if pool.TemplateID == 0 { |
| 1062 | cloudConfigSpecs, err := garmUtil.GetCloudConfigSpecFromExtraSpecs(pool.ExtraSpecs) |
| 1063 | if err != nil { |
| 1064 | return fmt.Errorf("pool has no template set and extra specs are invalid: %w", err) |
| 1065 | } |
| 1066 | if len(cloudConfigSpecs.RunnerInstallTemplate) == 0 { |
| 1067 | return fmt.Errorf("pool has no template set and extra specs has no runner_install_template set") |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | caBundles, err := garmX509.CombineAndDeduplicateBundles(r.entity.Credentials.CABundle, r.controllerInfo.CACertBundle) |
| 1072 | if err != nil { |
| 1073 | return fmt.Errorf("failed to get CA cert bundle: %w", err) |
| 1074 | } |
| 1075 | |
| 1076 | // If no runner_install_template override is set by the user, we set our own. |
| 1077 | hasJITConfig := len(instance.JitConfiguration) > 0 |
| 1078 | bootstrapArgs := commonParams.BootstrapInstance{ |
| 1079 | Name: instance.Name, |
| 1080 | Tools: r.tools, |
| 1081 | RepoURL: r.entity.ForgeURL(), |
| 1082 | MetadataURL: instance.MetadataURL, |
| 1083 | CallbackURL: instance.CallbackURL, |
| 1084 | InstanceToken: jwtToken, |
| 1085 | OSArch: pool.OSArch, |
| 1086 | OSType: pool.OSType, |
| 1087 | Flavor: pool.Flavor, |
| 1088 | Image: pool.Image, |
| 1089 | ExtraSpecs: pool.ExtraSpecs, |
| 1090 | PoolID: instance.PoolID, |
| 1091 | CACertBundle: caBundles, |
| 1092 | GitHubRunnerGroup: instance.GitHubRunnerGroup, |
| 1093 | JitConfigEnabled: hasJITConfig, |
| 1094 | } |
| 1095 | // We use the template management system unless: |
| 1096 | // * there is no template associated with the pool/scale set |
| 1097 | // * user explicitly overwrites the install template via extra specs |
| 1098 | bootstrapArgs = garmUtil.MaybeAddWrapperToExtraSpecs(r.ctx, bootstrapArgs) |
| 1099 | |
| 1100 | if !hasJITConfig { |
| 1101 | // We still need the labels here for situations where we don't have a JIT config generated. |
no test coverage detected