Skip to content

Commit

Permalink
Adds container name to taskrun.status.steps
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hrishin authored and tekton-robot committed Jul 25, 2019
1 parent 3409f09 commit c2ee772
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 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 @@ -194,7 +194,8 @@ func (tr *TaskRunStatus) InitializeCloudEvents(targets []string) {
// 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"`
ContainerName string `json:"container,omitempty"`
}

// CloudEventDelivery is the target of a cloud event along with the state of
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),
ContainerName: s.Name,
})
}
}
Expand Down
21 changes: 14 additions & 7 deletions pkg/status/taskrunpod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 123,
}},
Name: "state-name",
Name: "state-name",
ContainerName: "step-state-name",
}},
},
}, {
Expand Down Expand Up @@ -106,7 +107,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 123,
}},
Name: "state-name",
Name: "state-name",
ContainerName: "step-state-name",
}},
},
}, {
Expand All @@ -131,7 +133,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 0,
}},
Name: "step-push",
Name: "step-push",
ContainerName: "step-step-push",
}},
// We don't actually care about the time, just that it's not nil
CompletionTime: &metav1.Time{Time: time.Now()},
Expand All @@ -155,7 +158,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
ContainerState: corev1.ContainerState{
Running: &corev1.ContainerStateRunning{},
},
Name: "running-step",
Name: "running-step",
ContainerName: "step-running-step",
}},
},
}, {
Expand Down Expand Up @@ -189,7 +193,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 123,
}},
Name: "failure",
Name: "failure",
ContainerName: "step-failure",
}},
// We don't actually care about the time, just that it's not nil
CompletionTime: &metav1.Time{Time: time.Now()},
Expand Down Expand Up @@ -260,7 +265,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
Message: "i'm pending",
},
},
Name: "status-name",
Name: "status-name",
ContainerName: "step-status-name",
}},
},
}, {
Expand Down Expand Up @@ -363,7 +369,8 @@ func TestUpdateStatusFromPod(t *testing.T) {
ContainerState: corev1.ContainerState{
Running: &corev1.ContainerStateRunning{},
},
Name: "running-step",
Name: "running-step",
ContainerName: "step-running-step",
}},
},
}} {
Expand Down
9 changes: 6 additions & 3 deletions test/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,26 @@ func TestTaskRunFailure(t *testing.T) {
Reason: "Completed",
},
},
Name: "hello",
Name: "hello",
ContainerName: "step-hello",
}, {
ContainerState: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 1,
Reason: "Error",
},
},
Name: "exit",
Name: "exit",
ContainerName: "step-exit",
}, {
ContainerState: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{
ExitCode: 0,
Reason: "Completed",
},
},
Name: "world",
Name: "world",
ContainerName: "step-world",
}}
ignoreFields := cmpopts.IgnoreFields(corev1.ContainerStateTerminated{}, "StartedAt", "FinishedAt", "ContainerID")
if d := cmp.Diff(taskrun.Status.Steps, expectedStepState, ignoreFields); d != "" {
Expand Down

0 comments on commit c2ee772

Please sign in to comment.