title | authors | creation-date | last-updated | status | |
---|---|---|---|---|---|
workspace-paths |
|
2020-10-07 |
2020-10-18 |
proposed |
This TEP is motivated by several ideas:
- Tasks should be able to declare the content they expect to receive via a Workspace as well as the content they produce on to a Workspace.
- Pipelines should be able to declare dependencies on specific files or paths from one PipelineTask to be used by another PipelineTask.
- TaskRuns and PipelineRuns should be able to declare when a path a Task/Pipeline is expecting lives at a different location on the Workspace that the Run is binding. They should also be able to override the location that a Task/Pipeline will write content to on a Workspace.
- Tekton should be better able to validate workspaces at runtime.
- Catalog tasks are already doing this in an ad-hoc way and support should be made consistently available.
There are also some slightly more "woolly" reasons which I'll summarise at the end of this section.
Tasks
Task authors currently express whether a workspace is optional as well as where that workspace will be mounted. Workspace Paths adds an option for Task authors to declare important files or directories that must either be provided on a received Workspace or created on a Workspace during execution.
Example:
A
git
Task exposes anssh-credentials
workspace that expects the following files:private-key
(with default path"id_rsa"
) andknown_hosts
(default path"known_hosts"
).The same
git
Task exposes anoutput
workspace that lets the TaskRun choose a subdirectory of the Workspace to clone a repo into.
Pipelines
Pipeline authors currently express which workspaces are given to which PipelineTasks. Workspace Paths allows Pipeline authors to define files that a PipelineTask should produce that other PipelineTasks will consume.
Example:
A
git-clone
PipelineTask checks out a repo and the Pipeline declares that this checkout should include aDockerfile
. TheDockerfile
is then fed to thedocker-build
Task. The relationship between the two PipelineTasks should be understood as arunAfter
relationship:git-clone
must run first anddocker-build
should run second.
TaskRuns and PipelineRuns
TaskRun and PipelineRun authors can currently bind specific volume types to Workspaces. They should additionally be able to override the expected location of important files and directories on a Workspace.
Example:
A
git
Task expects a Workspace with aprivate-key
path on it, with default location of"/id_rsa"
. A TaskRun can override it to look instead at"/my-keys/id_ecdsa"
.
The only validation Tekton currently performs of Workspaces is against the Workspace structs in the controller. The Workspace Paths feature would allow for more precise runtime validation of the paths a workspace has provided or left out.
Example: In a
node-webpack-build
Task, a missingwebpack.config.js
file could result in a uniform error before the Task's Steps are allowed to run:Workspace path missing: workspace "source-repo" does not provide "webpack_config": expected path "/workspace/source-repo/webpack.config.js".
. This would put the TaskRun (or PipelineRun) into a clear failed state with the exact Task that expected the file along with which file was missing.
There are several patterns becoming more common in the catalog now that workspaces are seeing more use:
-
Tasks declare both a
workspace
as well as aparam
for a path into the workspace. Here's an example from our catalog:workspaces: - name: source description: A workspace where files will be uploaded from. - name: credentials description: A secret with a service account key to use as GOOGLE_APPLICATION_CREDENTIALS. params: - name: path description: The path to files or directories relative to the source workspace that you'd like to upload. type: string - name: serviceAccountPath description: The path inside the credentials workspace to the GOOGLE_APPLICATION_CREDENTIALS key file. type: string
Note above that the
path
andserviceAccountPath
params
are providing information specific to thesource
andcredentials
workspaces. Two things fall out from this:- Catalog Task authors clearly see a need to allow the paths into Workspaces to be customisable by users of their Tasks.
- The more workspaces that are needed for a Task, the more params the author needs to include to provide this customisable path behavior.
At time of writing there are 30 catalog entries employing this pattern. See the Catalog Examples reference for links to all of those.
-
Workspace descriptions are required to explain both the purpose of the workspace and the files that are expected to be received on them. Example from recent
tkn
PR:- kubeconfig: An optional workspace
that allows you to provide a
.kube/config
file fortkn
to access the cluster. The file should be placed at the root of the Workspace with namekubeconfig
.
- kubeconfig: An optional workspace
that allows you to provide a
The following items also motivate this TEP but to a lesser degree:
- Decouple declaration of the files and directories a Task needs from their eventual "location" inside the Task Steps' containers.
- Provide a kind of "structural typing" for the contents of a workspace, and a way for different but compatible "types" to interface by mapping paths.
- Provide a way for Task authors to declare paths expected on a workspace.
- Provide a way for Task authors to declare paths that will be produced on a workspace.
- Provide a way for Pipeline authors to declare important files that one PipelineTask produces and another expects.
- Allow overriding the paths in TaskRuns and Pipelines/PipelineRuns.
- Provide clear errors when expected or created paths are missing.
- Provide a blessed way of declaring paths on a workspace in catalog tasks.
- Inject new variables that allow Task and Pipeline authors to access paths without hard-coding them.
- Declaring any other file features like file types, permissions, content validation, etc...
-
When a workspace is optional, files should only be validated if the workspace is provided.
-
Any variables exposed by Workspace Paths should degrade gracefully if the workspace is optional and not provided.
$(workspaces.foo.files.bar.path)
should resolve to an empty string if the optional workspacefoo
is not provided. -
A Workspace Path can be any filesystem entry with a path: a file, a directory, a symlink, etc.
As a git
Task author I want to declare which files my Task expects to appear in the
ssh-credentials
workspace so that users can quickly learn the necessary files to
provide in their Secrets
.
As a webpack
build Task author I want to validate that webpack.config.js
is present in a given workspace before I try to run webpack so that my Task
fails early with a clear error message if an incorrectly populated workspace
has been passed to it.
As the author of a go-build
Task I want the user to be able to declare a specific
directory to build inside a workspace so that projects with any directory structure
can be built by my Task.
As the author of a TaskRun that builds and releases a project using "config-as-code" principles I want to organize my config and credential files in my team's repo according to my org's requirements (and not according to the requirements of the catalog Tasks I am choosing) so that I am structuring my projects within my company's agreed-upon guidelines.
- Some of the features stem from requirements in the issue Improve UX of getting credentials into Tasks.
- Echoes some of the described features of the FileSet Resource in the PipelineResources redesign from winter 2019/20.
- File contract features of the PipelineResources revamp.
Here are all of the examples in the catalog where we ask for both a workspace and a param providing a path into that workspace.
- 02-build-runtime-with-gradle
- 03-build-shared-class-cache
- 04-finalize-runtime-with-function
- 01-install-deps
- 02-build-archive
- 03-openwhisk
- 01-install-deps
- 02-build-archive
- 03-openwhisk
- ansible-runner
- build-push-gke-deploy
- buildpacks-phases
- buildpacks
- create-github-release
- gcs-create-bucket
- gcs-delete-bucket
- gcs-download
- gcs-generic
- gcs-upload
- git-batch-merge
- git-batch-merge
- git-clone
- git-clone
- github-app-token
- gke-cluster-create
- jib-gradle
- jib-maven
- kaniko
- maven
- wget