diff --git a/internal/runner/runner.go b/internal/runner/runner.go index b4b7846..98461f6 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -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) diff --git a/internal/runner/runner_test.go b/internal/runner/runner_test.go deleted file mode 100644 index 283eb41..0000000 --- a/internal/runner/runner_test.go +++ /dev/null @@ -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) - } -}