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 workspace types for Task and TaskRun with validation #1639

Merged
merged 1 commit into from
Dec 17, 2019

Conversation

bobcatfish
Copy link
Collaborator

@bobcatfish bobcatfish commented Nov 27, 2019

Changes

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 #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.

Future work:

  • Support for readonly
  • Support for configmap + secret volume types
  • Support in Pipeline + PipelineRun

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

Release Notes

Adds the concept of "workspaces" to Tasks. This allows Task authors to declare directories they expect to be provided via Volumes at runtime. At runtime, TaskRuns can provide PVCs or EmptyDirs to use for these directories.

@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 27, 2019
@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Nov 27, 2019
@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 27, 2019
docs/taskruns.md Outdated
- name: myworkspace
persistentVolumeClaim:
claimName: mypvc
volumeSubPath: my-subdir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be just subPath to match api

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, thanks for catching this!

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👼

Any reason to use StepTemplates for this ? "Add validation to ensure that the mountPaths don't clash with any explicitly declared volumeMounts" might be a valid reason 🤔

Randomize the volume name + volumeMount names so we don't have to worry about clashing with existing volumeMounts + volume names

This would mean the user has to use the variable substitution to get the name of the mountpoint right ? I think that's fair though 👼

Add support for ConfigMaps (and secrets?)

That would make sense, but we certainly can do that in follow-ups 😉

@bobcatfish
Copy link
Collaborator Author

Any reason to use StepTemplates for this ?

Basically just b/c it was convenient! 😅 maybe one way to make this a bit cleaner would be to create a new "step template" just for this, merge it with the user provided step template, and pass the result into the pod creation function - not sure how much different that'd be tho 🤔

@bobcatfish
Copy link
Collaborator Author

This would mean the user has to use the variable substitution to get the name of the mountpoint right ? I think that's fair though 👼

sgtm!

@tekton-robot tekton-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 3, 2019
@tekton-robot
Copy link
Collaborator

The following is the coverage report on pkg/.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/workspace_validation.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 74.8% 73.9% -0.9
pkg/workspace/apply.go Do not exist 94.4%
pkg/workspace/validate.go Do not exist 100.0%

@skaegi
Copy link
Contributor

skaegi commented Dec 3, 2019

One question... is there a particular concern and reason why the WorkspaceBinding embeds a PVCSource / EmptyDir instead of just a volume name? I already have cases where I would really like to embed Secrets and ConfigMaps as volumes and this would be helpful. Is there some concern about supporting some kinds of volume types?

Also... could we consider adding a readOnly boolean on the WorkspaceBinding. I believe the implementation is to emit a VolumeMount which already supports this field.

@vdemeester
Copy link
Member

One question... is there a particular concern and reason why the WorkspaceBinding embeds a PVCSource / EmptyDir instead of just a volume name? I already have cases where I would really like to embed Secrets and ConfigMaps as volumes and this would be helpful. Is there some concern about supporting some kinds of volume types?

Initially I thought "to be able to get the correct type of volume", but we don't really have to. So I'm now asking myself the same question 😝

Also... could we consider adding a readOnly boolean on the WorkspaceBinding. I believe the implementation is to emit a VolumeMount which already supports this field.

👍

@ghost
Copy link

ghost commented Dec 4, 2019

Here I've taken the example workspace taskrun yaml from this PR and added a volume to the podTemplate in the taskrun:

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
      volumeName: mypd
      subPath: my-subdir
    - name: custom2
      volumeName: mypd
  podTemplate:
    volumes:
      - name: mypd
        persistentVolumeClaim:
          claimName: my-pvc
  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"]
    - name: write2
      image: ubuntu
      command: ["/bin/bash"]
      args: ["-c", "echo stuffs > /workspace/custom2/foo"]
    - name: read2
      image: ubuntu
      command: ["/bin/bash"]
      args: ["-c", "cat /workspace/custom2/foo | grep stuffs"]
    workspaces:
    - name: custom
    - name: custom2

