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 overriding GenerateName on taskrun #670

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions pkg/cmd/task/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ func startTask(opt startOptions, args []string) error {
if err != nil {
return err
}
if len(trLast.ObjectMeta.GenerateName) > 0 {
tr.ObjectMeta.GenerateName = trLast.ObjectMeta.GenerateName
} else {
tr.ObjectMeta.GenerateName = trLast.ObjectMeta.Name + "-"
chmouel marked this conversation as resolved.
Show resolved Hide resolved
}
tr.Spec.Inputs = trLast.Spec.Inputs
tr.Spec.Outputs = trLast.Spec.Outputs
tr.Spec.ServiceAccountName = trLast.Spec.ServiceAccountName
Expand Down
76 changes: 76 additions & 0 deletions pkg/cmd/task/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,82 @@ func Test_start_task_last(t *testing.T) {
test.AssertOutput(t, "", tr.Spec.Workspaces[0].SubPath)
}

func Test_start_task_last_generate_name(t *testing.T) {
tasks := []*v1alpha1.Task{
tb.Task("task", "ns",
tb.TaskSpec(
tb.TaskInputs(
tb.InputsResource("my-repo", v1alpha1.PipelineResourceTypeGit),
tb.InputsParamSpec("myarg", v1alpha1.ParamTypeString),
tb.InputsParamSpec("print", v1alpha1.ParamTypeArray),
),
tb.TaskOutputs(
tb.OutputsResource("code-image", v1alpha1.PipelineResourceTypeImage),
),
tb.Step("busybox",
tb.StepName("hello"),
),
tb.Step("busybox",
tb.StepName("exit"),
),
tb.TaskWorkspace("test", "test workspace", "/workspace/test/file", true),
),
),
}

taskruns := []*v1alpha1.TaskRun{
tb.TaskRun("taskrun-123", "ns",
tb.TaskRunLabel("tekton.dev/task", "task"),
tb.TaskRunSpec(
tb.TaskRunTaskRef("task"),
tb.TaskRunServiceAccountName("svc"),
tb.TaskRunInputs(tb.TaskRunInputsParam("myarg", "value")),
tb.TaskRunInputs(tb.TaskRunInputsParam("print", "booms", "booms", "booms")),
tb.TaskRunInputs(tb.TaskRunInputsResource("my-repo", tb.TaskResourceBindingRef("git"))),
tb.TaskRunOutputs(tb.TaskRunOutputsResource("code-image", tb.TaskResourceBindingRef("image"))),
tb.TaskRunWorkspaceEmptyDir("test", ""),
),
),
}

ns := []*corev1.Namespace{
{
ObjectMeta: metav1.ObjectMeta{
Name: "ns",
},
},
}

// Setting GenerateName for test
taskruns[0].ObjectMeta.GenerateName = "test-generatename-task-run-"

seedData, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: ns})

objs := []runtime.Object{tasks[0], taskruns[0]}
pClient := newPipelineClient(objs...)

cs := pipelinetest.Clients{
Pipeline: pClient,
Kube: seedData.Kube,
}
p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube}

task := Command(p)
got, _ := test.ExecuteCommand(task, "start", "task",
"--last",
"-n=ns")

expected := "Taskrun started: random\n\nIn order to track the taskrun progress run:\ntkn taskrun logs random -f -n ns\n"
test.AssertOutput(t, expected, got)

tr, err := cs.Pipeline.TektonV1alpha1().TaskRuns("ns").Get("random", v1.GetOptions{})
if err != nil {
t.Errorf("Error listing taskruns %s", err.Error())
}

test.AssertOutput(t, "test-generatename-task-run-", tr.ObjectMeta.GenerateName)
}

func Test_start_task_last_with_inputs(t *testing.T) {
tasks := []*v1alpha1.Task{
tb.Task("task", "ns",
Expand Down