Skip to content

Commit

Permalink
add containerstate and containername for sidecars
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhelfand committed Feb 19, 2020
1 parent 4e9380f commit 5642b7b
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 8 deletions.
10 changes: 6 additions & 4 deletions pkg/apis/pipeline/v1alpha2/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,20 @@ 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"`
ContainerName string `json:"container,omitempty"`
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
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions pkg/pod/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
Expand Down
108 changes: 106 additions & 2 deletions pkg/pod/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}},
},
},
Expand Down

0 comments on commit 5642b7b

Please sign in to comment.