Skip to content

Commit

Permalink
Fix isolated workspaces ignored when using StepTemplate
Browse files Browse the repository at this point in the history
Prior to this fix, when one would use isolated workspaces (per step
workspace) in a `Task` *and* a `stepTemplate`, the isolated workspace
would be ignored and thus mounted in all steps instead.

This is now fixed by ensuring we do not loose the `Workspaces`
definition from a `Step` when we merge it with a `StepTemplate`.

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester authored and tekton-robot committed Sep 18, 2024
1 parent 1597151 commit 81b4fbf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/apis/pipeline/v1/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ 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, Results: s.Results, Params: s.Params, Ref: s.Ref, When: s.When}
newStep := Step{
Script: s.Script,
OnError: s.OnError,
Timeout: s.Timeout,
StdoutConfig: s.StdoutConfig,
StderrConfig: s.StderrConfig,
Results: s.Results,
Params: s.Params,
Ref: s.Ref,
When: s.When,
Workspaces: s.Workspaces,
}
newStep.SetContainerFields(merged)
steps[i] = newStep
}
Expand Down
42 changes: 42 additions & 0 deletions pkg/apis/pipeline/v1/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,48 @@ func TestMergeStepsWithStepTemplate(t *testing.T) {
Image: "some-image",
When: v1.StepWhenExpressions{{Input: "foo", Operator: selection.In, Values: []string{"foo", "bar"}}},
}},
}, {
name: "isolated workspaces",
template: &v1.StepTemplate{
Env: []corev1.EnvVar{{
Name: "KEEP_THIS",
Value: "A_VALUE",
}},
},
steps: []v1.Step{{
Image: "some-image",
Workspaces: []v1.WorkspaceUsage{{
Name: "foo",
MountPath: "/foo/bar",
}},
}, {
Image: "some-image",
Workspaces: []v1.WorkspaceUsage{{
Name: "bar",
MountPath: "/bar/baz",
}},
}},
expected: []v1.Step{{
Image: "some-image",
Env: []corev1.EnvVar{{
Name: "KEEP_THIS",
Value: "A_VALUE",
}},
Workspaces: []v1.WorkspaceUsage{{
Name: "foo",
MountPath: "/foo/bar",
}},
}, {
Image: "some-image",
Env: []corev1.EnvVar{{
Name: "KEEP_THIS",
Value: "A_VALUE",
}},
Workspaces: []v1.WorkspaceUsage{{
Name: "bar",
MountPath: "/bar/baz",
}},
}},
}} {
t.Run(tc.name, func(t *testing.T) {
result, err := v1.MergeStepsWithStepTemplate(tc.template, tc.steps)
Expand Down

0 comments on commit 81b4fbf

Please sign in to comment.