Rename GitHub specific types

This change renames a lot of variables, types and functions to be more
generic. The goal is to allow GARM to add more forges in the future.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2025-05-12 21:47:13 +00:00
parent 4890eb4732
commit 40e6581a75
72 changed files with 896 additions and 700 deletions

View file

@ -118,18 +118,18 @@ func (_m *GithubClient) DeleteEntityHook(ctx context.Context, id int64) (*github
}
// GetEntity provides a mock function with no fields
func (_m *GithubClient) GetEntity() params.GithubEntity {
func (_m *GithubClient) GetEntity() params.ForgeEntity {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for GetEntity")
}
var r0 params.GithubEntity
if rf, ok := ret.Get(0).(func() params.GithubEntity); ok {
var r0 params.ForgeEntity
if rf, ok := ret.Get(0).(func() params.ForgeEntity); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(params.GithubEntity)
r0 = ret.Get(0).(params.ForgeEntity)
}
return r0

View file

@ -118,18 +118,18 @@ func (_m *GithubEntityOperations) DeleteEntityHook(ctx context.Context, id int64
}
// GetEntity provides a mock function with no fields
func (_m *GithubEntityOperations) GetEntity() params.GithubEntity {
func (_m *GithubEntityOperations) GetEntity() params.ForgeEntity {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for GetEntity")
}
var r0 params.GithubEntity
if rf, ok := ret.Get(0).(func() params.GithubEntity); ok {
var r0 params.ForgeEntity
if rf, ok := ret.Get(0).(func() params.ForgeEntity); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(params.GithubEntity)
r0 = ret.Get(0).(params.ForgeEntity)
}
return r0

View file

@ -23,7 +23,7 @@ type GithubEntityOperations interface {
GetEntityJITConfig(ctx context.Context, instance string, pool params.Pool, labels []string) (jitConfigMap map[string]string, runner *github.Runner, err error)
// GetEntity returns the GitHub entity for which the github client was instanciated.
GetEntity() params.GithubEntity
GetEntity() params.ForgeEntity
// GithubBaseURL returns the base URL for the github or GHES API.
GithubBaseURL() *url.URL
}

View file

@ -206,9 +206,9 @@ func (r *Runner) CreateEnterprisePool(ctx context.Context, enterpriseID string,
param.RunnerBootstrapTimeout = appdefaults.DefaultRunnerBootstrapTimeout
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
pool, err := r.store.CreateEntityPool(ctx, entity, createPoolParams)
@ -223,9 +223,9 @@ func (r *Runner) GetEnterprisePoolByID(ctx context.Context, enterpriseID, poolID
if !auth.IsAdmin(ctx) {
return params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
pool, err := r.store.GetEntityPool(ctx, entity, poolID)
if err != nil {
@ -239,9 +239,9 @@ func (r *Runner) DeleteEnterprisePool(ctx context.Context, enterpriseID, poolID
return runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
pool, err := r.store.GetEntityPool(ctx, entity, poolID)
@ -270,9 +270,9 @@ func (r *Runner) ListEnterprisePools(ctx context.Context, enterpriseID string) (
return []params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
pools, err := r.store.ListEntityPools(ctx, entity)
if err != nil {
@ -286,9 +286,9 @@ func (r *Runner) UpdateEnterprisePool(ctx context.Context, enterpriseID, poolID
return params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
pool, err := r.store.GetEntityPool(ctx, entity, poolID)
if err != nil {
@ -320,9 +320,9 @@ func (r *Runner) ListEnterpriseInstances(ctx context.Context, enterpriseID strin
if !auth.IsAdmin(ctx) {
return nil, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
instances, err := r.store.ListEntityInstances(ctx, entity)
if err != nil {

View file

@ -58,7 +58,7 @@ type EnterpriseTestSuite struct {
testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint
forgeEndpoint params.ForgeEndpoint
}
func (s *EnterpriseTestSuite) SetupTest() {
@ -70,9 +70,9 @@ func (s *EnterpriseTestSuite) SetupTest() {
}
adminCtx := garmTesting.ImpersonateAdminContext(context.Background(), db, s.T())
s.githubEndpoint = garmTesting.CreateDefaultGithubEndpoint(adminCtx, db, s.T())
s.testCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), s.githubEndpoint)
s.secondaryTestCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "secondary-creds", db, s.T(), s.githubEndpoint)
s.forgeEndpoint = garmTesting.CreateDefaultGithubEndpoint(adminCtx, db, s.T())
s.testCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), s.forgeEndpoint)
s.secondaryTestCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "secondary-creds", db, s.T(), s.forgeEndpoint)
// create some organization objects in the database, for testing purposes
enterprises := map[string]params.Enterprise{}
@ -270,9 +270,9 @@ func (s *EnterpriseTestSuite) TestDeleteEnterpriseErrUnauthorized() {
}
func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolDefinedFailed() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -377,9 +377,9 @@ func (s *EnterpriseTestSuite) TestCreateEnterprisePoolFetchPoolParamsFailed() {
}
func (s *EnterpriseTestSuite) TestGetEnterprisePoolByID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
enterprisePool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -399,9 +399,9 @@ func (s *EnterpriseTestSuite) TestGetEnterprisePoolByIDErrUnauthorized() {
}
func (s *EnterpriseTestSuite) TestDeleteEnterprisePool() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -423,9 +423,9 @@ func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolErrUnauthorized() {
}
func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolRunnersFailed() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -442,9 +442,9 @@ func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolRunnersFailed() {
}
func (s *EnterpriseTestSuite) TestListEnterprisePools() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
enterprisePools := []params.Pool{}
for i := 1; i <= 2; i++ {
@ -469,9 +469,9 @@ func (s *EnterpriseTestSuite) TestListOrgPoolsErrUnauthorized() {
}
func (s *EnterpriseTestSuite) TestUpdateEnterprisePool() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
enterprisePool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -492,9 +492,9 @@ func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolErrUnauthorized() {
}
func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolMinIdleGreaterThanMax() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -511,9 +511,9 @@ func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolMinIdleGreaterThanMax() {
}
func (s *EnterpriseTestSuite) TestListEnterpriseInstances() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {

View file

@ -10,30 +10,30 @@ import (
"github.com/cloudbase/garm/params"
)
func (r *Runner) CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.GithubEndpoint, error) {
func (r *Runner) CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.ForgeEndpoint, error) {
if !auth.IsAdmin(ctx) {
return params.GithubEndpoint{}, runnerErrors.ErrUnauthorized
return params.ForgeEndpoint{}, runnerErrors.ErrUnauthorized
}
if err := param.Validate(); err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "failed to validate github endpoint params")
return params.ForgeEndpoint{}, errors.Wrap(err, "failed to validate github endpoint params")
}
ep, err := r.store.CreateGithubEndpoint(ctx, param)
if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "failed to create github endpoint")
return params.ForgeEndpoint{}, errors.Wrap(err, "failed to create github endpoint")
}
return ep, nil
}
func (r *Runner) GetGithubEndpoint(ctx context.Context, name string) (params.GithubEndpoint, error) {
func (r *Runner) GetGithubEndpoint(ctx context.Context, name string) (params.ForgeEndpoint, error) {
if !auth.IsAdmin(ctx) {
return params.GithubEndpoint{}, runnerErrors.ErrUnauthorized
return params.ForgeEndpoint{}, runnerErrors.ErrUnauthorized
}
endpoint, err := r.store.GetGithubEndpoint(ctx, name)
if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "failed to get github endpoint")
return params.ForgeEndpoint{}, errors.Wrap(err, "failed to get github endpoint")
}
return endpoint, nil
@ -52,23 +52,23 @@ func (r *Runner) DeleteGithubEndpoint(ctx context.Context, name string) error {
return nil
}
func (r *Runner) UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.GithubEndpoint, error) {
func (r *Runner) UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.ForgeEndpoint, error) {
if !auth.IsAdmin(ctx) {
return params.GithubEndpoint{}, runnerErrors.ErrUnauthorized
return params.ForgeEndpoint{}, runnerErrors.ErrUnauthorized
}
if err := param.Validate(); err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "failed to validate github endpoint params")
return params.ForgeEndpoint{}, errors.Wrap(err, "failed to validate github endpoint params")
}
newEp, err := r.store.UpdateGithubEndpoint(ctx, name, param)
if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "failed to update github endpoint")
return params.ForgeEndpoint{}, errors.Wrap(err, "failed to update github endpoint")
}
return newEp, nil
}
func (r *Runner) ListGithubEndpoints(ctx context.Context) ([]params.GithubEndpoint, error) {
func (r *Runner) ListGithubEndpoints(ctx context.Context) ([]params.ForgeEndpoint, error) {
if !auth.IsAdmin(ctx) {
return nil, runnerErrors.ErrUnauthorized
}

View file

@ -56,7 +56,7 @@ func (r *Runner) GetRunnerServiceName(ctx context.Context) (string, error) {
ctx, "failed to get instance params")
return "", runnerErrors.ErrUnauthorized
}
var entity params.GithubEntity
var entity params.ForgeEntity
switch {
case instance.PoolID != "":
@ -96,11 +96,11 @@ func (r *Runner) GetRunnerServiceName(ctx context.Context) (string, error) {
tpl := "actions.runner.%s.%s"
var serviceName string
switch entity.EntityType {
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
serviceName = fmt.Sprintf(tpl, entity.Owner, instance.Name)
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
serviceName = fmt.Sprintf(tpl, entity.Owner, instance.Name)
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
serviceName = fmt.Sprintf(tpl, fmt.Sprintf("%s-%s", entity.Owner, entity.Name), instance.Name)
}
return serviceName, nil

View file

@ -235,9 +235,9 @@ func (r *Runner) CreateOrgPool(ctx context.Context, orgID string, param params.C
param.RunnerBootstrapTimeout = appdefaults.DefaultRunnerBootstrapTimeout
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
pool, err := r.store.CreateEntityPool(ctx, entity, createPoolParams)
@ -253,9 +253,9 @@ func (r *Runner) GetOrgPoolByID(ctx context.Context, orgID, poolID string) (para
return params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
pool, err := r.store.GetEntityPool(ctx, entity, poolID)
@ -271,9 +271,9 @@ func (r *Runner) DeleteOrgPool(ctx context.Context, orgID, poolID string) error
return runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
pool, err := r.store.GetEntityPool(ctx, entity, poolID)
@ -304,9 +304,9 @@ func (r *Runner) ListOrgPools(ctx context.Context, orgID string) ([]params.Pool,
if !auth.IsAdmin(ctx) {
return []params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
pools, err := r.store.ListEntityPools(ctx, entity)
if err != nil {
@ -320,9 +320,9 @@ func (r *Runner) UpdateOrgPool(ctx context.Context, orgID, poolID string, param
return params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
pool, err := r.store.GetEntityPool(ctx, entity, poolID)
@ -356,9 +356,9 @@ func (r *Runner) ListOrgInstances(ctx context.Context, orgID string) ([]params.I
return nil, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
instances, err := r.store.ListEntityInstances(ctx, entity)

View file

@ -58,7 +58,7 @@ type OrgTestSuite struct {
testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint
githubEndpoint params.ForgeEndpoint
}
func (s *OrgTestSuite) SetupTest() {
@ -284,9 +284,9 @@ func (s *OrgTestSuite) TestDeleteOrganizationErrUnauthorized() {
}
func (s *OrgTestSuite) TestDeleteOrganizationPoolDefinedFailed() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -402,9 +402,9 @@ func (s *OrgTestSuite) TestCreateOrgPoolFetchPoolParamsFailed() {
}
func (s *OrgTestSuite) TestGetOrgPoolByID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
orgPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -424,9 +424,9 @@ func (s *OrgTestSuite) TestGetOrgPoolByIDErrUnauthorized() {
}
func (s *OrgTestSuite) TestDeleteOrgPool() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -448,9 +448,9 @@ func (s *OrgTestSuite) TestDeleteOrgPoolErrUnauthorized() {
}
func (s *OrgTestSuite) TestDeleteOrgPoolRunnersFailed() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -467,9 +467,9 @@ func (s *OrgTestSuite) TestDeleteOrgPoolRunnersFailed() {
}
func (s *OrgTestSuite) TestListOrgPools() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
orgPools := []params.Pool{}
for i := 1; i <= 2; i++ {
@ -494,9 +494,9 @@ func (s *OrgTestSuite) TestListOrgPoolsErrUnauthorized() {
}
func (s *OrgTestSuite) TestUpdateOrgPool() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
orgPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -517,9 +517,9 @@ func (s *OrgTestSuite) TestUpdateOrgPoolErrUnauthorized() {
}
func (s *OrgTestSuite) TestUpdateOrgPoolMinIdleGreaterThanMax() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -536,9 +536,9 @@ func (s *OrgTestSuite) TestUpdateOrgPoolMinIdleGreaterThanMax() {
}
func (s *OrgTestSuite) TestListOrgInstances() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {

View file

@ -67,7 +67,7 @@ const (
maxCreateAttempts = 5
)
func NewEntityPoolManager(ctx context.Context, entity params.GithubEntity, instanceTokenGetter auth.InstanceTokenGetter, providers map[string]common.Provider, store dbCommon.Store) (common.PoolManager, error) {
func NewEntityPoolManager(ctx context.Context, entity params.ForgeEntity, instanceTokenGetter auth.InstanceTokenGetter, providers map[string]common.Provider, store dbCommon.Store) (common.PoolManager, error) {
ctx = garmUtil.WithSlogContext(ctx, slog.Any("pool_mgr", entity.String()), slog.Any("pool_type", entity.EntityType))
ghc, err := ghClient.Client(ctx, entity)
if err != nil {
@ -83,7 +83,7 @@ func NewEntityPoolManager(ctx context.Context, entity params.GithubEntity, insta
return nil, errors.Wrap(err, "getting controller info")
}
consumerID := fmt.Sprintf("pool-manager-%s-%s", entity.String(), entity.Credentials.Endpoint.Name)
consumerID := fmt.Sprintf("pool-manager-%s-%s", entity.String(), entity.Credentials.Endpoint().Name)
slog.InfoContext(ctx, "registering consumer", "consumer_id", consumerID)
consumer, err := watcher.RegisterConsumer(
ctx, consumerID,
@ -120,7 +120,7 @@ func NewEntityPoolManager(ctx context.Context, entity params.GithubEntity, insta
type basePoolManager struct {
ctx context.Context
consumerID string
entity params.GithubEntity
entity params.ForgeEntity
ghcli common.GithubClient
controllerInfo params.ControllerInfo
instanceTokenGetter auth.InstanceTokenGetter
@ -877,7 +877,7 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error
bootstrapArgs := commonParams.BootstrapInstance{
Name: instance.Name,
Tools: r.tools,
RepoURL: r.entity.GithubURL(),
RepoURL: r.entity.ForgeURL(),
MetadataURL: instance.MetadataURL,
CallbackURL: instance.CallbackURL,
InstanceToken: jwtToken,
@ -887,7 +887,7 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error
Image: pool.Image,
ExtraSpecs: pool.ExtraSpecs,
PoolID: instance.PoolID,
CACertBundle: r.entity.Credentials.CABundle,
CACertBundle: r.entity.Credentials.CABundle(),
GitHubRunnerGroup: instance.GitHubRunnerGroup,
JitConfigEnabled: hasJITConfig,
}
@ -981,11 +981,11 @@ func (r *basePoolManager) paramsWorkflowJobToParamsJob(job params.WorkflowJob) (
}
switch r.entity.EntityType {
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
jobParams.EnterpriseID = &asUUID
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
jobParams.RepoID = &asUUID
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
jobParams.OrgID = &asUUID
default:
return jobParams, errors.Errorf("unknown pool type: %s", r.entity.EntityType)
@ -1931,15 +1931,15 @@ func (r *basePoolManager) InstallWebhook(ctx context.Context, param params.Insta
func (r *basePoolManager) ValidateOwner(job params.WorkflowJob) error {
switch r.entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
if !strings.EqualFold(job.Repository.Name, r.entity.Name) || !strings.EqualFold(job.Repository.Owner.Login, r.entity.Owner) {
return runnerErrors.NewBadRequestError("job not meant for this pool manager")
}
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
if !strings.EqualFold(job.Organization.Login, r.entity.Owner) {
return runnerErrors.NewBadRequestError("job not meant for this pool manager")
}
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
if !strings.EqualFold(job.Enterprise.Slug, r.entity.Owner) {
return runnerErrors.NewBadRequestError("job not meant for this pool manager")
}

View file

@ -57,8 +57,8 @@ func (s *stubGithubClient) GetWorkflowJobByID(_ context.Context, _, _ string, _
return nil, nil, s.err
}
func (s *stubGithubClient) GetEntity() params.GithubEntity {
return params.GithubEntity{}
func (s *stubGithubClient) GetEntity() params.ForgeEntity {
return params.ForgeEntity{}
}
func (s *stubGithubClient) GithubBaseURL() *url.URL {

View file

@ -119,7 +119,7 @@ func isManagedRunner(labels []string, controllerID string) bool {
return runnerControllerID == controllerID
}
func composeWatcherFilters(entity params.GithubEntity) dbCommon.PayloadFilterFunc {
func composeWatcherFilters(entity params.ForgeEntity) dbCommon.PayloadFilterFunc {
// We want to watch for changes in either the controller or the
// entity itself.
return watcher.WithAny(
@ -131,6 +131,6 @@ func composeWatcherFilters(entity params.GithubEntity) dbCommon.PayloadFilterFun
// Any operation on the entity we're managing the pool for.
watcher.WithEntityFilter(entity),
// Watch for changes to the github credentials
watcher.WithGithubCredentialsFilter(entity.Credentials),
watcher.WithForgeCredentialsFilter(entity.Credentials),
)
}

View file

@ -14,7 +14,7 @@ import (
// entityGetter is implemented by all github entities (repositories, organizations and enterprises)
type entityGetter interface {
GetEntity() (params.GithubEntity, error)
GetEntity() (params.ForgeEntity, error)
}
func (r *basePoolManager) handleControllerUpdateEvent(controllerInfo params.ControllerInfo) {
@ -38,7 +38,7 @@ func (r *basePoolManager) getClientOrStub() runnerCommon.GithubClient {
return ghc
}
func (r *basePoolManager) handleEntityUpdate(entity params.GithubEntity, operation common.OperationType) {
func (r *basePoolManager) handleEntityUpdate(entity params.ForgeEntity, operation common.OperationType) {
slog.DebugContext(r.ctx, "received entity operation", "entity", entity.ID, "operation", operation)
if r.entity.ID != entity.ID {
slog.WarnContext(r.ctx, "entity ID mismatch; stale event? refusing to update", "entity", entity.ID)
@ -56,7 +56,7 @@ func (r *basePoolManager) handleEntityUpdate(entity params.GithubEntity, operati
return
}
credentialsUpdate := r.entity.Credentials.ID != entity.Credentials.ID
credentialsUpdate := r.entity.Credentials.GetID() != entity.Credentials.GetID()
defer func() {
slog.DebugContext(r.ctx, "deferred tools update", "credentials_update", credentialsUpdate)
if !credentialsUpdate {
@ -85,7 +85,7 @@ func (r *basePoolManager) handleEntityUpdate(entity params.GithubEntity, operati
slog.DebugContext(r.ctx, "lock released", "entity", entity.ID)
}
func (r *basePoolManager) handleCredentialsUpdate(credentials params.GithubCredentials) {
func (r *basePoolManager) handleCredentialsUpdate(credentials params.ForgeCredentials) {
// when we switch credentials on an entity (like from one app to another or from an app
// to a PAT), we may still get events for the previous credentials as the channel is buffered.
// The watcher will watch for changes to the entity itself, which includes events that
@ -97,12 +97,12 @@ func (r *basePoolManager) handleCredentialsUpdate(credentials params.GithubCrede
// test-repo. This function would handle situations where "org_pat" is updated.
// If "test-repo" is updated with new credentials, that event is handled above in
// handleEntityUpdate.
shouldUpdateTools := r.entity.Credentials.ID == credentials.ID
shouldUpdateTools := r.entity.Credentials.GetID() == credentials.GetID()
defer func() {
if !shouldUpdateTools {
return
}
slog.DebugContext(r.ctx, "deferred tools update", "credentials_id", credentials.ID)
slog.DebugContext(r.ctx, "deferred tools update", "credentials_id", credentials.GetID())
if err := r.updateTools(); err != nil {
slog.ErrorContext(r.ctx, "failed to update tools", "error", err)
}
@ -110,12 +110,12 @@ func (r *basePoolManager) handleCredentialsUpdate(credentials params.GithubCrede
r.mux.Lock()
if !shouldUpdateTools {
slog.InfoContext(r.ctx, "credential ID mismatch; stale event?", "credentials_id", credentials.ID)
slog.InfoContext(r.ctx, "credential ID mismatch; stale event?", "credentials_id", credentials.GetID())
r.mux.Unlock()
return
}
slog.DebugContext(r.ctx, "updating credentials", "credentials_id", credentials.ID)
slog.DebugContext(r.ctx, "updating credentials", "credentials_id", credentials.GetID())
r.entity.Credentials = credentials
r.ghcli = r.getClientOrStub()
r.mux.Unlock()
@ -130,7 +130,7 @@ func (r *basePoolManager) handleWatcherEvent(event common.ChangePayload) {
slog.ErrorContext(r.ctx, "failed to cast payload to github credentials")
return
}
r.handleCredentialsUpdate(credentials)
r.handleCredentialsUpdate(credentials.GetForgeCredentials())
case common.ControllerEntityType:
controllerInfo, ok := event.Payload.(params.ControllerInfo)
if !ok {

View file

@ -49,7 +49,7 @@ type PoolTestSuite struct {
adminCtx context.Context
testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint
githubEndpoint params.ForgeEndpoint
}
func (s *PoolTestSuite) SetupTest() {
@ -75,9 +75,9 @@ func (s *PoolTestSuite) SetupTest() {
}
// create some pool objects in the database, for testing purposes
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: org.ID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
orgPools := []params.Pool{}
for i := 1; i <= 3; i++ {

View file

@ -235,9 +235,9 @@ func (r *Runner) CreateRepoPool(ctx context.Context, repoID string, param params
createPoolParams.RunnerBootstrapTimeout = appdefaults.DefaultRunnerBootstrapTimeout
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := r.store.CreateEntityPool(ctx, entity, createPoolParams)
@ -253,9 +253,9 @@ func (r *Runner) GetRepoPoolByID(ctx context.Context, repoID, poolID string) (pa
return params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := r.store.GetEntityPool(ctx, entity, poolID)
@ -271,9 +271,9 @@ func (r *Runner) DeleteRepoPool(ctx context.Context, repoID, poolID string) erro
return runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := r.store.GetEntityPool(ctx, entity, poolID)
if err != nil {
@ -300,9 +300,9 @@ func (r *Runner) ListRepoPools(ctx context.Context, repoID string) ([]params.Poo
if !auth.IsAdmin(ctx) {
return []params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pools, err := r.store.ListEntityPools(ctx, entity)
if err != nil {
@ -328,9 +328,9 @@ func (r *Runner) UpdateRepoPool(ctx context.Context, repoID, poolID string, para
return params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := r.store.GetEntityPool(ctx, entity, poolID)
if err != nil {
@ -362,9 +362,9 @@ func (r *Runner) ListRepoInstances(ctx context.Context, repoID string) ([]params
if !auth.IsAdmin(ctx) {
return nil, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
instances, err := r.store.ListEntityInstances(ctx, entity)
if err != nil {

View file

@ -62,7 +62,7 @@ type RepoTestSuite struct {
testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint
githubEndpoint params.ForgeEndpoint
}
func (s *RepoTestSuite) SetupTest() {
@ -299,9 +299,9 @@ func (s *RepoTestSuite) TestDeleteRepositoryErrUnauthorized() {
}
func (s *RepoTestSuite) TestDeleteRepositoryPoolDefinedFailed() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -419,9 +419,9 @@ func (s *RepoTestSuite) TestCreateRepoPoolFetchPoolParamsFailed() {
}
func (s *RepoTestSuite) TestGetRepoPoolByID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
repoPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -441,9 +441,9 @@ func (s *RepoTestSuite) TestGetRepoPoolByIDErrUnauthorized() {
}
func (s *RepoTestSuite) TestDeleteRepoPool() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -465,9 +465,9 @@ func (s *RepoTestSuite) TestDeleteRepoPoolErrUnauthorized() {
}
func (s *RepoTestSuite) TestDeleteRepoPoolRunnersFailed() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -484,9 +484,9 @@ func (s *RepoTestSuite) TestDeleteRepoPoolRunnersFailed() {
}
func (s *RepoTestSuite) TestListRepoPools() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
repoPools := []params.Pool{}
for i := 1; i <= 2; i++ {
@ -511,9 +511,9 @@ func (s *RepoTestSuite) TestListRepoPoolsErrUnauthorized() {
}
func (s *RepoTestSuite) TestListPoolInstances() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -542,9 +542,9 @@ func (s *RepoTestSuite) TestListPoolInstancesErrUnauthorized() {
}
func (s *RepoTestSuite) TestUpdateRepoPool() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
repoPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -565,9 +565,9 @@ func (s *RepoTestSuite) TestUpdateRepoPoolErrUnauthorized() {
}
func (s *RepoTestSuite) TestUpdateRepoPoolMinIdleGreaterThanMax() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {
@ -584,9 +584,9 @@ func (s *RepoTestSuite) TestUpdateRepoPoolMinIdleGreaterThanMax() {
}
func (s *RepoTestSuite) TestListRepoInstances() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil {

View file

@ -602,10 +602,10 @@ func (r *Runner) validateHookBody(signature, secret string, body []byte) error {
return nil
}
func (r *Runner) findEndpointForJob(job params.WorkflowJob) (params.GithubEndpoint, error) {
func (r *Runner) findEndpointForJob(job params.WorkflowJob) (params.ForgeEndpoint, error) {
uri, err := url.ParseRequestURI(job.WorkflowJob.HTMLURL)
if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "parsing job URL")
return params.ForgeEndpoint{}, errors.Wrap(err, "parsing job URL")
}
baseURI := fmt.Sprintf("%s://%s", uri.Scheme, uri.Host)
@ -616,7 +616,7 @@ func (r *Runner) findEndpointForJob(job params.WorkflowJob) (params.GithubEndpoi
// that much about the performance of this function.
endpoints, err := r.store.ListGithubEndpoints(r.ctx)
if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "fetching github endpoints")
return params.ForgeEndpoint{}, errors.Wrap(err, "fetching github endpoints")
}
for _, ep := range endpoints {
if ep.BaseURL == baseURI {
@ -624,7 +624,7 @@ func (r *Runner) findEndpointForJob(job params.WorkflowJob) (params.GithubEndpoi
}
}
return params.GithubEndpoint{}, runnerErrors.NewNotFoundError("no endpoint found for job")
return params.ForgeEndpoint{}, runnerErrors.NewNotFoundError("no endpoint found for job")
}
func (r *Runner) DispatchWorkflowJob(hookTargetType, signature string, jobData []byte) error {
@ -928,7 +928,7 @@ func (r *Runner) getGHCliFromInstance(ctx context.Context, instance params.Insta
}
// Fetching the entity from the database will populate all fields, including credentials.
entity, err = r.store.GetGithubEntity(ctx, entity.EntityType, entity.ID)
entity, err = r.store.GetForgeEntity(ctx, entity.EntityType, entity.ID)
if err != nil {
return nil, nil, errors.Wrap(err, "fetching entity")
}

View file

@ -80,7 +80,7 @@ func (r *Runner) DeleteScaleSetByID(ctx context.Context, scaleSetID uint) error
return errors.Wrap(err, "getting entity")
}
entity, err := r.store.GetGithubEntity(ctx, paramEntity.EntityType, paramEntity.ID)
entity, err := r.store.GetForgeEntity(ctx, paramEntity.EntityType, paramEntity.ID)
if err != nil {
return errors.Wrap(err, "getting entity")
}
@ -143,7 +143,7 @@ func (r *Runner) UpdateScaleSetByID(ctx context.Context, scaleSetID uint, param
return params.ScaleSet{}, errors.Wrap(err, "getting entity")
}
entity, err := r.store.GetGithubEntity(ctx, paramEntity.EntityType, paramEntity.ID)
entity, err := r.store.GetForgeEntity(ctx, paramEntity.EntityType, paramEntity.ID)
if err != nil {
return params.ScaleSet{}, errors.Wrap(err, "getting entity")
}
@ -198,7 +198,7 @@ func (r *Runner) UpdateScaleSetByID(ctx context.Context, scaleSetID uint, param
return newScaleSet, nil
}
func (r *Runner) CreateEntityScaleSet(ctx context.Context, entityType params.GithubEntityType, entityID string, param params.CreateScaleSetParams) (scaleSetRet params.ScaleSet, err error) {
func (r *Runner) CreateEntityScaleSet(ctx context.Context, entityType params.ForgeEntityType, entityID string, param params.CreateScaleSetParams) (scaleSetRet params.ScaleSet, err error) {
if !auth.IsAdmin(ctx) {
return params.ScaleSet{}, runnerErrors.ErrUnauthorized
}
@ -211,7 +211,7 @@ func (r *Runner) CreateEntityScaleSet(ctx context.Context, entityType params.Git
param.GitHubRunnerGroup = "Default"
}
entity, err := r.store.GetGithubEntity(ctx, entityType, entityID)
entity, err := r.store.GetForgeEntity(ctx, entityType, entityID)
if err != nil {
return params.ScaleSet{}, errors.Wrap(err, "getting entity")
}
@ -287,11 +287,11 @@ func (r *Runner) ListScaleSetInstances(ctx context.Context, scalesetID uint) ([]
return instances, nil
}
func (r *Runner) ListEntityScaleSets(ctx context.Context, entityType params.GithubEntityType, entityID string) ([]params.ScaleSet, error) {
func (r *Runner) ListEntityScaleSets(ctx context.Context, entityType params.ForgeEntityType, entityID string) ([]params.ScaleSet, error) {
if !auth.IsAdmin(ctx) {
return []params.ScaleSet{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: entityID,
EntityType: entityType,
}