diff --git a/database/sql/enterprise_test.go b/database/sql/enterprise_test.go index 4c51d2ac..9e1a86dd 100644 --- a/database/sql/enterprise_test.go +++ b/database/sql/enterprise_test.go @@ -152,7 +152,7 @@ func (s *EnterpriseTestSuite) SetupTest() { Flavor: "test-flavor", OSType: "linux", OSArch: "amd64", - Tags: []string{"self-hosted", "arm64", "linux"}, + Tags: []string{"amd64-linux-runner"}, }, CreateInstanceParams: params.CreateInstanceParams{ Name: "test-instance-name", diff --git a/database/sql/instances_test.go b/database/sql/instances_test.go index 82b5cb46..de37033d 100644 --- a/database/sql/instances_test.go +++ b/database/sql/instances_test.go @@ -97,7 +97,7 @@ func (s *InstancesTestSuite) SetupTest() { Image: "test-image", Flavor: "test-flavor", OSType: "linux", - Tags: []string{"self-hosted", "amd64", "linux"}, + Tags: []string{"amd64", "linux"}, } entity, err := org.GetEntity() s.Require().Nil(err) diff --git a/database/sql/organizations_test.go b/database/sql/organizations_test.go index 049a061e..11be72d0 100644 --- a/database/sql/organizations_test.go +++ b/database/sql/organizations_test.go @@ -153,7 +153,7 @@ func (s *OrgTestSuite) SetupTest() { Flavor: "test-flavor", OSType: "linux", OSArch: "amd64", - Tags: []string{"self-hosted", "arm64", "linux"}, + Tags: []string{"amd64-linux-runner"}, }, CreateInstanceParams: params.CreateInstanceParams{ Name: "test-instance-name", diff --git a/database/sql/pools_test.go b/database/sql/pools_test.go index 97dbdf71..e6cf7f4a 100644 --- a/database/sql/pools_test.go +++ b/database/sql/pools_test.go @@ -88,7 +88,7 @@ func (s *PoolsTestSuite) SetupTest() { Image: fmt.Sprintf("test-image-%d", i), Flavor: "test-flavor", OSType: "linux", - Tags: []string{"self-hosted", "amd64", "linux"}, + Tags: []string{"amd64-linux-runner"}, }, ) if err != nil { diff --git a/database/sql/repositories_test.go b/database/sql/repositories_test.go index a588263b..6eb20a2c 100644 --- a/database/sql/repositories_test.go +++ b/database/sql/repositories_test.go @@ -165,7 +165,7 @@ func (s *RepoTestSuite) SetupTest() { Flavor: "test-flavor", OSType: "windows", OSArch: "amd64", - Tags: []string{"self-hosted", "arm64", "windows"}, + Tags: []string{"arm64-windows-runner"}, }, CreateInstanceParams: params.CreateInstanceParams{ Name: "test-instance", diff --git a/runner/enterprises_test.go b/runner/enterprises_test.go index 501d96a8..22946ae6 100644 --- a/runner/enterprises_test.go +++ b/runner/enterprises_test.go @@ -121,7 +121,7 @@ func (s *EnterpriseTestSuite) SetupTest() { Flavor: "test", OSType: "linux", OSArch: "arm64", - Tags: []string{"self-hosted", "arm64", "linux"}, + Tags: []string{"arm64-linux-runner"}, RunnerBootstrapTimeout: 0, }, CreateInstanceParams: params.CreateInstanceParams{ diff --git a/runner/organizations_test.go b/runner/organizations_test.go index 7954d2e7..4d439b76 100644 --- a/runner/organizations_test.go +++ b/runner/organizations_test.go @@ -122,7 +122,7 @@ func (s *OrgTestSuite) SetupTest() { Flavor: "test", OSType: "linux", OSArch: "arm64", - Tags: []string{"self-hosted", "arm64", "linux"}, + Tags: []string{"arm64-linux-runner"}, RunnerBootstrapTimeout: 0, }, CreateInstanceParams: params.CreateInstanceParams{ diff --git a/runner/pools.go b/runner/pools.go index aab423ff..7daa3fa5 100644 --- a/runner/pools.go +++ b/runner/pools.go @@ -99,12 +99,8 @@ func (r *Runner) UpdatePoolByID(ctx context.Context, poolID string, param params return params.Pool{}, runnerErrors.NewBadRequestError("min_idle_runners cannot be larger than max_runners") } - if param.Tags != nil && len(param.Tags) > 0 { - newTags, err := r.processTags(string(pool.OSArch), pool.OSType, param.Tags) - if err != nil { - return params.Pool{}, errors.Wrap(err, "processing tags") - } - param.Tags = newTags + if len(param.Tags) == 0 { + return params.Pool{}, runnerErrors.NewBadRequestError("tags cannot be empty") } entity, err := pool.GithubEntity() diff --git a/runner/pools_test.go b/runner/pools_test.go index 49ca5a5c..08bcfbb8 100644 --- a/runner/pools_test.go +++ b/runner/pools_test.go @@ -91,7 +91,7 @@ func (s *PoolTestSuite) SetupTest() { Image: fmt.Sprintf("test-image-%d", i), Flavor: "test-flavor", OSType: "linux", - Tags: []string{"self-hosted", "amd64", "linux"}, + Tags: []string{"amd64-linux-runner"}, RunnerBootstrapTimeout: 0, }, ) @@ -113,6 +113,9 @@ func (s *PoolTestSuite) SetupTest() { MinIdleRunners: &minIdleRunners, Image: "test-images-updated", Flavor: "test-flavor-updated", + Tags: []string{ + "amd64-linux-runner", + }, }, CreateInstanceParams: params.CreateInstanceParams{ Name: "test-instance-name", @@ -199,8 +202,14 @@ func (s *PoolTestSuite) TestDeletePoolByIDRunnersFailed() { func (s *PoolTestSuite) TestUpdatePoolByID() { pool, err := s.Runner.UpdatePoolByID(s.Fixtures.AdminContext, s.Fixtures.Pools[0].ID, s.Fixtures.UpdatePoolParams) + var tags []string + for _, tag := range pool.Tags { + tags = append(tags, tag.Name) + } + s.Require().Nil(err) s.Require().Equal(*s.Fixtures.UpdatePoolParams.MaxRunners, pool.MaxRunners) + s.Require().Equal(s.Fixtures.UpdatePoolParams.Tags, tags) s.Require().Equal(*s.Fixtures.UpdatePoolParams.MinIdleRunners, pool.MinIdleRunners) s.Require().Equal(s.Fixtures.UpdatePoolParams.Image, pool.Image) s.Require().Equal(s.Fixtures.UpdatePoolParams.Flavor, pool.Flavor) diff --git a/runner/repositories_test.go b/runner/repositories_test.go index 717e795d..d0a6ab61 100644 --- a/runner/repositories_test.go +++ b/runner/repositories_test.go @@ -121,7 +121,7 @@ func (s *RepoTestSuite) SetupTest() { Flavor: "test", OSType: "linux", OSArch: "arm64", - Tags: []string{"self-hosted", "arm64", "linux"}, + Tags: []string{"arm64-linux-runner"}, RunnerBootstrapTimeout: 0, }, CreateInstanceParams: params.CreateInstanceParams{ @@ -177,7 +177,7 @@ func (s *RepoTestSuite) TestCreateRepository() { s.Require().Equal(params.PoolBalancerTypeRoundRobin, repo.PoolBalancerType) } -func (s *RepoTestSuite) TestCreareRepositoryPoolBalancerTypePack() { +func (s *RepoTestSuite) TestCreateRepositoryPoolBalancerTypePack() { // setup mocks expectations s.Fixtures.PoolMgrMock.On("Start").Return(nil) s.Fixtures.PoolMgrCtrlMock.On("CreateRepoPoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Repository"), s.Fixtures.Providers, s.Fixtures.Store).Return(s.Fixtures.PoolMgrMock, nil) diff --git a/runner/runner.go b/runner/runner.go index 9873695d..6f37c55f 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -786,49 +786,9 @@ func (r *Runner) appendTagsToCreatePoolParams(param params.CreatePoolParams) (pa return params.CreatePoolParams{}, runnerErrors.NewBadRequestError("no such provider %s", param.ProviderName) } - newTags, err := r.processTags(string(param.OSArch), param.OSType, param.Tags) - if err != nil { - return params.CreatePoolParams{}, fmt.Errorf("failed to process tags: %w", err) - } - - param.Tags = newTags - return param, nil } -func (r *Runner) processTags(osArch string, osType commonParams.OSType, tags []string) ([]string, error) { - // github automatically adds the "self-hosted" tag as well as the OS type (linux, windows, etc) - // and architecture (arm, x64, etc) to all self hosted runners. When a workflow job comes in, we try - // to find a pool based on the labels that are set in the workflow. If we don't explicitly define these - // default tags for each pool, and the user targets these labels, we won't be able to match any pools. - // The downside is that all pools with the same OS and arch will have these default labels. Users should - // set distinct and unique labels on each pool, and explicitly target those labels, or risk assigning - // the job to the wrong worker type. - ghArch, err := util.ResolveToGithubArch(osArch) - if err != nil { - return nil, errors.Wrap(err, "invalid arch") - } - - ghOSType, err := util.ResolveToGithubTag(osType) - if err != nil { - return nil, errors.Wrap(err, "invalid os type") - } - - labels := []string{ - "self-hosted", - ghArch, - ghOSType, - } - - for _, val := range tags { - if val != "self-hosted" && val != ghArch && val != ghOSType { - labels = append(labels, val) - } - } - - return labels, nil -} - func (r *Runner) GetInstance(ctx context.Context, instanceName string) (params.Instance, error) { if !auth.IsAdmin(ctx) { return params.Instance{}, runnerErrors.ErrUnauthorized