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

Unscheduled Runs shouldn't be included in full status #5287

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
91 changes: 91 additions & 0 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10004,3 +10004,94 @@ spec:
})
}
}

func TestReconcile_CancelUnscheduled(t *testing.T) {
testCases := []struct {
name string
embeddedStatusVal string
}{
{
name: "default embedded status",
embeddedStatusVal: config.DefaultEmbeddedStatus,
},
{
name: "full embedded status",
embeddedStatusVal: config.FullEmbeddedStatus,
},
{
name: "both embedded status",
embeddedStatusVal: config.BothEmbeddedStatus,
},
{
name: "minimal embedded status",
embeddedStatusVal: config.MinimalEmbeddedStatus,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
pipelineRunName := "cancel-test-run"
prs := []*v1beta1.PipelineRun{parse.MustParsePipelineRun(t, `metadata:
name: cancel-test-run
namespace: foo
spec:
pipelineSpec:
tasks:
- name: wait-1
taskSpec:
apiVersion: example.dev/v0
kind: Wait
params:
- name: duration
value: 1h
- name: wait-2
runAfter:
- wait-1
taskSpec:
apiVersion: example.dev/v0
kind: Wait
params:
- name: duration
value: 10s
- name: wait-3
runAfter:
- wait-1
taskRef:
name: hello-world
`)}

ts := []*v1beta1.Task{simpleHelloWorldTask}

cms := []*corev1.ConfigMap{withEmbeddedStatus(withCustomTasks(newFeatureFlagsConfigMap()), tc.embeddedStatusVal)}

d := test.Data{
PipelineRuns: prs,
Tasks: ts,
ConfigMaps: cms,
}
prt := newPipelineRunTest(d, t)
defer prt.Cancel()

pr, clients := prt.reconcileRun("foo", pipelineRunName, []string{}, false)

if tc.embeddedStatusVal != config.MinimalEmbeddedStatus {
if len(pr.Status.Runs) > 1 {
t.Errorf("Expected one Run in status, but found %d", len(pr.Status.Runs))
}
if len(pr.Status.TaskRuns) > 0 {
t.Errorf("Expected no TaskRuns in status, but found %d", len(pr.Status.TaskRuns))
}
}
if tc.embeddedStatusVal != config.FullEmbeddedStatus {
if len(pr.Status.ChildReferences) > 1 {
t.Errorf("Expected one Run or TaskRun in child references, but found %d", len(pr.Status.ChildReferences))
}
}

err := cancelPipelineRun(prt.TestAssets.Ctx, logtesting.TestLogger(t), pr, clients.Pipeline)
if err != nil {
t.Fatalf("Error found: %v", err)
}
})
}
}
12 changes: 5 additions & 7 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,19 @@ func (state PipelineRunState) GetRunsStatus(pr *v1beta1.PipelineRun) map[string]
continue
}

var prrs *v1beta1.PipelineRunRunStatus
if rpt.Run != nil {
prrs = pr.Status.Runs[rpt.RunName]
if rpt.Run == nil {
continue
}

prrs := pr.Status.Runs[rpt.RunName]

if prrs == nil {
prrs = &v1beta1.PipelineRunRunStatus{
PipelineTaskName: rpt.PipelineTask.Name,
WhenExpressions: rpt.PipelineTask.WhenExpressions,
}
}

if rpt.Run != nil {
prrs.Status = &rpt.Run.Status
}
prrs.Status = &rpt.Run.Status

status[rpt.RunName] = prrs
}
Expand Down
32 changes: 32 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2381,6 +2381,15 @@ spec:
}},
TaskRef: &v1beta1.TaskRef{Name: "unit-test-task"},
}
unscheduledPipelineTask := v1beta1.PipelineTask{
Name: "unit-test-2",
WhenExpressions: []v1beta1.WhenExpression{{
Copy link
Member

Choose a reason for hiding this comment

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

What is the significance of whenExpression in the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

None - I just copy-pasted the task above.

Copy link
Member

Choose a reason for hiding this comment

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

will be great to avoid such copy/paste specially given that it does not bring any value to the test, thanks 🙏

Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
TaskRef: &v1beta1.TaskRef{Name: "unit-test-task"},
}

task := parse.MustParseTask(t, fmt.Sprintf(`
metadata:
Expand Down Expand Up @@ -2418,6 +2427,12 @@ status:
ResolvedTaskResources: &resources.ResolvedTaskResources{
TaskSpec: &task.Spec,
},
}, {
PipelineTask: &unscheduledPipelineTask,
TaskRunName: "test-pipeline-run-success-unit-test-2",
ResolvedTaskResources: &resources.ResolvedTaskResources{
TaskSpec: &task.Spec,
},
}}
pr.Status.InitializeConditions(testClock)
status := state.GetTaskRunsStatus(pr)
Expand Down Expand Up @@ -2473,6 +2488,19 @@ spec:
Name: "unit-test-run",
},
}
unscheduledPipelineTask := v1beta1.PipelineTask{
Name: "unit-test-2",
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
TaskRef: &v1beta1.TaskRef{
APIVersion: "example.dev/v0",
Kind: "Example",
Name: "unit-test-run",
},
}

run := parse.MustParseRun(t, fmt.Sprintf(`
metadata:
Expand All @@ -2489,6 +2517,10 @@ status:
CustomTask: true,
RunName: "test-pipeline-run-success-unit-test-1",
Run: run,
}, {
PipelineTask: &unscheduledPipelineTask,
CustomTask: true,
RunName: "test-pipeline-run-success-unit-test-2",
}}
pr.Status.InitializeConditions(testClock)
status := state.GetRunsStatus(pr)
Expand Down