Skip to content

Commit

Permalink
Merge pull request #5 from mercedes-benz/0.1.4_without_default_labels
Browse files Browse the repository at this point in the history
feat: garm pools do not force default labels
  • Loading branch information
bavarianbidi authored May 22, 2024
2 parents 221f5bb + 8a45c2d commit 2497686
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 48 deletions.
8 changes: 0 additions & 8 deletions runner/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ 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
}

var newPool params.Pool

if pool.RepoID != "" {
Expand Down
40 changes: 0 additions & 40 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,49 +776,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{}, errors.Wrap(err, "processing tags")
}

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
Expand Down

0 comments on commit 2497686

Please sign in to comment.