forked from tektoncd/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workspace types for Task and TaskRun with validation
This allows users to use Volumes with Tasks such that: - The actual volumes to use (or subdirectories on those volumes) are provided at runtime, not at Task authoring time - At Task authoring time you can declare that you expect a volume to be provided and control what path that volume should end up at - Validation will be provided that the volumes (workspaces) are actually provided at runtime Before this change, there were two ways to use Volumes with Tasks: - VolumeMounts were explicitly declared at the level of a step - Volumes were declared in Tasks, meaning the Task author controlled the name of the volume being used and it wasn't possible at runtime to use a subdir of the volume - Or the Volume could be provided via the podTemplate, if the user realized this was possible None of this was validated and could cause unexpected and hard to diagnose errors at runtime. We have also limited (at least initially) the types of volume source being supported instead of expanding to all volume sources, tho we can expand it later if we want to and if users need it. This would reduce the API surface that a Tekton compliant system would need to conform to (once we actually define what conformance means!). Part of tektoncd#1438 In future commits we will add support for workspaces to Pipelines and PipelineRuns as well; for now if a user tries to use a Pipeline with a Task that requires a Workspace, it will fail at runtime because it is not (yet) possible for the Pipeline and PipelineRun to provide workspaces. Co-authored-by: Scott <[email protected]>
- Loading branch information
1 parent
f2daa0b
commit f9b302e
Showing
20 changed files
with
1,003 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: my-pvc | ||
spec: | ||
resources: | ||
requests: | ||
storage: 5Gi | ||
volumeMode: Filesystem | ||
accessModes: | ||
- ReadWriteOnce | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: TaskRun | ||
metadata: | ||
generateName: custom-volume- | ||
spec: | ||
workspaces: | ||
- name: custom | ||
emptyDir: {} | ||
persistentVolumeClaim: | ||
claimName: my-pvc | ||
subPath: my-subdir | ||
taskSpec: | ||
steps: | ||
- name: write | ||
image: ubuntu | ||
command: ["/bin/bash"] | ||
args: ["-c", "echo stuff > /workspace/custom/foo"] | ||
- name: read | ||
image: ubuntu | ||
command: ["/bin/bash"] | ||
args: ["-c", "cat /workspace/custom/foo | grep stuff"] | ||
workspaces: | ||
- name: custom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright 2019 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// WorkspaceDeclaration is a declaration of a volume that a Task requires. | ||
type WorkspaceDeclaration struct { | ||
// Name is the name by which you can bind the volume at runtime. | ||
Name string `json:"name"` | ||
// Description is an optional human readable description of this volume. | ||
// +optional | ||
Description string `json:"description,omitempty"` | ||
// MountPath overrides the directory that the volume will be made available at. | ||
// +optional | ||
MountPath string `json:"mountPath,omitempty"` | ||
} | ||
|
||
// WorkspaceBinding maps a Task's declared workspace to a Volume. | ||
// Currently we only support PersistentVolumeClaims and EmptyDir. | ||
type WorkspaceBinding struct { | ||
// Name is the name of the workspace populated by the volume. | ||
Name string `json:"name"` | ||
// SubPath is optionally a directory on the volume which should be used | ||
// for this binding (i.e. the volume will be mounted at this sub directory). | ||
// +optional | ||
SubPath string `json:"subPath,omitempty"` | ||
// PersistentVolumeClaimVolumeSource represents a reference to a | ||
// PersistentVolumeClaim in the same namespace. Either this OR EmptyDir can be used. | ||
// +optional | ||
PersistentVolumeClaim *corev1.PersistentVolumeClaimVolumeSource `json:"persistentVolumeClaim,omitempty"` | ||
// EmptyDir represents a temporary directory that shares a Task's lifetime. | ||
// More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir | ||
// Either this OR PersistentVolumeClaim can be used. | ||
// +optional | ||
EmptyDir *corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty"` | ||
} |
Oops, something went wrong.