Skip to content

Commit e35fb2d

Browse files
committed
feature: add paramterization support for csi in pipelineRun workspaces and taskRun workspaces
1 parent 0bc1593 commit e35fb2d

File tree

7 files changed

+392
-2
lines changed

7 files changed

+392
-2
lines changed

Diff for: docs/variables.md

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ For instructions on using variable substitutions see the relevant section of [th
125125
| `TaskRun` | `spec.workspaces[].secret.secretName` |
126126
| `TaskRun` | `spec.workspaces[].projected.sources[].configMap.name` |
127127
| `TaskRun` | `spec.workspaces[].projected.sources[].secret.name` |
128+
| `TaskRun` | `spec.workspaces[].csi.driver` |
129+
| `TaskRun` | `spec.workspaces[].csi.nodePublishSecretRef.name` |
128130
| `Pipeline` | `spec.tasks[].params[].value` |
129131
| `Pipeline` | `spec.tasks[].conditions[].params[].value` |
130132
| `Pipeline` | `spec.results[].value` |
@@ -137,3 +139,5 @@ For instructions on using variable substitutions see the relevant section of [th
137139
| `PipelineRun` | `spec.workspaces[].secret.secretName` |
138140
| `PipelineRun` | `spec.workspaces[].projected.sources[].configMap.name` |
139141
| `PipelineRun` | `spec.workspaces[].projected.sources[].secret.name` |
142+
| `PipelineRun` | `spec.workspaces[].csi.driver` |
143+
| `PipelineRun` | `spec.workspaces[].csi.nodePublishSecretRef.name` |

Diff for: pkg/reconciler/pipelinerun/pipelinerun_test.go

+113
Original file line numberDiff line numberDiff line change
@@ -5385,6 +5385,57 @@ spec:
53855385
Name: "name-1",
53865386
}}}}}},
53875387
},
5388+
{
5389+
name: "populate params to pipelineRun workspaceBindings csi.driver",
5390+
pr: parse.MustParseV1PipelineRun(t, `
5391+
metadata:
5392+
annotations:
5393+
PipelineRunAnnotation: PipelineRunValue
5394+
name: test-pipeline-run
5395+
namespace: foo
5396+
spec:
5397+
params:
5398+
- name: myCSIDriver
5399+
value: driver-1
5400+
pipelineRef:
5401+
name: test-pipeline
5402+
taskRunTemplate:
5403+
serviceAccountName: test-sa
5404+
taskRunSpecs:
5405+
- pipelineTaskName: hello-world-1
5406+
workspaces:
5407+
- name: ws-1
5408+
csi:
5409+
driver: $(params.myCSIDriver)
5410+
`),
5411+
expected: v1.WorkspaceBinding{CSI: &corev1.CSIVolumeSource{Driver: "driver-1"}},
5412+
},
5413+
{
5414+
name: "populate params to pipelineRun workspaceBindings csi.nodePublishSecretRef.name",
5415+
pr: parse.MustParseV1PipelineRun(t, `
5416+
metadata:
5417+
annotations:
5418+
PipelineRunAnnotation: PipelineRunValue
5419+
name: test-pipeline-run
5420+
namespace: foo
5421+
spec:
5422+
params:
5423+
- name: myNodePublishSecretRef
5424+
value: ref-1
5425+
pipelineRef:
5426+
name: test-pipeline
5427+
taskRunTemplate:
5428+
serviceAccountName: test-sa
5429+
taskRunSpecs:
5430+
- pipelineTaskName: hello-world-1
5431+
workspaces:
5432+
- name: ws-1
5433+
csi:
5434+
nodePublishSecretRef:
5435+
name: $(params.myNodePublishSecretRef)
5436+
`),
5437+
expected: v1.WorkspaceBinding{CSI: &corev1.CSIVolumeSource{NodePublishSecretRef: &corev1.LocalObjectReference{Name: "ref-1"}}},
5438+
},
53885439
}
53895440
for _, tt := range tests {
53905441
t.Run(tt.name, func(t *testing.T) {
@@ -5739,6 +5790,68 @@ spec:
57395790
sources:
57405791
- secret:
57415792
name: aResultValue
5793+
`),
5794+
},
5795+
{
5796+
name: "csi.driver success",
5797+
prs: []*v1.PipelineRun{parse.MustParseV1PipelineRun(t, `
5798+
metadata:
5799+
name: test-pipeline-run-different-service-accs
5800+
namespace: foo
5801+
spec:
5802+
pipelineRef:
5803+
name: test-pipeline
5804+
taskRunTemplate:
5805+
serviceAccountName: test-sa-0
5806+
workspaces:
5807+
- name: ws-1
5808+
csi:
5809+
driver: $(tasks.a-task.results.aResult)
5810+
`)},
5811+
expectedTr: mustParseTaskRunWithObjectMeta(t,
5812+
taskRunObjectMeta("test-pipeline-run-different-service-accs-b-task", "foo",
5813+
"test-pipeline-run-different-service-accs", "test-pipeline", "b-task", false),
5814+
`spec:
5815+
serviceAccountName: test-sa-0
5816+
taskRef:
5817+
name: b-task
5818+
kind: Task
5819+
workspaces:
5820+
- name: s1
5821+
csi:
5822+
driver: aResultValue
5823+
`),
5824+
},
5825+
{
5826+
name: "nodePublishSecretRef.name success",
5827+
prs: []*v1.PipelineRun{parse.MustParseV1PipelineRun(t, `
5828+
metadata:
5829+
name: test-pipeline-run-different-service-accs
5830+
namespace: foo
5831+
spec:
5832+
pipelineRef:
5833+
name: test-pipeline
5834+
taskRunTemplate:
5835+
serviceAccountName: test-sa-0
5836+
workspaces:
5837+
- name: ws-1
5838+
csi:
5839+
nodePublishSecretRef:
5840+
name: $(tasks.a-task.results.aResult)
5841+
`)},
5842+
expectedTr: mustParseTaskRunWithObjectMeta(t,
5843+
taskRunObjectMeta("test-pipeline-run-different-service-accs-b-task", "foo",
5844+
"test-pipeline-run-different-service-accs", "test-pipeline", "b-task", false),
5845+
`spec:
5846+
serviceAccountName: test-sa-0
5847+
taskRef:
5848+
name: b-task
5849+
kind: Task
5850+
workspaces:
5851+
- name: s1
5852+
csi:
5853+
nodePublishSecretRef:
5854+
name: aResultValue
57425855
`),
57435856
},
57445857
}

Diff for: pkg/reconciler/pipelinerun/resources/apply.go

+12
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ func ApplyResultsToWorkspaceBindings(trResults map[string][]v1.TaskRunResult, pr
404404
if pr.Spec.Workspaces[i].ConfigMap != nil {
405405
pr.Spec.Workspaces[i].ConfigMap.Name = substitution.ApplyReplacements(binding.ConfigMap.Name, stringReplacements)
406406
}
407+
if pr.Spec.Workspaces[i].CSI != nil {
408+
pr.Spec.Workspaces[i].CSI.Driver = substitution.ApplyReplacements(binding.CSI.Driver, stringReplacements)
409+
if pr.Spec.Workspaces[i].CSI.NodePublishSecretRef != nil {
410+
pr.Spec.Workspaces[i].CSI.NodePublishSecretRef.Name = substitution.ApplyReplacements(binding.CSI.NodePublishSecretRef.Name, stringReplacements)
411+
}
412+
}
407413
if pr.Spec.Workspaces[i].Secret != nil {
408414
pr.Spec.Workspaces[i].Secret.SecretName = substitution.ApplyReplacements(binding.Secret.SecretName, stringReplacements)
409415
}
@@ -610,6 +616,12 @@ func ApplyParametersToWorkspaceBindings(ctx context.Context, pr *v1.PipelineRun)
610616
if pr.Spec.Workspaces[i].Secret != nil {
611617
pr.Spec.Workspaces[i].Secret.SecretName = substitution.ApplyReplacements(binding.Secret.SecretName, parameters)
612618
}
619+
if pr.Spec.Workspaces[i].CSI != nil {
620+
pr.Spec.Workspaces[i].CSI.Driver = substitution.ApplyReplacements(binding.CSI.Driver, parameters)
621+
if pr.Spec.Workspaces[i].CSI.NodePublishSecretRef != nil {
622+
pr.Spec.Workspaces[i].CSI.NodePublishSecretRef.Name = substitution.ApplyReplacements(binding.CSI.NodePublishSecretRef.Name, parameters)
623+
}
624+
}
613625
if pr.Spec.Workspaces[i].Projected != nil {
614626
for j, source := range binding.Projected.Sources {
615627
if pr.Spec.Workspaces[i].Projected.Sources[j].ConfigMap != nil {

Diff for: pkg/reconciler/pipelinerun/resources/apply_test.go

+64
Original file line numberDiff line numberDiff line change
@@ -4903,6 +4903,70 @@ func TestApplyParametersToWorkspaceBindings(t *testing.T) {
49034903
},
49044904
},
49054905
},
4906+
{
4907+
name: "csi-driver",
4908+
ps: &v1.PipelineSpec{
4909+
Params: []v1.ParamSpec{
4910+
{Name: "csi-driver", Type: v1.ParamTypeString},
4911+
},
4912+
},
4913+
pr: &v1.PipelineRun{
4914+
Spec: v1.PipelineRunSpec{
4915+
Params: []v1.Param{
4916+
{Name: "csi-driver", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "csi-driver-value"}},
4917+
},
4918+
Workspaces: []v1.WorkspaceBinding{
4919+
{
4920+
CSI: &corev1.CSIVolumeSource{Driver: "$(params.csi-driver)"},
4921+
},
4922+
},
4923+
},
4924+
},
4925+
expectedPr: &v1.PipelineRun{
4926+
Spec: v1.PipelineRunSpec{
4927+
Params: []v1.Param{
4928+
{Name: "csi-driver", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "csi-driver-value"}},
4929+
},
4930+
Workspaces: []v1.WorkspaceBinding{
4931+
{
4932+
CSI: &corev1.CSIVolumeSource{Driver: "csi-driver-value"},
4933+
},
4934+
},
4935+
},
4936+
},
4937+
},
4938+
{
4939+
name: "csi-nodePublishSecretRef-name",
4940+
ps: &v1.PipelineSpec{
4941+
Params: []v1.ParamSpec{
4942+
{Name: "csi-nodePublishSecretRef-name", Type: v1.ParamTypeString},
4943+
},
4944+
},
4945+
pr: &v1.PipelineRun{
4946+
Spec: v1.PipelineRunSpec{
4947+
Params: []v1.Param{
4948+
{Name: "csi-nodePublishSecretRef-name", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "csi-nodePublishSecretRef-value"}},
4949+
},
4950+
Workspaces: []v1.WorkspaceBinding{
4951+
{
4952+
CSI: &corev1.CSIVolumeSource{NodePublishSecretRef: &corev1.LocalObjectReference{Name: "$(params.csi-nodePublishSecretRef-name)"}},
4953+
},
4954+
},
4955+
},
4956+
},
4957+
expectedPr: &v1.PipelineRun{
4958+
Spec: v1.PipelineRunSpec{
4959+
Params: []v1.Param{
4960+
{Name: "csi-nodePublishSecretRef-name", Value: v1.ParamValue{Type: v1.ParamTypeString, StringVal: "csi-nodePublishSecretRef-value"}},
4961+
},
4962+
Workspaces: []v1.WorkspaceBinding{
4963+
{
4964+
CSI: &corev1.CSIVolumeSource{NodePublishSecretRef: &corev1.LocalObjectReference{Name: "csi-nodePublishSecretRef-value"}},
4965+
},
4966+
},
4967+
},
4968+
},
4969+
},
49064970
}
49074971

49084972
for _, tt := range testCases {

Diff for: pkg/reconciler/taskrun/resources/apply.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,21 @@ func ApplyParametersToWorkspaceBindings(ts *v1.TaskSpec, tr *v1.TaskRun) *v1.Tas
229229
parameters, _, _ := getTaskParameters(tsCopy, tr, tsCopy.Params...)
230230
for i, binding := range tr.Spec.Workspaces {
231231
if tr.Spec.Workspaces[i].PersistentVolumeClaim != nil {
232-
binding.PersistentVolumeClaim.ClaimName = substitution.ApplyReplacements(binding.PersistentVolumeClaim.ClaimName, parameters)
232+
tr.Spec.Workspaces[i].PersistentVolumeClaim.ClaimName = substitution.ApplyReplacements(binding.PersistentVolumeClaim.ClaimName, parameters)
233233
}
234234
tr.Spec.Workspaces[i].SubPath = substitution.ApplyReplacements(binding.SubPath, parameters)
235235
if tr.Spec.Workspaces[i].ConfigMap != nil {
236-
binding.ConfigMap.Name = substitution.ApplyReplacements(binding.ConfigMap.Name, parameters)
236+
tr.Spec.Workspaces[i].ConfigMap.Name = substitution.ApplyReplacements(binding.ConfigMap.Name, parameters)
237237
}
238238
if tr.Spec.Workspaces[i].Secret != nil {
239239
tr.Spec.Workspaces[i].Secret.SecretName = substitution.ApplyReplacements(binding.Secret.SecretName, parameters)
240240
}
241+
if tr.Spec.Workspaces[i].CSI != nil {
242+
tr.Spec.Workspaces[i].CSI.Driver = substitution.ApplyReplacements(binding.CSI.Driver, parameters)
243+
if tr.Spec.Workspaces[i].CSI.NodePublishSecretRef != nil {
244+
tr.Spec.Workspaces[i].CSI.NodePublishSecretRef.Name = substitution.ApplyReplacements(binding.CSI.NodePublishSecretRef.Name, parameters)
245+
}
246+
}
241247
if binding.Projected != nil {
242248
for j, source := range binding.Projected.Sources {
243249
if source.ConfigMap != nil {

Diff for: pkg/reconciler/taskrun/resources/apply_test.go

+88
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,94 @@ func TestApplyParametersToWorkspaceBindings(t *testing.T) {
19201920
},
19211921
},
19221922
},
1923+
{
1924+
name: "csi-driver",
1925+
ts: &v1.TaskSpec{
1926+
Params: []v1.ParamSpec{
1927+
{Name: "csi-driver-name", Type: v1.ParamTypeString},
1928+
},
1929+
},
1930+
tr: &v1.TaskRun{
1931+
Spec: v1.TaskRunSpec{
1932+
Workspaces: []v1.WorkspaceBinding{
1933+
{
1934+
CSI: &corev1.CSIVolumeSource{Driver: "$(params.csi-driver-name)"},
1935+
},
1936+
},
1937+
Params: v1.Params{
1938+
{
1939+
Name: "csi-driver-name", Value: v1.ParamValue{
1940+
Type: v1.ParamTypeString,
1941+
StringVal: "csi-driver-value",
1942+
},
1943+
},
1944+
},
1945+
},
1946+
},
1947+
want: &v1.TaskRun{
1948+
Spec: v1.TaskRunSpec{
1949+
Workspaces: []v1.WorkspaceBinding{
1950+
{
1951+
CSI: &corev1.CSIVolumeSource{Driver: "csi-driver-value"},
1952+
},
1953+
},
1954+
Params: v1.Params{
1955+
{
1956+
Name: "csi-driver-name", Value: v1.ParamValue{
1957+
Type: v1.ParamTypeString,
1958+
StringVal: "csi-driver-value",
1959+
},
1960+
},
1961+
},
1962+
},
1963+
},
1964+
},
1965+
{
1966+
name: "csi-nodePublishSecretRef-name",
1967+
ts: &v1.TaskSpec{
1968+
Params: []v1.ParamSpec{
1969+
{Name: "csi-nodePublishSecretRef-name", Type: v1.ParamTypeString},
1970+
},
1971+
},
1972+
tr: &v1.TaskRun{
1973+
Spec: v1.TaskRunSpec{
1974+
Workspaces: []v1.WorkspaceBinding{
1975+
{
1976+
CSI: &corev1.CSIVolumeSource{NodePublishSecretRef: &corev1.LocalObjectReference{
1977+
Name: "$(params.csi-nodePublishSecretRef-name)",
1978+
}},
1979+
},
1980+
},
1981+
Params: v1.Params{
1982+
{
1983+
Name: "csi-nodePublishSecretRef-name", Value: v1.ParamValue{
1984+
Type: v1.ParamTypeString,
1985+
StringVal: "csi-nodePublishSecretRef-value",
1986+
},
1987+
},
1988+
},
1989+
},
1990+
},
1991+
want: &v1.TaskRun{
1992+
Spec: v1.TaskRunSpec{
1993+
Workspaces: []v1.WorkspaceBinding{
1994+
{
1995+
CSI: &corev1.CSIVolumeSource{NodePublishSecretRef: &corev1.LocalObjectReference{
1996+
Name: "csi-nodePublishSecretRef-value",
1997+
}},
1998+
},
1999+
},
2000+
Params: v1.Params{
2001+
{
2002+
Name: "csi-nodePublishSecretRef-name", Value: v1.ParamValue{
2003+
Type: v1.ParamTypeString,
2004+
StringVal: "csi-nodePublishSecretRef-value",
2005+
},
2006+
},
2007+
},
2008+
},
2009+
},
2010+
},
19232011
}
19242012
for _, tt := range tests {
19252013
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)