From d760ddcc57b0c2144e74ba1a083852c7543806e1 Mon Sep 17 00:00:00 2001 From: Dan Lorenc Date: Thu, 27 Jun 2019 09:12:54 +0800 Subject: [PATCH] Add the imageID for each step to the TaskRun.Spec.Status object. 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. --- pkg/apis/pipeline/v1alpha1/taskrun_types.go | 5 ++++- pkg/status/taskrunpod.go | 1 + pkg/status/taskrunpod_test.go | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_types.go b/pkg/apis/pipeline/v1alpha1/taskrun_types.go index 8b88896f7ae..dd6766c0ab9 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_types.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_types.go @@ -196,6 +196,7 @@ type StepState struct { corev1.ContainerState Name string `json:"name,omitempty"` ContainerName string `json:"container,omitempty"` + ImageID string `json:"imageID,omitempty"` } // CloudEventDelivery is the target of a cloud event along with the state of @@ -230,7 +231,9 @@ type CloudEventDeliveryState struct { // Error is the text of error (if any) Error string `json:"message"` // RetryCount is the number of attempts of sending the cloud event - RetryCount int32 `json:"retryCount"` + RetryCount int32 `json:"retryCount"` + Name string `json:"name,omitempty"` + ImageID string `json:"imageID,omitempty"` } // +genclient diff --git a/pkg/status/taskrunpod.go b/pkg/status/taskrunpod.go index 6fa0ce72330..a946ab9e454 100644 --- a/pkg/status/taskrunpod.go +++ b/pkg/status/taskrunpod.go @@ -53,6 +53,7 @@ func UpdateStatusFromPod(taskRun *v1alpha1.TaskRun, pod *corev1.Pod, resourceLis ContainerState: *s.State.DeepCopy(), Name: resources.TrimContainerNamePrefix(s.Name), ContainerName: s.Name, + ImageID: s.ImageID, }) } } diff --git a/pkg/status/taskrunpod_test.go b/pkg/status/taskrunpod_test.go index 4ab34ad3017..adfffda331d 100644 --- a/pkg/status/taskrunpod_test.go +++ b/pkg/status/taskrunpod_test.go @@ -74,9 +74,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, @@ -102,11 +104,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, @@ -125,6 +130,7 @@ func TestUpdateStatusFromPod(t *testing.T) { }}, Name: "state-name", ContainerName: "step-state-name", + ImageID: "image-id", }}, }, }, { @@ -138,6 +144,7 @@ func TestUpdateStatusFromPod(t *testing.T) { ExitCode: 0, }, }, + ImageID: "image-id", }}, }, want: v1alpha1.TaskRunStatus{ @@ -151,6 +158,7 @@ func TestUpdateStatusFromPod(t *testing.T) { }}, Name: "step-push", ContainerName: "step-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()}, @@ -181,9 +189,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", @@ -209,8 +218,10 @@ func TestUpdateStatusFromPod(t *testing.T) { Terminated: &corev1.ContainerStateTerminated{ ExitCode: 123, }}, + Name: "failure", ContainerName: "step-failure", + ImageID: "image-id", }}, // We don't actually care about the time, just that it's not nil CompletionTime: &metav1.Time{Time: time.Now()},