refactor: remove single-use runner utils for container name, image uri
This commit is contained in:
parent
a970cb1f5d
commit
ac2b95f8ac
2 changed files with 8 additions and 53 deletions
|
@ -25,20 +25,6 @@ func NewRunner(driver ContainerDriver, labels map[string]string) Runner {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Runner) GetImageUriByLabel(label string) string {
|
||||
uri, exists := r.Labels[label]
|
||||
|
||||
if exists {
|
||||
return uri
|
||||
}
|
||||
|
||||
return "debian:latest"
|
||||
}
|
||||
|
||||
func (r *Runner) GetContainerName(jobId string) string {
|
||||
return fmt.Sprintf("runner-%s", jobId)
|
||||
}
|
||||
|
||||
// Executes a workflow using the runner.
|
||||
//
|
||||
// This is the high-level call that will set up the container
|
||||
|
@ -62,8 +48,14 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker {
|
|||
defer groupWait.Done()
|
||||
jobTracker := NewTaskTracker(rootTracker).SetStatus("started")
|
||||
|
||||
runnerImage := r.GetImageUriByLabel(job.RunsOn)
|
||||
containerName := r.GetContainerName(jobTracker.TaskId)
|
||||
runnerImage, defined := r.Labels[job.RunsOn]
|
||||
|
||||
if !defined {
|
||||
jobTracker.SetStatus("failed").SetError(fmt.Errorf("Unknown runner image label: %s", job.RunsOn))
|
||||
return
|
||||
}
|
||||
|
||||
containerName := fmt.Sprintf("runner-%s", jobTracker.TaskId)
|
||||
|
||||
logger.Info("Using image %s (label: %s)", runnerImage, job.RunsOn)
|
||||
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
package runner
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetContainerNameReturnsADeterministicName(t *testing.T) {
|
||||
runner := Runner{}
|
||||
containerName := runner.GetContainerName("testid")
|
||||
if containerName != "runner-testid" {
|
||||
t.Errorf("Unexpected container name: %s", containerName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetImageUriByLabelReturnsAUriIfLabelled(t *testing.T) {
|
||||
labels := map[string]string{
|
||||
"test-label": "some-image",
|
||||
}
|
||||
runner := Runner{
|
||||
Labels: labels,
|
||||
}
|
||||
imageUri := runner.GetImageUriByLabel("test-label")
|
||||
if uri, _ := labels["test-label"]; imageUri != uri {
|
||||
t.Errorf("Expected uri %s, got %s instead.", uri, imageUri)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetImageUriByLabelReturnsTheDefaultUriIfLabelUnknown(t *testing.T) {
|
||||
labels := map[string]string{}
|
||||
runner := Runner{
|
||||
Labels: labels,
|
||||
}
|
||||
imageUri := runner.GetImageUriByLabel("test-label")
|
||||
if imageUri != "debian:latest" {
|
||||
t.Errorf("Expected default uri, got %s instead.", imageUri)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue