Skip to content

Commit

Permalink
Add the imageID for each step to the TaskRun.Spec.Status object.
Browse files Browse the repository at this point in the history
This allows users to trace the exact steps (including digest) used in each TaskRun.
This information is already available on a Pod, but we need to assume completed Pods
will be GC'ed and not available long after the run is complete.
  • Loading branch information
dlorenc committed Jun 27, 2019
1 parent 9f31820 commit 97b5ebe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pkg/apis/pipeline/v1alpha1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ func (tr *TaskRunStatus) SetCondition(newCond *apis.Condition) {
// StepState reports the results of running a step in the Task.
type StepState struct {
corev1.ContainerState
Name string `json:"name,omitempty"`
Name string `json:"name,omitempty"`
ImageID string `json:"imageID,omitempty"`
}

// +genclient
Expand Down
1 change: 1 addition & 0 deletions pkg/status/taskrunpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func UpdateStatusFromPod(taskRun *v1alpha1.TaskRun, pod *corev1.Pod, resourceLis
taskRun.Status.Steps = append(taskRun.Status.Steps, v1alpha1.StepState{
ContainerState: *s.State.DeepCopy(),
Name: resources.TrimContainerNamePrefix(s.Name),
ImageID: s.ImageID,
})
}
}
Expand Down
22 changes: 16 additions & 6 deletions pkg/status/taskrunpod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ func TestUpdateStatusFromPod(t *testing.T) {
podStatus: corev1.PodStatus{
InitContainerStatuses: []corev1.ContainerStatus{{
// creds-init; ignored
ImageID: "ignored",
}},
ContainerStatuses: []corev1.ContainerStatus{{
Name: "step-state-name",
Name: "step-state-name",
ImageID: "",
State: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 123,
Expand All @@ -82,11 +84,14 @@ func TestUpdateStatusFromPod(t *testing.T) {
podStatus: corev1.PodStatus{
InitContainerStatuses: []corev1.ContainerStatus{{
// creds-init; ignored.
ImageID: "ignoreme",
}, {
// git-init; ignored.
ImageID: "ignoreme",
}},
ContainerStatuses: []corev1.ContainerStatus{{
Name: "step-state-name",
Name: "step-state-name",
ImageID: "image-id",
State: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 123,
Expand All @@ -103,7 +108,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 123,
}},
Name: "state-name",
Name: "state-name",
ImageID: "image-id",
}},
},
}, {
Expand All @@ -117,6 +123,7 @@ func TestUpdateStatusFromPod(t *testing.T) {
ExitCode: 0,
},
},
ImageID: "image-id",
}},
},
want: v1alpha1.TaskRunStatus{
Expand All @@ -128,7 +135,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 0,
}},
Name: "step-push",
Name: "step-push",
ImageID: "image-id",
}},
// We don't actually care about the time, just that it's not nil
CompletionTime: &metav1.Time{Time: time.Now()},
Expand Down Expand Up @@ -158,9 +166,10 @@ func TestUpdateStatusFromPod(t *testing.T) {
}, {
desc: "failure-terminated",
podStatus: corev1.PodStatus{
Phase: corev1.PodFailed,
Phase: corev1.PodFailed,
InitContainerStatuses: []corev1.ContainerStatus{{
// creds-init status; ignored
ImageID: "ignore-me",
}},
ContainerStatuses: []corev1.ContainerStatus{{
Name: "step-failure",
Expand All @@ -185,7 +194,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 123,
}},
Name: "failure",
Name: "failure",
ImageID: "image-id",
}},
// We don't actually care about the time, just that it's not nil
CompletionTime: &metav1.Time{Time: time.Now()},
Expand Down

0 comments on commit 97b5ebe

Please sign in to comment.