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 #5294

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
91 changes: 91 additions & 0 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7749,3 +7749,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 @@ -198,21 +198,19 @@ func (state PipelineRunState) GetRunsStatus(pr *v1beta1.PipelineRun) map[string]
continue
}

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

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

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

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

status[rprt.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 @@ -2067,6 +2067,15 @@ spec:
}},
TaskRef: &v1beta1.TaskRef{Name: "unit-test-task"},
}
unscheduledPipelineTask := v1beta1.PipelineTask{
Name: "unit-test-2",
WhenExpressions: []v1beta1.WhenExpression{{
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 @@ -2104,6 +2113,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 @@ -2159,6 +2174,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 @@ -2175,6 +2203,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