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 bug always overriding GenerateName when specifying last flag #644

Merged
merged 1 commit into from
Jan 31, 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/pipeline/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ func (opt *startOptions) startPipeline(pName string) error {
if err != nil {
return err
}
if len(prLast.ObjectMeta.GenerateName) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a unit test for if len(prLast.ObjectMeta.GenerateName) > 0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I'll consider it!!

pr.ObjectMeta.GenerateName = prLast.ObjectMeta.GenerateName
} else {
danielhelfand marked this conversation as resolved.
Show resolved Hide resolved
pr.ObjectMeta.GenerateName = prLast.ObjectMeta.Name + "-"
}
pr.Spec.Resources = prLast.Spec.Resources
pr.Spec.Params = prLast.Spec.Params
// If the prLast is a "new" PR, let's populate those fields too
Expand Down
77 changes: 77 additions & 0 deletions pkg/cmd/pipeline/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2410,3 +2410,80 @@ func Test_lastPipelineRun(t *testing.T) {
})
}
}

func Test_start_pipeline_last_generate_name(t *testing.T) {

pipelineName := "test-pipeline"

ps := []*v1alpha1.Pipeline{
tb.Pipeline(pipelineName, "ns",
tb.PipelineSpec(
tb.PipelineDeclaredResource("git-repo", "git"),
tb.PipelineDeclaredResource("build-image", "image"),
tb.PipelineParamSpec("pipeline-param-1", v1alpha1.ParamTypeString, tb.ParamSpecDefault("somethingdifferent-1")),
tb.PipelineParamSpec("rev-param", v1alpha1.ParamTypeString, tb.ParamSpecDefault("revision")),
tb.PipelineTask("unit-test-1", "unit-test-task",
tb.PipelineTaskInputResource("workspace", "git-repo"),
tb.PipelineTaskOutputResource("image-to-use", "best-image"),
tb.PipelineTaskOutputResource("workspace", "git-repo"),
),
),
),
}

prs := []*v1alpha1.PipelineRun{
tb.PipelineRun("test-pipeline-run-123", "ns",
tb.PipelineRunLabel("tekton.dev/pipeline", pipelineName),
tb.PipelineRunSpec(pipelineName,
tb.PipelineRunServiceAccountName("test-sa"),
tb.PipelineRunResourceBinding("git-repo", tb.PipelineResourceBindingRef("some-repo")),
tb.PipelineRunResourceBinding("build-image", tb.PipelineResourceBindingRef("some-image")),
tb.PipelineRunParam("pipeline-param-1", "somethingmorefun"),
tb.PipelineRunParam("rev-param", "revision1"),
),
),
}

// Setting GenerateName for test
prs[0].ObjectMeta.GenerateName = "test-generatename-pipeline-run-"

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

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

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

cs := pipelinetest.Clients{
Pipeline: pClient,
Kube: seedData.Kube,
}

p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube}

pipeline := Command(p)
got, _ := test.ExecuteCommand(pipeline, "start", pipelineName,
"--last",
"-r=git-repo=scaffold-git",
"-p=rev-param=revision2",
"-s=svc1",
"--task-serviceaccount=task3=task3svc3",
"--task-serviceaccount=task5=task3svc5",
"-n", "ns")

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

pr, err := cs.Pipeline.TektonV1alpha1().PipelineRuns(p.Namespace()).Get("random", v1.GetOptions{})
if err != nil {
t.Errorf("Error getting pipelineruns %s", err.Error())
}

test.AssertOutput(t, "test-generatename-pipeline-run-", pr.ObjectMeta.GenerateName)
}