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

Controlling max parallel jobs per pipeline[WIP] #3112

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ type PipelineRunSpec struct {
// TaskRunSpecs holds a set of runtime specs
// +optional
TaskRunSpecs []PipelineTaskRunSpec `json:"taskRunSpecs,omitempty"`
// MaxParallel holds the nbr of parallel task that can run for a specific pipeline
// +optional
MaxParallel int `json:"maxParallel,omitempty"`
}

// PipelineRunSpecStatus defines the pipelinerun spec status the user can provide
Expand Down
18 changes: 15 additions & 3 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,22 @@ func (c *Reconciler) runNextSchedulableTask(ctx context.Context, pr *v1beta1.Pip
continue
}
if rprt.ResolvedConditionChecks == nil || rprt.ResolvedConditionChecks.IsSuccess() {
rprt.TaskRun, err = c.createTaskRun(ctx, rprt, pr, as.StorageBasePath(pr))
tasks, err := c.taskRunLister.List(labels.SelectorFromSet(pr.Labels)) // https://github.com/tektoncd/pipeline/blob/master/docs/labels.md
if err != nil {
recorder.Eventf(pr, corev1.EventTypeWarning, "TaskRunCreationFailed", "Failed to create TaskRun %q: %v", rprt.TaskRunName, err)
return fmt.Errorf("error creating TaskRun called %s for PipelineTask %s from PipelineRun %s: %w", rprt.TaskRunName, rprt.PipelineTask.Name, pr.Name, err)
return fmt.Errorf("error creating task list for PipelineTask %s from PipelineRun %s: %w", rprt.PipelineTask.Name, pr.Name, err)
}
var countRunningTasks int = 0
for _, task := range tasks {
if task.Status.Conditions != nil && task.Status.Conditions[0].Reason == "Running" { // https://github.com/tektoncd/pipeline/blob/master/docs/taskruns.md#monitoring-steps
countRunningTasks++
}
}
if countRunningTasks > pr.Spec.MaxParallel || pr.Spec.PipelineSpec == nil {
rprt.TaskRun, err = c.createTaskRun(ctx, rprt, pr, as.StorageBasePath(pr))
if err != nil {
recorder.Eventf(pr, corev1.EventTypeWarning, "TaskRunCreationFailed", "Failed to create TaskRun %q: %v", rprt.TaskRunName, err)
return fmt.Errorf("error creating TaskRun called %s for PipelineTask %s from PipelineRun %s: %w", rprt.TaskRunName, rprt.PipelineTask.Name, pr.Name, err)
}
}
} else if !rprt.ResolvedConditionChecks.HasStarted() {
for _, rcc := range rprt.ResolvedConditionChecks {
Expand Down