From 606340f50698f6a80d28b583eab719f15f3e3117 Mon Sep 17 00:00:00 2001 From: Daniel Helfand Date: Wed, 19 Feb 2020 17:46:48 -0500 Subject: [PATCH] add containerstate and containername for sidecars --- pkg/apis/pipeline/v1alpha2/taskrun_types.go | 10 +- .../v1alpha2/zz_generated.deepcopy.go | 5 +- pkg/pod/status.go | 6 +- pkg/pod/status_test.go | 108 +++++++++++++++++- 4 files changed, 120 insertions(+), 9 deletions(-) diff --git a/pkg/apis/pipeline/v1alpha2/taskrun_types.go b/pkg/apis/pipeline/v1alpha2/taskrun_types.go index a5d64bd1c99..4101b3b56c4 100644 --- a/pkg/apis/pipeline/v1alpha2/taskrun_types.go +++ b/pkg/apis/pipeline/v1alpha2/taskrun_types.go @@ -173,7 +173,7 @@ func (tr *TaskRunStatus) SetCondition(newCond *apis.Condition) { } } -// StepState reports the results of running a step in the Task. +// StepState reports the results of running a step in a Task. type StepState struct { corev1.ContainerState Name string `json:"name,omitempty"` @@ -181,10 +181,12 @@ type StepState struct { ImageID string `json:"imageID,omitempty"` } -// SidecarState reports the results of sidecar in the Task. +// SidecarState reports the results of running a sidecar in a Task. type SidecarState struct { - Name string `json:"name,omitempty"` - ImageID string `json:"imageID,omitempty"` + 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 diff --git a/pkg/apis/pipeline/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/pipeline/v1alpha2/zz_generated.deepcopy.go index 3e79cb420bf..a7399d8a03c 100644 --- a/pkg/apis/pipeline/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/pipeline/v1alpha2/zz_generated.deepcopy.go @@ -920,6 +920,7 @@ func (in *PipelineTaskRun) DeepCopy() *PipelineTaskRun { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SidecarState) DeepCopyInto(out *SidecarState) { *out = *in + in.ContainerState.DeepCopyInto(&out.ContainerState) return } @@ -1402,7 +1403,9 @@ func (in *TaskRunStatusFields) DeepCopyInto(out *TaskRunStatusFields) { if in.Sidecars != nil { in, out := &in.Sidecars, &out.Sidecars *out = make([]SidecarState, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } return } diff --git a/pkg/pod/status.go b/pkg/pod/status.go index 02ff4769abe..e55a08607dc 100644 --- a/pkg/pod/status.go +++ b/pkg/pod/status.go @@ -158,8 +158,10 @@ func MakeTaskRunStatus(tr v1alpha1.TaskRun, pod *corev1.Pod, taskSpec v1alpha1.T }) } else if isContainerSidecar(s.Name) { trs.Sidecars = append(trs.Sidecars, v1alpha1.SidecarState{ - Name: trimSidecarPrefix(s.Name), - ImageID: s.ImageID, + ContainerState: *s.State.DeepCopy(), + Name: trimSidecarPrefix(s.Name), + ContainerName: s.Name, + ImageID: s.ImageID, }) } } diff --git a/pkg/pod/status_test.go b/pkg/pod/status_test.go index 9215e116ca8..310867a42c6 100644 --- a/pkg/pod/status_test.go +++ b/pkg/pod/status_test.go @@ -491,8 +491,112 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerName: "step-running-step", }}, Sidecars: []v1alpha1.SidecarState{{ - Name: "running", - ImageID: "image-id", + ContainerState: corev1.ContainerState{ + Running: &corev1.ContainerStateRunning{}, + }, + Name: "running", + ImageID: "image-id", + ContainerName: "sidecar-running", + }}, + }, + }, + }, { + desc: "with-sidecar-waiting", + podStatus: corev1.PodStatus{ + Phase: corev1.PodRunning, + ContainerStatuses: []corev1.ContainerStatus{{ + Name: "step-waiting-step", + State: corev1.ContainerState{ + Waiting: &corev1.ContainerStateWaiting{ + Reason: "PodInitializing", + Message: "PodInitializing", + }, + }, + }, { + Name: "sidecar-waiting", + ImageID: "image-id", + State: corev1.ContainerState{ + Waiting: &corev1.ContainerStateWaiting{ + Reason: "PodInitializing", + Message: "PodInitializing", + }, + }, + Ready: true, + }}, + }, + want: v1alpha1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: []apis.Condition{conditionRunning}, + }, + TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ + Steps: []v1alpha1.StepState{{ + ContainerState: corev1.ContainerState{ + Waiting: &corev1.ContainerStateWaiting{ + Reason: "PodInitializing", + Message: "PodInitializing", + }, + }, + Name: "waiting-step", + ContainerName: "step-waiting-step", + }}, + Sidecars: []v1alpha1.SidecarState{{ + ContainerState: corev1.ContainerState{ + Waiting: &corev1.ContainerStateWaiting{ + Reason: "PodInitializing", + Message: "PodInitializing", + }, + }, + Name: "waiting", + ImageID: "image-id", + ContainerName: "sidecar-waiting", + }}, + }, + }, + }, { + desc: "with-sidecar-terminated", + podStatus: corev1.PodStatus{ + Phase: corev1.PodRunning, + ContainerStatuses: []corev1.ContainerStatus{{ + Name: "step-running-step", + State: corev1.ContainerState{ + Running: &corev1.ContainerStateRunning{}, + }, + }, { + Name: "sidecar-error", + ImageID: "image-id", + State: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 1, + Reason: "Error", + Message: "Error", + }, + }, + Ready: true, + }}, + }, + want: v1alpha1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: []apis.Condition{conditionRunning}, + }, + TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ + Steps: []v1alpha1.StepState{{ + ContainerState: corev1.ContainerState{ + Running: &corev1.ContainerStateRunning{}, + }, + Name: "running-step", + ContainerName: "step-running-step", + }}, + Sidecars: []v1alpha1.SidecarState{{ + ContainerState: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 1, + Reason: "Error", + Message: "Error", + }, + }, + Name: "error", + ImageID: "image-id", + ContainerName: "sidecar-error", }}, }, },