Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reconciler): Support default value for RUNNER_NAME_PREFIX from my… #540

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion controllers/githubactionrunner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (r *GithubActionRunnerReconciler) getPodRunnerPairs(ctx context.Context, cr

allRunners, err := r.GithubAPI.GetRunners(ctx, cr.Spec.Organization, cr.Spec.Repository, token)
runners := funk.Filter(allRunners, func(r *github.Runner) bool {
return strings.HasPrefix(r.GetName(), cr.Name)
return strings.HasPrefix(r.GetName(), getRunnerNamePrefix(cr))
}).([]*github.Runner)

if err != nil {
Expand All @@ -426,3 +426,32 @@ func (r *GithubActionRunnerReconciler) getPodRunnerPairs(ctx context.Context, cr

return from(podList, runners), err
}

// getRunnerNamePrefix gets the prefix for the name of a runner
func getRunnerNamePrefix(cr *garov1alpha1.GithubActionRunner) string {
runnerPrefix := cr.Name

// If no value is set for env var RUNNER_NAME_PREFIX it defaults to 'github-runner'
// (https://github.com/myoung34/docker-github-actions-runner#environment-variables)
// so we check if it is set, and if not, we prepend it to the runnerPrefix used
// to check if a GitHub Actions Runner was created by us.
hasRunnerNamePrefix := false
for _, container := range cr.Spec.PodTemplateSpec.Spec.Containers {
for _, env := range container.Env {
if env.Name == "RUNNER_NAME_PREFIX" {
hasRunnerNamePrefix = true
runnerPrefix = fmt.Sprintf("%s-%s", env.Value, runnerPrefix)
break
}
}
if hasRunnerNamePrefix {
break
}
}

if !hasRunnerNamePrefix {
runnerPrefix = fmt.Sprintf("github-runner-%s", runnerPrefix)
}

return runnerPrefix
}