Is this about what you'd expect @skaegi , @vdemeester ?

@ghost
Copy link

ghost commented Dec 4, 2019

In regards support for configmaps and secrets - we have plans to implement those as part of this (it's in the TODOs section at the top).

Is there any other reason to separate them out like this rather than just having the volume type embedded in the workspace binding?

@ghost
Copy link

ghost commented Dec 4, 2019

Also - readOnly is definitely on the roadmap for workspaces! whether or not it's part of this PR.

@ghost
Copy link

ghost commented Dec 4, 2019

(for a bit of context - @bobcatfish and I wrote it initially to use the podTemplate volumes but it felt like extra yaml when we could make it part of the binding spec and leave the podTemplate out of things completely)

@vdemeester
Copy link
Member

Is this about what you'd expect @skaegi , @vdemeester ?

Oh, ok, I would maybe prefer the following (but 😛) to reduce a bit the verbosity of the thing.

# […]
spec:
  workspaces:
    - name: custom
      persistentVolumeClaim:
        claimName: my-pvc
      subPath: my-subdir
    - name: custom2
      persistentVolumeClaim:
        claimName: my-pvc
# […]

@skaegi
Copy link
Contributor

skaegi commented Dec 4, 2019

Thanks for the example @sbwsg -- that helps. I forgot that taskruns don't directly have volumes and agree the extra podSpec stuff just doesn't look great and does not enhance readability.

@skaegi
Copy link
Contributor

skaegi commented Dec 4, 2019

I went back through our current usage to verify and can confirm that if we had...

configMap [ConfigMapVolumeSource]
emptyDir [EmptyDirVolumeSource]
persistentVolumeClaim [PersistentVoluemClaimVolumeSource]
secret: [SecretVolumeSource]

all of our cases are covered.

We also on occasion might use downwardAPI volumes however that is always static and not parameterized. Especially in the context of a TaskRun I found downwardAPI a bit strange as it ends up looking up values against the Pod so I'm happy to not have it present in the WorkspaceBinding.

@bobcatfish a while back we had wondered about removing volumes from the Task. The TLDR; is I think we want to retain support. Looking through our usage I see cases where a Task wants to do work in emptyDir memory and also cases where we're mounting the hostPath. We might also directly generate non-parameterizable Tasks that hardcode the pvcs and devices involved so having volumes grants us flexibility there too.

bobcatfish added a commit to bobcatfish/pipeline that referenced this pull request Dec 6, 2019
Each test case for parameter substitution application was being given a
totally separate test case, with the variables being used being declared
in different places across the file. For tektoncd#1639 I came along and wanted
to start adding more tests for workspace substitution and found it hard
to tell where to start so I:

* Combined most of the test cases for param subsitution into one test
  so you can easily see everything that is being tested (none of the
  test cases conflicted with each other and can easily be applied
  together)
* I kept the array param test cases separate cuz they seemd to be
  testing distinct test cases
* The Volume test cases were a bit odd b/c they were trying to make sure
  substitution was _applied_ to volumes, but there is no volume specific
  function so they were calling an internal function and passing in
  dummy values that are not representative of the actual values you'd
  substitute for volumes so instead I folded these test cases into the
  param application test.

Probably the resource application test case should be made quite similar
to the param test but it seemed like some of the resource stuff was
distinct and had to be tested in isolateion (e.g. just outputs, just
inputs, etc.)

Also removed some depreated (and duplicated!) volume tests:
in tektoncd#1311 I removed support for ${} but instead of removing these tests
I just updated them, making them duplicates of the above test cases.
@bobcatfish bobcatfish marked this pull request as ready for review December 6, 2019 22:02
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 6, 2019
@bobcatfish
Copy link
Collaborator Author

This should be ready for a real review @skaegi @vdemeester @sbwsg ! 🎉

@tekton-robot
Copy link
Collaborator

The following is the coverage report on pkg/.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1alpha1/task_validation.go 81.2% 83.4% 2.2
pkg/apis/pipeline/v1alpha1/taskrun_validation.go 95.3% 96.2% 0.9
pkg/apis/pipeline/v1alpha1/workspace_types.go Do not exist 100.0%
pkg/apis/pipeline/v1alpha1/workspace_validation.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 74.8% 74.0% -0.8
pkg/workspace/apply.go Do not exist 94.1%
pkg/workspace/validate.go Do not exist 100.0%
test/builder/task.go 81.4% 81.9% 0.5

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@tekton-robot tekton-robot assigned ghost Dec 11, 2019
@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 11, 2019
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On thought: we need to be aware of #1701 👼
Otherwise, looks good to me 👼

/cc @skaegi

@vdemeester
Copy link
Member

I1210 22:23:15.091] pkg/apis/pipeline/v1alpha1/git_resource.go:125:16: undefined: pipeline.WorkspaceDir
I1210 22:23:15.092] pkg/apis/pipeline/v1alpha1/pull_request_resource.go:142:15: undefined: pipeline.WorkspaceDir
I1210 22:23:15.092] pkg/apis/pipeline/v1alpha1/workspace_types.go:44:23: undefined: pipeline.WorkspaceDir

