Skip to content

Commit 52a30a3

Browse files
committed
feat(taskspec): create Status.Steps even without StepActions
With this change, TaskRun.Status.Steps are now populated even when there is only inline steps defined.
1 parent 6290b16 commit 52a30a3

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

pkg/reconciler/taskrun/resources/taskspec.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,24 @@ func updateTaskRunProvenance(taskRun *v1.TaskRun, stepName string, stepIndex int
197197

198198
// GetStepActionsData extracts the StepActions and merges them with the inlined Step specification.
199199
func GetStepActionsData(ctx context.Context, taskSpec v1.TaskSpec, taskRun *v1.TaskRun, tekton clientset.Interface, k8s kubernetes.Interface, requester remoteresource.Requester) ([]v1.Step, error) {
200-
// If there are no step-ref to resolve, return immediately
200+
steps := make([]v1.Step, len(taskSpec.Steps))
201+
202+
// Init step states and known step states indexes lookup map
203+
if taskRun.Status.Steps == nil {
204+
taskRun.Status.Steps = []v1.StepState{}
205+
}
206+
stepStatusIndex := make(map[string]int, len(taskRun.Status.Steps))
207+
for i, stepState := range taskRun.Status.Steps {
208+
stepStatusIndex[stepState.Name] = i
209+
}
210+
211+
// If there are no step-ref to resolve, return immediately with nil provenance
201212
if !hasStepRefs(&taskSpec) {
202-
return taskSpec.Steps, nil
213+
for i, step := range taskSpec.Steps {
214+
steps[i] = step
215+
updateTaskRunProvenance(taskRun, step.Name, i, nil, stepStatusIndex) // create StepState with nil provenance
216+
}
217+
return steps, nil
203218
}
204219

205220
// Phase 1: Concurrently resolve all StepActions
@@ -229,15 +244,6 @@ func GetStepActionsData(ctx context.Context, taskSpec v1.TaskSpec, taskRun *v1.T
229244
}
230245

231246
// Phase 2: Sequentially merge results into the final step list and update status
232-
if taskRun.Status.Steps == nil {
233-
taskRun.Status.Steps = []v1.StepState{}
234-
}
235-
stepStatusIndex := make(map[string]int, len(taskRun.Status.Steps))
236-
for i, stepState := range taskRun.Status.Steps {
237-
stepStatusIndex[stepState.Name] = i
238-
}
239-
240-
steps := make([]v1.Step, len(taskSpec.Steps))
241247
for i, step := range taskSpec.Steps {
242248
if step.Ref == nil {
243249
steps[i] = step

pkg/reconciler/taskrun/resources/taskspec_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,8 @@ spec:
737737
Status: v1.TaskRunStatus{
738738
TaskRunStatusFields: v1.TaskRunStatusFields{
739739
Steps: []v1.StepState{{
740-
Name: "step1",
740+
Name: "step1",
741+
Provenance: &v1.Provenance{},
741742
}},
742743
},
743744
},
@@ -804,7 +805,20 @@ spec:
804805
},
805806
},
806807
},
807-
want: v1.TaskRunStatus{},
808+
want: v1.TaskRunStatus{
809+
TaskRunStatusFields: v1.TaskRunStatusFields{
810+
Steps: []v1.StepState{
811+
{
812+
Name: "first-inline",
813+
Provenance: &v1.Provenance{},
814+
},
815+
{
816+
Name: "second-inline",
817+
Provenance: &v1.Provenance{},
818+
},
819+
},
820+
},
821+
},
808822
}, {
809823
name: "StepAction only",
810824
tr: &v1.TaskRun{

0 commit comments

Comments
 (0)