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

Replace PipelineRunReasonFailedValidation with more granular reasons #7417

Merged
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
5 changes: 5 additions & 0 deletions docs/pipeline-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,11 @@ all of the running TaskRuns as cancelled failed.</p>
<td><p>ReasonCouldntGetPipeline indicates that the reason for the failure status is that the
associated Pipeline couldn&rsquo;t be retrieved</p>
</td>
</tr><tr><td><p>&#34;CouldntGetPipelineResult&#34;</p></td>
<td><p>PipelineRunReasonCouldntGetPipelineResult indicates that the pipeline fails to retrieve the
referenced result. This could be due to failed TaskRuns or Runs that were supposed to produce
the results</p>
</td>
</tr><tr><td><p>&#34;CouldntGetTask&#34;</p></td>
<td><p>ReasonCouldntGetTask indicates that the reason for the failure status is that the
associated Pipeline&rsquo;s Tasks couldn&rsquo;t all be retrieved</p>
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ const (
// ReasonFailedValidation indicates that the reason for failure status is
// that pipelinerun failed runtime validation
PipelineRunReasonFailedValidation PipelineRunReason = "PipelineValidationFailed"
// PipelineRunReasonCouldntGetPipelineResult indicates that the pipeline fails to retrieve the
// referenced result. This could be due to failed TaskRuns or Runs that were supposed to produce
// the results
PipelineRunReasonCouldntGetPipelineResult PipelineRunReason = "CouldntGetPipelineResult"
// ReasonInvalidGraph indicates that the reason for the failure status is that the
// associated Pipeline is an invalid graph (a.k.a wrong order, cycle, …)
PipelineRunReasonInvalidGraph PipelineRunReason = "PipelineInvalidGraph"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1.PipelineRun, getPipel
pr.Status.Results, err = resources.ApplyTaskResultsToPipelineResults(ctx, pipelineSpec.Results,
pipelineRunFacts.State.GetTaskRunsResults(), pipelineRunFacts.State.GetRunsResults(), pipelineRunFacts.GetPipelineTaskStatus())
if err != nil {
pr.Status.MarkFailed(v1.PipelineRunReasonFailedValidation.String(), err.Error())
pr.Status.MarkFailed(v1.PipelineRunReasonCouldntGetPipelineResult.String(), err.Error())
return err
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/reconciler/pipelinerun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func ApplyTaskResultsToPipelineResults(
}
variableParts := strings.Split(variable, ".")

if (variableParts[0] != v1beta1.ResultTaskPart && variableParts[0] != v1beta1.ResultFinallyPart) || variableParts[2] != v1beta1.ResultResultPart {
if (variableParts[0] != v1.ResultTaskPart && variableParts[0] != v1.ResultFinallyPart) || variableParts[2] != v1beta1.ResultResultPart {
validPipelineResult = false
invalidPipelineResults = append(invalidPipelineResults, pipelineResult.Name)
continue
Expand Down Expand Up @@ -470,7 +470,7 @@ func ApplyTaskResultsToPipelineResults(
} else {
// if the task is not successful (e.g. skipped or failed) and the results is missing, don't return error
if status, ok := taskstatus[PipelineTaskStatusPrefix+taskName+PipelineTaskStatusSuffix]; ok {
if status != v1beta1.TaskRunReasonSuccessful.String() {
if status != v1.TaskRunReasonSuccessful.String() {
validPipelineResult = false
continue
}
Expand All @@ -494,7 +494,7 @@ func ApplyTaskResultsToPipelineResults(
} else {
// if the task is not successful (e.g. skipped or failed) and the results is missing, don't return error
if status, ok := taskstatus[PipelineTaskStatusPrefix+taskName+PipelineTaskStatusSuffix]; ok {
if status != v1beta1.TaskRunReasonSuccessful.String() {
if status != v1.TaskRunReasonSuccessful.String() {
validPipelineResult = false
continue
}
Expand All @@ -519,7 +519,7 @@ func ApplyTaskResultsToPipelineResults(
}

if len(invalidPipelineResults) > 0 {
return runResults, fmt.Errorf("invalid pipelineresults %v, the referred results don't exist", invalidPipelineResults)
return runResults, fmt.Errorf("invalid pipelineresults %v, the referenced results don't exist", invalidPipelineResults)
}

return runResults, nil
Expand Down
28 changes: 14 additions & 14 deletions pkg/reconciler/pipelinerun/resources/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4083,7 +4083,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
},
},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [pipeline-result-1], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [pipeline-result-1], the referenced results don't exist"),
}, {
description: "object-reference-key-not-exist",
results: []v1.PipelineResult{{
Expand All @@ -4102,7 +4102,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
},
},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [pipeline-result-1], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [pipeline-result-1], the referenced results don't exist"),
}, {
description: "object-results-resultname-not-exist",
results: []v1.PipelineResult{{
Expand All @@ -4121,7 +4121,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
},
},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [pipeline-result-1], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [pipeline-result-1], the referenced results don't exist"),
}, {
description: "invalid-result-variable-no-returned-result",
results: []v1.PipelineResult{{
Expand All @@ -4135,7 +4135,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
}},
},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referenced results don't exist"),
}, {
description: "no-taskrun-results-no-returned-results",
results: []v1.PipelineResult{{
Expand All @@ -4146,7 +4146,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
"pt1": {},
},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referenced results don't exist"),
}, {
description: "invalid-taskrun-name-no-returned-result",
results: []v1.PipelineResult{{
Expand All @@ -4160,7 +4160,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
}},
},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referenced results don't exist"),
}, {
description: "invalid-result-name-no-returned-result",
results: []v1.PipelineResult{{
Expand All @@ -4174,7 +4174,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
}},
},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referenced results don't exist"),
}, {
description: "unsuccessful-taskrun-no-returned-result",
results: []v1.PipelineResult{{
Expand All @@ -4183,7 +4183,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
}},
taskResults: map[string][]v1.TaskRunResult{},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referenced results don't exist"),
}, {
description: "mixed-success-tasks-some-returned-results",
results: []v1.PipelineResult{{
Expand All @@ -4203,7 +4203,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
Name: "bar",
Value: *v1.NewStructuredValues("rae"),
}},
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referenced results don't exist"),
}, {
description: "no-run-results-no-returned-results",
results: []v1.PipelineResult{{
Expand All @@ -4212,7 +4212,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
}},
runResults: map[string][]v1beta1.CustomRunResult{},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referenced results don't exist"),
}, {
description: "wrong-customtask-name-no-returned-result",
results: []v1.PipelineResult{{
Expand All @@ -4226,7 +4226,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
}},
},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referenced results don't exist"),
}, {
description: "right-customtask-name-wrong-result-name-no-returned-result",
results: []v1.PipelineResult{{
Expand All @@ -4240,7 +4240,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
}},
},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referenced results don't exist"),
}, {
description: "unsuccessful-run-no-returned-result",
results: []v1.PipelineResult{{
Expand All @@ -4251,7 +4251,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
"customtask": {},
},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referenced results don't exist"),
}, {
description: "wrong-result-reference-expression",
results: []v1.PipelineResult{{
Expand All @@ -4262,7 +4262,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) {
"customtask": {},
},
expectedResults: nil,
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referred results don't exist"),
expectedError: fmt.Errorf("invalid pipelineresults [foo], the referenced results don't exist"),
}} {
t.Run(tc.description, func(t *testing.T) {
received, err := resources.ApplyTaskResultsToPipelineResults(context.Background(), tc.results, tc.taskResults, tc.runResults, nil /*skipped tasks*/)
Expand Down
Loading