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 GetChildReferences #5006

Merged
merged 1 commit into from
Jun 21, 2022
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
3 changes: 1 addition & 2 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun, get
}

if cfg.FeatureFlags.EmbeddedStatus == config.MinimalEmbeddedStatus || cfg.FeatureFlags.EmbeddedStatus == config.BothEmbeddedStatus {
pr.Status.ChildReferences = pipelineRunFacts.State.GetChildReferences(v1beta1.SchemeGroupVersion.String(),
v1alpha1.SchemeGroupVersion.String())
pr.Status.ChildReferences = pipelineRunFacts.State.GetChildReferences()
}

pr.Status.SkippedTasks = pipelineRunFacts.GetSkippedTasks()
Expand Down
27 changes: 10 additions & 17 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,27 +238,24 @@ func (state PipelineRunState) GetRunsResults() map[string][]v1alpha1.RunResult {

// GetChildReferences returns a slice of references, including version, kind, name, and pipeline task name, for all
// TaskRuns and Runs in the state.
func (state PipelineRunState) GetChildReferences(taskRunVersion string, runVersion string) []v1beta1.ChildStatusReference {
func (state PipelineRunState) GetChildReferences() []v1beta1.ChildStatusReference {
var childRefs []v1beta1.ChildStatusReference

for _, rprt := range state {
if rprt.CustomTask {
childRefs = append(childRefs, rprt.getChildRefForRun(runVersion))
} else if rprt.TaskRun != nil {
childRefs = append(childRefs, rprt.getChildRefForTaskRun(taskRunVersion))
switch {
case rprt.Run != nil:
Copy link
Contributor

Choose a reason for hiding this comment

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

So I didn't think about this on first glance, but now I'm remembering that, in fact, we should be adding a ChildReference for a PipelineTask with nil Run and nil TaskRun if that PipelineTask has WhenExpressions - that is, if the WhenExpressions result in the corresponding Run or TaskRun never getting created, the PipelineTask, with the WhenExpressions, should still be in ChildReferences.

Copy link
Member Author

@jerop jerop Jun 21, 2022

Choose a reason for hiding this comment

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

@abayer we do not create a Run or TaskRun when a PipelineTask is skipped, and "nil" Run or TaskRun should not be added to the PipelineRun status - https://github.com/tektoncd/community/blob/main/teps/0007-conditions-beta.md#status-1

The WhenExpressions for skipped PipelineTasks are in the SkippedTasks section of the PipelineRun status - they should not be in ChildReferences

Copy link
Contributor

Choose a reason for hiding this comment

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

Aaah, then we should probably remove the WhenExpressions from ChildStatusReference. =)

Copy link
Member Author

Choose a reason for hiding this comment

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

If I remember correctly, the reason we added WhenExpressions to ChildStatusReference is for convenience for users to see the resolved WhenExpressions that evaluated to True and led to the execution of the PipelineTask - open to removing them if users don't find them to be useful (cc @pritidesai)

childRefs = append(childRefs, rprt.getChildRefForRun())
case rprt.TaskRun != nil:
childRefs = append(childRefs, rprt.getChildRefForTaskRun())
}
}
return childRefs
}

func (rprt *ResolvedPipelineRunTask) getChildRefForRun(runVersion string) v1beta1.ChildStatusReference {
if rprt.Run != nil {
runVersion = rprt.Run.APIVersion
}

func (rprt *ResolvedPipelineRunTask) getChildRefForRun() v1beta1.ChildStatusReference {
return v1beta1.ChildStatusReference{
TypeMeta: runtime.TypeMeta{
APIVersion: runVersion,
APIVersion: rprt.Run.APIVersion,
Kind: pipeline.RunControllerName,
},
Name: rprt.RunName,
Expand All @@ -267,14 +264,10 @@ func (rprt *ResolvedPipelineRunTask) getChildRefForRun(runVersion string) v1beta
}
}

func (rprt *ResolvedPipelineRunTask) getChildRefForTaskRun(taskRunVersion string) v1beta1.ChildStatusReference {
if rprt.TaskRun != nil {
taskRunVersion = rprt.TaskRun.APIVersion
}

func (rprt *ResolvedPipelineRunTask) getChildRefForTaskRun() v1beta1.ChildStatusReference {
return v1beta1.ChildStatusReference{
TypeMeta: runtime.TypeMeta{
APIVersion: taskRunVersion,
APIVersion: rprt.TaskRun.APIVersion,
Kind: pipeline.TaskRunControllerName,
},
Name: rprt.TaskRunName,
Expand Down
11 changes: 2 additions & 9 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2442,14 +2442,7 @@ func TestPipelineRunState_GetChildReferences(t *testing.T) {
},
},
}},
childRefs: []v1beta1.ChildStatusReference{{
TypeMeta: runtime.TypeMeta{
APIVersion: "tekton.dev/v1alpha1",
Kind: "Run",
},
Name: "unresolved-custom-task-run",
PipelineTaskName: "unresolved-custom-task-1",
}},
childRefs: nil,
},
{
name: "single-task",
Expand Down Expand Up @@ -2576,7 +2569,7 @@ func TestPipelineRunState_GetChildReferences(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
childRefs := tc.state.GetChildReferences(v1beta1.SchemeGroupVersion.String(), v1alpha1.SchemeGroupVersion.String())
childRefs := tc.state.GetChildReferences()
if d := cmp.Diff(tc.childRefs, childRefs); d != "" {
t.Errorf("Didn't get expected child references for %s: %s", tc.name, diff.PrintWantGot(d))
}
Expand Down