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

When Expressions Status #3333

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions docs/pipelineruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ False|PipelineRunTimeout|Yes|The `PipelineRun` timed out.
When a `PipelineRun` changes status, [events](events.md#pipelineruns) are triggered accordingly.

When a `PipelineRun` has `Tasks` with [WhenExpressions](pipelines.md#guard-task-execution-using-whenexpressions):
- If the `WhenExpressions` evaluate to `true`, the `Task` is executed and the `TaskRun` will be listed in the `Task Runs` section of the `status` of the `PipelineRun`.
- If the `WhenExpressions` evaluate to `false`, the `Task` is skipped and it is listed in the `Skipped Tasks` section of the `status` of the `PipelineRun`.
- If the `WhenExpressions` evaluate to `true`, the `Task` is executed then the `TaskRun` and its resolved `WhenExpressions` will be listed in the `Task Runs` section of the `status` of the `PipelineRun`.
- If the `WhenExpressions` evaluate to `false`, the `Task` is skipped then its name and its resolved `WhenExpressions` will be listed in the `Skipped Tasks` section of the `status` of the `PipelineRun`.

```yaml
Conditions:
Expand All @@ -470,11 +470,25 @@ Conditions:
Type: Succeeded
Skipped Tasks:
Name: skip-this-task
When Expressions:
Input: foo
Operator: in
Values:
bar
Input: foo
Operator: notin
Values:
foo
Task Runs:
pipelinerun-to-skip-task-run-this-task-r2djj:
Pipeline Task Name: run-this-task
Status:
...
When Expressions:
Input: foo
Operator: in
Values:
foo
```

## Cancelling a `PipelineRun`
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ type PipelineRunStatusFields struct {
type SkippedTask struct {
// Name is the Pipeline Task name
Name string `json:"name"`
// WhenExpressions is the list of checks guarding the execution of the PipelineTask
// +optional
WhenExpressions []WhenExpression `json:"whenExpressions,omitempty"`
}

// PipelineRunResult used to describe the results of a pipeline
Expand All @@ -363,6 +366,9 @@ type PipelineRunTaskRunStatus struct {
// ConditionChecks maps the name of a condition check to its Status
// +optional
ConditionChecks map[string]*PipelineRunConditionCheckStatus `json:"conditionChecks,omitempty"`
// WhenExpressions is the list of checks guarding the execution of the PipelineTask
// +optional
WhenExpressions []WhenExpression `json:"whenExpressions,omitempty"`
}

// PipelineRunConditionCheckStatus returns the condition check status
Expand Down
18 changes: 17 additions & 1 deletion pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 50 additions & 2 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,12 @@ func TestUpdateTaskRunsState(t *testing.T) {
// from a TaskRun associated to the PipelineRun
pr := tb.PipelineRun("test-pipeline-run", tb.PipelineRunNamespace("foo"), tb.PipelineRunSpec("test-pipeline"))
pipelineTask := v1beta1.PipelineTask{
Name: "unit-test-1",
Name: "unit-test-1",
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
TaskRef: &v1beta1.TaskRef{Name: "unit-test-task"},
}
task := tb.Task("unit-test-task", tb.TaskSpec(
Expand Down Expand Up @@ -792,6 +797,11 @@ func TestUpdateTaskRunsState(t *testing.T) {
Conditions: []apis.Condition{{Type: apis.ConditionSucceeded}},
},
},
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
}
expectedPipelineRunStatus := v1beta1.PipelineRunStatus{
PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
Expand All @@ -809,7 +819,7 @@ func TestUpdateTaskRunsState(t *testing.T) {
}}
pr.Status.InitializeConditions()
status := state.GetTaskRunsStatus(pr)
if d := cmp.Diff(status, expectedPipelineRunStatus.TaskRuns); d != "" {
if d := cmp.Diff(expectedPipelineRunStatus.TaskRuns, status); d != "" {
t.Fatalf("Expected PipelineRun status to match TaskRun(s) status, but got a mismatch: %s", diff.PrintWantGot(d))
}

Expand Down Expand Up @@ -2076,9 +2086,28 @@ func TestReconcileWithWhenExpressionsWithParameters(t *testing.T) {
t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRunName, diff.PrintWantGot(d))
}

actualWhenExpressionsInTaskRun := pipelineRun.Status.PipelineRunStatusFields.TaskRuns[expectedTaskRunName].WhenExpressions
expectedWhenExpressionsInTaskRun := []v1beta1.WhenExpression{{
Input: "foo",
Operator: "notin",
Values: []string{"bar"},
}, {
Input: "yes",
Operator: "in",
Values: []string{"yes"},
}}
if d := cmp.Diff(expectedWhenExpressionsInTaskRun, actualWhenExpressionsInTaskRun); d != "" {
t.Errorf("expected to see When Expressions %v created. Diff %s", expectedTaskRunName, diff.PrintWantGot(d))
}

actualSkippedTasks := pipelineRun.Status.SkippedTasks
expectedSkippedTasks := []v1beta1.SkippedTask{{
Name: "hello-world-2",
WhenExpressions: v1beta1.WhenExpressions{{
Input: "yes",
Operator: "notin",
Values: []string{"yes"},
}},
}}
if d := cmp.Diff(actualSkippedTasks, expectedSkippedTasks); d != "" {
t.Errorf("expected to find Skipped Tasks %v. Diff %s", expectedSkippedTasks, diff.PrintWantGot(d))
Expand Down Expand Up @@ -2197,9 +2226,28 @@ func TestReconcileWithWhenExpressionsWithTaskResults(t *testing.T) {
t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRunName, diff.PrintWantGot(d))
}

actualWhenExpressionsInTaskRun := pipelineRun.Status.PipelineRunStatusFields.TaskRuns[expectedTaskRunName].WhenExpressions
expectedWhenExpressionsInTaskRun := []v1beta1.WhenExpression{{
Input: "aResultValue",
Operator: "in",
Values: []string{"aResultValue"},
}, {
Input: "aResultValue",
Operator: "in",
Values: []string{"aResultValue"},
}}
if d := cmp.Diff(expectedWhenExpressionsInTaskRun, actualWhenExpressionsInTaskRun); d != "" {
t.Errorf("expected to see When Expressions %v created. Diff %s", expectedTaskRunName, diff.PrintWantGot(d))
}

actualSkippedTasks := pipelineRun.Status.SkippedTasks
expectedSkippedTasks := []v1beta1.SkippedTask{{
Name: "c-task",
WhenExpressions: v1beta1.WhenExpressions{{
Input: "aResultValue",
Operator: "in",
Values: []string{"missing"},
}},
}, {
Name: "d-task",
}}
Expand Down
9 changes: 7 additions & 2 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (state PipelineRunState) GetTaskRunsStatus(pr *v1beta1.PipelineRun) map[str
if prtrs == nil {
prtrs = &v1beta1.PipelineRunTaskRunStatus{
PipelineTaskName: rprt.PipelineTask.Name,
WhenExpressions: rprt.PipelineTask.WhenExpressions,
}
}

Expand Down Expand Up @@ -281,10 +282,14 @@ func (facts *PipelineRunFacts) GetPipelineConditionStatus(pr *v1beta1.PipelineRu
}

func (facts *PipelineRunFacts) GetSkippedTasks() []v1beta1.SkippedTask {
skipped := []v1beta1.SkippedTask{}
var skipped []v1beta1.SkippedTask
for _, rprt := range facts.State {
if rprt.Skip(facts) {
skipped = append(skipped, v1beta1.SkippedTask{Name: rprt.PipelineTask.Name})
skippedTask := v1beta1.SkippedTask{
Name: rprt.PipelineTask.Name,
WhenExpressions: rprt.PipelineTask.WhenExpressions,
}
skipped = append(skipped, skippedTask)
}
}
return skipped
Expand Down