From 3d2b5cbb24dd5e8e278d52c9e26b11f5ef3f7d34 Mon Sep 17 00:00:00 2001 From: Chitrang Patel Date: Fri, 15 Mar 2024 11:50:02 -0400 Subject: [PATCH] Fix: Merge StepTemplate with Step containing Results and Params Prior to this, when we merged StepTemplate with the Spec, we would lose the Results and Params because the merged Step would overwrite the original Step. This PR adds the Results and Params when creating the new Step so that we don't lose this information. It fixes Issue https://github.com/tektoncd/pipeline/issues/7754 Signed-off-by: Chitrang Patel --- pkg/apis/pipeline/v1/merge.go | 2 +- pkg/apis/pipeline/v1/merge_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/apis/pipeline/v1/merge.go b/pkg/apis/pipeline/v1/merge.go index 45798c3726f..5153a26be5d 100644 --- a/pkg/apis/pipeline/v1/merge.go +++ b/pkg/apis/pipeline/v1/merge.go @@ -60,7 +60,7 @@ func MergeStepsWithStepTemplate(template *StepTemplate, steps []Step) ([]Step, e amendConflictingContainerFields(&merged, s) // Pass through original step Script, for later conversion. - newStep := Step{Script: s.Script, OnError: s.OnError, Timeout: s.Timeout, StdoutConfig: s.StdoutConfig, StderrConfig: s.StderrConfig} + newStep := Step{Script: s.Script, OnError: s.OnError, Timeout: s.Timeout, StdoutConfig: s.StdoutConfig, StderrConfig: s.StderrConfig, Results: s.Results, Params: s.Params} newStep.SetContainerFields(merged) steps[i] = newStep } diff --git a/pkg/apis/pipeline/v1/merge_test.go b/pkg/apis/pipeline/v1/merge_test.go index 3c7db97963c..a7803126556 100644 --- a/pkg/apis/pipeline/v1/merge_test.go +++ b/pkg/apis/pipeline/v1/merge_test.go @@ -127,6 +127,31 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { MountPath: "/workspace/data", }}, }}, + }, { + name: "results-and-params-should-not-be-removed", + template: &v1.StepTemplate{ + Command: []string{"/somecmd"}, + }, + steps: []v1.Step{{ + Image: "some-image", + OnError: "foo", + Results: []v1.StepResult{{ + Name: "result", + }}, + Params: v1.Params{{ + Name: "param", + }}, + }}, + expected: []v1.Step{{ + Command: []string{"/somecmd"}, Image: "some-image", + OnError: "foo", + Results: []v1.StepResult{{ + Name: "result", + }}, + Params: v1.Params{{ + Name: "param", + }}, + }}, }, { name: "merge-env-by-step", template: &v1.StepTemplate{