@bobcatfish Did you forget to commit something ? 🤔

@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 16, 2019
@bobcatfish
Copy link
Collaborator Author

Thanks @vdemeester ! @skaegi you said you this approach looks like it'll work for you, @sbwsg mentioned you wanted to try this out a bit and give us some more feedback. Since we still have to do the Pipeline and PipelineRun portion of this, I'm assuming you'd be okay with merging this PR and continuing to iterate on the design as we keep working on it (let me know if not!)

@tekton-robot
Copy link
Collaborator

The following is the coverage report on pkg/.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go Do not exist 94.1%
pkg/workspace/validate.go Do not exist 100.0%
test/builder/task.go 81.8% 82.3% 0.5

@bobcatfish
Copy link
Collaborator Author

I1216 14:37:17.611] pkg/workspace/apply_test.go:29: File is not `gofmt`-ed with `-s` (gofmt)
I1216 14:37:17.611] 			"custom": corev1.Volume{
I1216 14:37:17.611] pkg/pod/pod.go:34:2: `homeVolumeName` is unused (varcheck)
I1216 14:37:17.611] 	homeVolumeName      = "tekton-internal-home"
I1216 14:37:17.612] 	^
I1216 14:37:17.612] pkg/pod/pod.go:33:2: `workspaceVolumeName` is unused (varcheck)
I1216 14:37:17.612] 	workspaceVolumeName = "tekton-internal-workspace"
I1216 14:37:17.612] 	^

whoops

@tekton-robot
Copy link
Collaborator

The following is the coverage report on pkg/.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go Do not exist 94.1%
pkg/workspace/validate.go Do not exist 100.0%
test/builder/task.go 81.8% 82.3% 0.5

@ghost
Copy link

ghost commented Dec 16, 2019

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 16, 2019
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

but @bobcatfish it needs a rebase (again 😛 )

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vdemeester

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 17, 2019
@vdemeester vdemeester added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 17, 2019
@vdemeester
Copy link
Member

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 17, 2019
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.

It's possible folks might be specifying volumes already in the Task or
via the stepTemplate that might collide with the names we are using for
the workspaces; instead of validating this and making the Task author
change these, we can instead randomize them!

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 <sbws@google.com>
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 17, 2019
@ghost
Copy link

ghost commented Dec 17, 2019

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 17, 2019
@tekton-robot
Copy link
Collaborator

The following is the coverage report on pkg/.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go Do not exist 94.1%
pkg/workspace/validate.go Do not exist 100.0%
test/builder/task.go 81.8% 82.3% 0.5

@vdemeester vdemeester removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 17, 2019
@tekton-robot tekton-robot merged commit c55d311 into tektoncd:master Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants