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

TEP-0090: Refactor ResolvePipelineRunTask #4938

Merged
Merged
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
72 changes: 40 additions & 32 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,6 @@ func ResolvePipelineRunTask(
} else {
rprt.TaskRunName = GetTaskRunName(pipelineRun.Status.TaskRuns, pipelineRun.Status.ChildReferences, task.Name, pipelineRun.Name)

// Find the Task that this PipelineTask is using
var (
t v1beta1.TaskObject
err error
spec v1beta1.TaskSpec
taskName string
kind v1beta1.TaskKind
)

taskRun, err := getTaskRun(rprt.TaskRunName)
if err != nil {
if !kerrors.IsNotFound(err) {
Expand All @@ -509,30 +500,12 @@ func ResolvePipelineRunTask(
rprt.TaskRun = taskRun
}

if task.TaskRef != nil {
// If the TaskRun has already a store TaskSpec in its status, use it as source of truth
if taskRun != nil && taskRun.Status.TaskSpec != nil {
spec = *taskRun.Status.TaskSpec
taskName = task.TaskRef.Name
} else {
t, err = getTask(ctx, task.TaskRef.Name)
switch {
case errors.Is(err, remote.ErrorRequestInProgress):
return nil, err
case err != nil:
return nil, &TaskNotFoundError{
Name: task.TaskRef.Name,
Msg: err.Error(),
}
default:
spec = t.TaskSpec()
taskName = t.TaskMetadata().Name
}
}
kind = task.TaskRef.Kind
} else {
spec = task.TaskSpec.TaskSpec
// Find the Task that this PipelineTask is using
spec, taskName, kind, err := resolveTask(ctx, taskRun, getTask, task)
if err != nil {
return nil, err
}

spec.SetDefaults(ctx)
rtr, err := resolvePipelineTaskResources(task, &spec, taskName, kind, providedResources)
if err != nil {
Expand All @@ -553,6 +526,41 @@ func ResolvePipelineRunTask(
return &rprt, nil
}

func resolveTask(ctx context.Context, taskRun *v1beta1.TaskRun, getTask resources.GetTask, task v1beta1.PipelineTask) (v1beta1.TaskSpec, string, v1beta1.TaskKind, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @jerop for refactoring 🙏

not a blocker (its merged already 🤣) or the intent is not to demotivate but its always great to have a unit test for any new function introduced. We are carrying a lot of such functions without any unit tests since long time back.

var (
t v1beta1.TaskObject
err error
spec v1beta1.TaskSpec
taskName string
kind v1beta1.TaskKind
)
if task.TaskRef != nil {
// If the TaskRun has already a stored TaskSpec in its status, use it as source of truth
if taskRun != nil && taskRun.Status.TaskSpec != nil {
spec = *taskRun.Status.TaskSpec
taskName = task.TaskRef.Name
} else {
t, err = getTask(ctx, task.TaskRef.Name)
switch {
case errors.Is(err, remote.ErrorRequestInProgress):
return v1beta1.TaskSpec{}, "", "", err
case err != nil:
return v1beta1.TaskSpec{}, "", "", &TaskNotFoundError{
Name: task.TaskRef.Name,
Msg: err.Error(),
}
default:
spec = t.TaskSpec()
taskName = t.TaskMetadata().Name
}
}
kind = task.TaskRef.Kind
} else {
spec = task.TaskSpec.TaskSpec
}
return spec, taskName, kind, err
}

// getConditionCheckName should return a unique name for a `ConditionCheck` if one has not already been defined, and the existing one otherwise.
func getConditionCheckName(taskRunStatus map[string]*v1beta1.PipelineRunTaskRunStatus, childRefs []v1beta1.ChildStatusReference, trName, conditionRegisterName string) string {
for _, cr := range childRefs {
Expand Down