Skip to content

Commit

Permalink
Adds an initial implementation for conditionals
Browse files Browse the repository at this point in the history
In this implementation, condition evaluations aka ConditionChecks are
backed by TaskRuns. All conditionChecks associated with a `PipelineTask`
have to succeed before the task is executed. If a ConditionCheck fails,
the PipelineTask's associated TaskRun is marked failed i.e. its
`Status.ConditionSucceeded` is False. However, the PipelineRun itself
is not marked as failed.

Signed-off-by: Dibyo Mukherjee <dibyo@google.com>
  • Loading branch information
dibyom committed Jul 24, 2019
1 parent 096dcd4 commit 30bc7a6
Show file tree
Hide file tree
Showing 13 changed files with 1,686 additions and 101 deletions.
77 changes: 77 additions & 0 deletions examples/pipelineruns/conditional-pipelinerun.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: tekton.dev/v1alpha1
kind: Condition
metadata:
name: always-true
spec:
check:
image: alpine
command: ["/bin/sh"]
args: ['-c', 'cat /workspace/prmetadata.json']
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: pipeline-git
spec:
type: git
params:
- name: revision
value: master
- name: url
value: https://github.com/tektoncd/pipeline
---
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: list-files
spec:
inputs:
resources:
- name: workspace
type: git
steps:
- name: run-ls
image: ubuntu
command: ["/bin/bash"]
args: ['-c', 'ls -al ${inputs.resources.workspace.path}']
---
apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
name: list-files-pipeline
spec:
resources:
- name: source-repo
type: git
tasks:
- name: list-files-0
taskRef:
name: list-files
resources:
inputs:
- name: workspace
resource: source-repo
- name: list-files-1
taskRef:
name: list-files
runAfter:
- list-files-0
conditions:
- conditionRef: "always-true"
resources:
inputs:
- name: workspace
resource: source-repo
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
name: demo-condtional-pr
spec:
pipelineRef:
name: list-files-pipeline
serviceAccount: 'default'
resources:
- name: source-repo
resourceRef:
name: pipeline-git
13 changes: 7 additions & 6 deletions pkg/apis/pipeline/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package pipeline

// GroupName is the Kubernetes resource group name for Pipeline types.
const (
GroupName = "tekton.dev"
TaskLabelKey = "/task"
TaskRunLabelKey = "/taskRun"
PipelineLabelKey = "/pipeline"
PipelineRunLabelKey = "/pipelineRun"
PipelineTaskLabelKey = "/pipelineTask"
GroupName = "tekton.dev"
TaskLabelKey = "/task"
TaskRunLabelKey = "/taskRun"
PipelineLabelKey = "/pipeline"
PipelineRunLabelKey = "/pipelineRun"
PipelineTaskLabelKey = "/pipelineTask"
PipelineRunConditionCheckKey = "/pipelineConditionCheck"
)
1 change: 1 addition & 0 deletions pkg/apis/pipeline/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

// Check that Task may be validated and defaulted.
var _ apis.Validatable = (*Condition)(nil)
//var _ apis.Defaultable = (*Condition)(nil)

// +genclient
// +genclient:noStatus
Expand Down
3 changes: 3 additions & 0 deletions pkg/reconciler/v1alpha1/pipelinerun/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/knative/pkg/tracker"
pipelineclient "github.com/tektoncd/pipeline/pkg/client/injection/client"
clustertaskinformer "github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1alpha1/clustertask"
conditioninformer "github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1alpha1/condition"
pipelineinformer "github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1alpha1/pipeline"
resourceinformer "github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1alpha1/pipelineresource"
pipelineruninformer "github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1alpha1/pipelinerun"
Expand Down Expand Up @@ -54,6 +55,7 @@ func NewController(
pipelineRunInformer := pipelineruninformer.Get(ctx)
pipelineInformer := pipelineinformer.Get(ctx)
resourceInformer := resourceinformer.Get(ctx)
conditionInformer := conditioninformer.Get(ctx)
timeoutHandler := reconciler.NewTimeoutHandler(ctx.Done(), logger)

opt := reconciler.Options{
Expand All @@ -72,6 +74,7 @@ func NewController(
clusterTaskLister: clusterTaskInformer.Lister(),
taskRunLister: taskRunInformer.Lister(),
resourceLister: resourceInformer.Lister(),
conditionLister: conditionInformer.Lister(),
timeoutHandler: timeoutHandler,
}
impl := controller.NewImpl(c, c.Logger, pipelineRunControllerName)
Expand Down
Loading

0 comments on commit 30bc7a6

Please sign in to comment.