Skip to content

Commit 34b8084

Browse files
committed
Adds container name to taskrun.status.steps
Recently while introducing some minor changes in steps status details, it broked some functionality across CLI, Dashboard and other projects integration. Maybe because those integration tries to extract some attributes related to the pod base on TaskRun.Status fields i.e extracting the container name from step's name for fetching the logs for TaskRun.Status.Steps. In order to fix the issue, thi patch adds container name in step's status. So that consumer of status api dont need figure internal details bsed on steps details. Fixes #1027
1 parent 3409f09 commit 34b8084

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

pkg/apis/pipeline/v1alpha1/taskrun_types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ func (tr *TaskRunStatus) InitializeCloudEvents(targets []string) {
194194
// StepState reports the results of running a step in the Task.
195195
type StepState struct {
196196
corev1.ContainerState
197-
Name string `json:"name,omitempty"`
197+
Name string `json:"name,omitempty"`
198+
ContainerName string `json:"container,omitempty"`
198199
}
199200

200201
// CloudEventDelivery is the target of a cloud event along with the state of

pkg/status/taskrunpod.go

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func UpdateStatusFromPod(taskRun *v1alpha1.TaskRun, pod *corev1.Pod, resourceLis
3636
taskRun.Status.Steps = append(taskRun.Status.Steps, v1alpha1.StepState{
3737
ContainerState: *s.State.DeepCopy(),
3838
Name: resources.TrimContainerNamePrefix(s.Name),
39+
ContainerName: s.Name,
3940
})
4041
}
4142
}

pkg/status/taskrunpod_test.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
7777
Terminated: &corev1.ContainerStateTerminated{
7878
ExitCode: 123,
7979
}},
80-
Name: "state-name",
80+
Name: "state-name",
81+
ContainerName: "step-state-name",
8182
}},
8283
},
8384
}, {
@@ -106,7 +107,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
106107
Terminated: &corev1.ContainerStateTerminated{
107108
ExitCode: 123,
108109
}},
109-
Name: "state-name",
110+
Name: "state-name",
111+
ContainerName: "step-state-name",
110112
}},
111113
},
112114
}, {
@@ -131,7 +133,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
131133
Terminated: &corev1.ContainerStateTerminated{
132134
ExitCode: 0,
133135
}},
134-
Name: "step-push",
136+
Name: "step-push",
137+
ContainerName: "step-step-push",
135138
}},
136139
// We don't actually care about the time, just that it's not nil
137140
CompletionTime: &metav1.Time{Time: time.Now()},
@@ -155,7 +158,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
155158
ContainerState: corev1.ContainerState{
156159
Running: &corev1.ContainerStateRunning{},
157160
},
158-
Name: "running-step",
161+
Name: "running-step",
162+
ContainerName: "step-running-step",
159163
}},
160164
},
161165
}, {
@@ -189,7 +193,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
189193
Terminated: &corev1.ContainerStateTerminated{
190194
ExitCode: 123,
191195
}},
192-
Name: "failure",
196+
Name: "failure",
197+
ContainerName: "step-failure",
193198
}},
194199
// We don't actually care about the time, just that it's not nil
195200
CompletionTime: &metav1.Time{Time: time.Now()},
@@ -260,7 +265,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
260265
Message: "i'm pending",
261266
},
262267
},
263-
Name: "status-name",
268+
Name: "status-name",
269+
ContainerName: "step-status-name",
264270
}},
265271
},
266272
}, {
@@ -363,7 +369,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
363369
ContainerState: corev1.ContainerState{
364370
Running: &corev1.ContainerStateRunning{},
365371
},
366-
Name: "running-step",
372+
Name: "running-step",
373+
ContainerName: "step-running-step",
367374
}},
368375
},
369376
}} {

test/taskrun_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,26 @@ func TestTaskRunFailure(t *testing.T) {
7878
Reason: "Completed",
7979
},
8080
},
81-
Name: "hello",
81+
Name: "hello",
82+
ContainerName: "step-hello",
8283
}, {
8384
ContainerState: corev1.ContainerState{
8485
Terminated: &corev1.ContainerStateTerminated{
8586
ExitCode: 1,
8687
Reason: "Error",
8788
},
8889
},
89-
Name: "exit",
90+
Name: "exit",
91+
ContainerName: "step-exit",
9092
}, {
9193
ContainerState: corev1.ContainerState{
9294
Terminated: &corev1.ContainerStateTerminated{
9395
ExitCode: 0,
9496
Reason: "Completed",
9597
},
9698
},
97-
Name: "world",
99+
Name: "world",
100+
ContainerName: "step-world",
98101
}}
99102
ignoreFields := cmpopts.IgnoreFields(corev1.ContainerStateTerminated{}, "StartedAt", "FinishedAt", "ContainerID")
100103
if d := cmp.Diff(taskrun.Status.Steps, expectedStepState, ignoreFields); d != "" {

0 commit comments

Comments
 (0)