-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Design: Conditional execution #27
Comments
One possibility: all Tasks and Pipelines could have a |
I think there's probably a need for both "do X after a Task or Pipeline if $SOMETHING is true" and "only run this Task or Pipeline if $SOMETHING is true before we start" - the most obvious use case that we see for the latter in Jenkins Declarative Pipelines is "only run this stage if we're not on a pull request" and the like. Having different environments, etc for PR runs does cut down on the need for that to some extent, but there's always going to be some fairly sizable chunks of work that people will want to do if-and-only-if some condition is met. |
Interesting point @abayer ! So it sounds like you would recommend that we make our requirements for this design a bit more general, e.g. instead of |
@bobcatfish - exactly! Otherwise, people will end up needing to have separate but nearly identical Pipelines for a PR build vs a master build etc. What other information needs to be available is a wider question, of course, and I've got a whole spiel I'm working up on extensibility in that area as well as others. =) |
Makes sense to me @abayer - I'll update the task description! |
We hit a similar PRs -> many pipelines problem in Concourse, which has been a standing pain point. The solution being worked on is "spaces". A resource can pump versions into spaces which don't need to be defined when the pipeline is set. Take git commits, since PRs are the motivating case. Right now, a git resource follows a single branch. A PR resource can follow commits in PRs. But what I don't get is a separate pipeline, unless I either have (a) a shared pipeline for everything, (b) separate pipelines for PRs vs main or (c) tooling that creates and destroys pipelines on need. None of these is particularly palatable. The first is confusing and difficult to set up, the second introduces duplication and busywork, the third is cool but requires an investment in tooling and testing that might not be commensurate with the value. Most CF teams settle on (b), given the relative rareness of PR-based activity. Teams with a PR-based workflow gravitate towards (c). Teams working in private repos enjoy the luxury of ignoring the problem altogether. The space concept would essentially add (c) as a feature to Concourse itself. A git resource can create a "space" for each PR that lands, which essentially allows a parallel pipeline to be created on demand, but which shares its history with the overall pipeline it belongs to. Other examples of spaces I've seen discussed are upstream dependency versions and IaaSes. So you might create a new space when a new Ruby interpreter version lands (a problem buildpacks faces for literally hundreds of upstream dependencies), or have spaces to corral a single pipeline that runs deployment, upgrade and smoke tests across multiple platforms (Master Pipeline has this problem). |
@jchesterpivotal - yeah, Jenkins' multibranch Pipelines are basically (c). I should really get more familiar with Concourse. =) |
The way we've been talking about handling this is a decoupling Resources from Pipelines (if we can), discussion in #200 - so you can use the same Pipeline with different Resources. |
another use case here that @fejta brought up yesterday: conditionally executing based on which files changed in a commit, e.g. if you only changed markdown files, maybe you don't want to run your whole test suite my gut reaction is that the theoretical "metadata" that is provided to each Pipeline's Task can include information like this, and the Pipeline's Task can express if there are certain file changes it is interested in or not. |
@bobcatfish - hey, yeah, I had a note for myself scribbled down to try to understand what role "changelog"s could play in this world. Actually, that's part of a broader area I'm not clear on - historical data from run to run. I'm still getting my head around the CRD and API model here, so I don't know if we'll be recording run metadata (like, in this example, the commit hash for the git resource used in a particular run, which we'd need to calculate the changes in a subsequent run) in the |
This is something that probably isn't clear in our current docs or plans, but you can see there is a hint of it in the fact that there is a The idea was that this is a location where we would persist a copy of all of the
|
@tejal29 @bobcatfish - might be worth taking a look at Jenkins X's PipelineActivity CRD - see https://jenkins-x.io/architecture/custom-resources/ and https://github.com/jenkins-x/jx/blob/master/pkg/apis/jenkins.io/v1/types_pipeline.go. @rawlingsj can speak more to it - I'm just starting to dig in. |
It seems to me that "after this |
I also just realized that the "only execute this |
...and that means I owe @bobcatfish an apology for saying that #233 wasn't related to this. =) |
Ok, thinking out loud a bit here as to how the design and implementation work for the whole scope of this could be split up. First, I'm gonna use shorthand here for the three different use cases for conditional behavior, and because I've been neck-deep in building/maintaining/etc the Jenkins Declarative Pipeline stuff, I'm going to reuse the terminology there for two of 'em:
Now that I've rambled about terminology, on to the separate design/implementation threads...
...ok, this is getting a bit long, so I'm going to stop here, get more thoughts organized, and come back later today or tomorrow. =) |
In re: the "checking some value on some other CRD" condition - I'm pretty sure that we want something like this, but I don't know exactly how we'd use it yet, so this could be tabled until later. |
@bobcatfish - any thoughts on my comment above? I'm not at all sure yet how to actually implement it, mind you. =) |
I am so sorry this is taking so long to review @abayer 😓going to prioritize this for next week 🤞🤞🤞 |
Okay sorry again @abayer finally got a chance to review this, thanks for the thorough write-up! Now that I've got my head in this space, I'll try to be way more prompt with responding so you won't be blocked anymore :D Mostly I'd say I agree with everything you've said above!
I totally agree!
What I'm wondering is if we can define one way of expressing these conditions, and use that for all conditional cases? i.e. if:
(I'm thinking that putting those 3 features together could satisfy all of
Totally agree - a few ideas that come to mind:
I think it would be very interesting if we could allow a lot of flexibility here: i.e. if someone wanted to, they could write a Python script (i.e. we don't force a new language on them, they can use the language of their choice), but we provide some kind of simple default (and maybe allow something super flexible like rego even 😇 ) |
Sounds right to me - |
So for next steps @abayer what do you think about making a doc where we can distill your list above Looks like we have a couple ideas already:
|
Will do! |
Hey @bobcatfish @abayer, Thanks! for having this feature discussion. A kind request, May I know where we are up to in terms of One of the simple use case we are trying to address is add to "manual approval" gate in pipeline execution. pipeline:
task1:
task2:
task3:
task4:
- wait: manual-approval So pipeline execution waits to start One of the way apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: manual-approval
spec:
type: wait-until # could provide better key name
params:
- name: approved
value: false
---
apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
name: gated-pipeline
spec:
tasks:
- name: foo-task
resources:
inputs:
- name: approval
resource: manual-approval Really not sure if its right to mutate |
/assign @abayer |
Verrrrrrry beginning of the doc is shared at https://docs.google.com/document/d/1R6WlDMC3vuY5StiEIFg5MP18n7_kOa1QHxB10CRlbw0/edit?usp=sharing |
Doc now has a bunch of stream-of-consciousness thoughts and some very rough mockups for CRD changes. As I mention in the stream of consciousness bit, I think that manual approval and "wait for condition" in general probably shouldn't be in the first push - we should start with "execute this taskrun if..." and "execute these steps after a taskrun or pipelinerun if...", making sure the condition checking is extensible so that we can add "wait until..." later. "wait until..." will necessitate some sort of pubsub/message bus/eventing system that would allow external services/apps to report their completion/result so that the condition checking in the TaskRun controller could pick that up, and I'm not nearly qualified to design/implement (or even describe, really) what that should look like. =) |
…adme Update README for 0.3.1 release
@kimsterv has put together a doc solely for requirements: https://docs.google.com/document/d/1C3crx89VXbeIqAem1648IxP3SCWsQvsgjM0r2vmiPIY (shared with tekton-dev) |
Lots of great ideas above! I'm working on distilling them into a design doc (and a quick PoC) -- mostly based on @abayer 's ideas around the condition CRD + @vincent-pli 's suggestion of using containers to do the evaluation. At a high level, here is what I think the initial design should look like:
|
Looks like a great scoping to me - @dibyom do you want to review this in the working group meeting tomorrow? |
Yes! I'll get something written up by then! |
Closing since we have a design in place and issue to track (#1137) the implementation. |
@dibyom: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@dibyom has been contributing significant work including variable path resource substitution tektoncd#877 and his continued work on one of our oldest and most sought after features: conditional execution (tektoncd#27)! He has also reviewed 44+ PRs in the Pipelines repo: https://tekton.devstats.cd.foundation/d/46/pr-reviews-by-contributor?orgId=1&var-period=d&var-repo_name=tektoncd%2Fpipeline&var-reviewers="dibyom"
@dibyom has been contributing significant work including variable path resource substitution #877 and his continued work on one of our oldest and most sought after features: conditional execution (#27)! He has also reviewed 44+ PRs in the Pipelines repo: https://tekton.devstats.cd.foundation/d/46/pr-reviews-by-contributor?orgId=1&var-period=d&var-repo_name=tektoncd%2Fpipeline&var-reviewers="dibyom"
Has this been implemented yet? And if so... what version of Tekton. |
The work for this task is to design this feature and present one or more proposals (before implementing).
Expected Behavior
Pipelines need to be able to express Tasks that execute conditionally, e.g.:
Additionally (as pointed out by @abayer !) Pipelines may need more complex logic, e.g.:
This means we need to be able to express conditional execution generally against the state of the Pipeline. We can start with a specific subset, e.g.:
Actual Behavior
At the moment, execution of a Pipeline will continue to traverse DAG the user has expressed until either the Pipeline completes or one of the Tasks fails (a step exits with a non-0 code).
Additional Info
For other designs:
This doc has a (very) rough start at expressing some of the requirements for this (note doc visible to members of [email protected]).
The text was updated successfully, but these errors were encountered: