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

validate TaskRun retries in TestRunSpec is greater than or equal to zero #7836

Merged
merged 1 commit into from
Apr 10, 2024
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
4 changes: 3 additions & 1 deletion pkg/apis/pipeline/v1/taskrun_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func (ts *TaskRunSpec) Validate(ctx context.Context) (errs *apis.FieldError) {
errs = errs.Also(apis.ErrInvalidValue(fmt.Sprintf("statusMessage should not be set if status is not set, but it is currently set to %s", ts.StatusMessage), "statusMessage"))
}
}

if ts.Retries < 0 {
errs = errs.Also(apis.ErrInvalidValue(fmt.Sprintf("%d should be >= 0", ts.Retries), "retries"))
}
if ts.Timeout != nil {
// timeout should be a valid duration of at least 0.
if ts.Timeout.Duration < 0 {
Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/pipeline/v1/taskrun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,15 @@ func TestTaskRunSpec_Invalidate(t *testing.T) {
Timeout: &metav1.Duration{Duration: -48 * time.Hour},
},
wantErr: apis.ErrInvalidValue("-48h0m0s should be >= 0", "timeout"),
}, {
name: "negative pipeline retries",
spec: v1.TaskRunSpec{
TaskRef: &v1.TaskRef{
Name: "taskrefname",
},
Retries: -3,
},
wantErr: apis.ErrInvalidValue("-3 should be >= 0", "retries"),
}, {
name: "wrong taskrun cancel",
spec: v1.TaskRunSpec{
Expand Down Expand Up @@ -828,6 +837,18 @@ func TestTaskRunSpec_Validate(t *testing.T) {
}},
},
},
}, {
name: "with positive retries",
spec: v1.TaskRunSpec{
Timeout: &metav1.Duration{Duration: 0},
Retries: 3,
TaskSpec: &v1.TaskSpec{
Steps: []v1.Step{{
Name: "mystep",
Image: "myimage",
}},
},
},
}, {
name: "parameters",
spec: v1.TaskRunSpec{
Expand Down