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 <[email protected]>
(cherry picked from commit 81b4fbf)
  • Loading branch information
vdemeester authored and tekton-robot committed Oct 1, 2024
1 parent 5e6ec48 commit ea65f15
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/apis/pipeline/v1/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ 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,
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 @@ -183,6 +183,48 @@ func TestMergeStepsWithStepTemplate(t *testing.T) {
},
}},
}},
}, {
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 ea65f15

Please sign in to comment.