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

Add variable substitution for PVC name #2506

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
1 change: 1 addition & 0 deletions docs/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ in `Tasks` and `Pipelines`.
| `resources.outputs.<resource name>.path` | The path to the output resource's directory. |
| `results.<result name>.path` | The path to the file where a Task's result should be written. |
| `workspaces.<workspace name>.path` | The path to the mounted workspace. |
| `workspaces.<workspace name>.claim` | The name of the PersistentVolumeClaim used as a volume source for the workspace or empty string if a volume source other than PersistentVolumeClaim was used. |
| `workspaces.<workspace name>.volume` | The name of the volume populating the workspace. |
| `credentials.path` | The path to the location of credentials written by the `creds-init` init container. |

Expand Down
12 changes: 10 additions & 2 deletions pkg/reconciler/taskrun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ func ApplyResources(spec *v1alpha1.TaskSpec, resolvedResources map[string]v1alph
return ApplyReplacements(spec, replacements, map[string][]string{})
}

// ApplyWorkspaces applies the substitution from paths that the workspaces in w are mounted to and the
// volumes that wb are realized with in the task spec ts.
// ApplyWorkspaces applies the substitution from paths that the workspaces in w are mounted to, the
// volumes that wb are realized with in the task spec ts and the PersistentVolumeClaim names for the
// workspaces.
func ApplyWorkspaces(spec *v1alpha1.TaskSpec, w []v1alpha1.WorkspaceDeclaration, wb []v1alpha1.WorkspaceBinding) *v1alpha1.TaskSpec {
stringReplacements := map[string]string{}

Expand All @@ -108,6 +109,13 @@ func ApplyWorkspaces(spec *v1alpha1.TaskSpec, w []v1alpha1.WorkspaceDeclaration,
for name, vv := range v {
stringReplacements[fmt.Sprintf("workspaces.%s.volume", name)] = vv.Name
}
for _, w := range wb {
if w.PersistentVolumeClaim != nil {
stringReplacements[fmt.Sprintf("workspaces.%s.claim", w.Name)] = w.PersistentVolumeClaim.ClaimName
} else {
stringReplacements[fmt.Sprintf("workspaces.%s.claim", w.Name)] = ""
}
}
return ApplyReplacements(spec, stringReplacements, map[string][]string{})
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/reconciler/taskrun/resources/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ func TestApplyWorkspaces(t *testing.T) {
Env: []corev1.EnvVar{{
Name: "template-var",
Value: "$(workspaces.myws.volume)",
}, {
Name: "pvc-name",
Value: "$(workspaces.myws.claim)",
}, {
Name: "non-pvc-name",
Value: "$(workspaces.otherws.claim)",
}},
},
Steps: []v1alpha1.Step{{Container: corev1.Container{
Expand Down Expand Up @@ -671,6 +677,8 @@ func TestApplyWorkspaces(t *testing.T) {
}}
want := applyMutation(ts, func(spec *v1alpha1.TaskSpec) {
spec.StepTemplate.Env[0].Value = "ws-9l9zj"
spec.StepTemplate.Env[1].Value = "foo"
spec.StepTemplate.Env[2].Value = ""

spec.Steps[0].Name = "ws-9l9zj"
spec.Steps[0].Image = "ws-mz4c7"
Expand Down