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 committed Jul 18, 2019
1 parent df7ec8b commit 38c2583
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/apis/pipeline/v1alpha1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (tr *TaskRunStatus) SetCondition(newCond *apis.Condition) {
type StepState struct {
corev1.ContainerState
Name string `json:"name,omitempty"`
Container string `json:"container,omitempty"`
}

// +genclient
Expand Down
11 changes: 6 additions & 5 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),
Container: s.Name,
})
}
}
Expand Down Expand Up @@ -64,8 +65,8 @@ func updateCompletedTaskRun(taskRun *v1alpha1.TaskRun, pod *corev1.Pod) {
})
} else {
taskRun.Status.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
Reason: ReasonSucceeded,
Message: "All Steps have completed executing",
})
Expand All @@ -78,9 +79,9 @@ func updateIncompleteTaskRun(taskRun *v1alpha1.TaskRun, pod *corev1.Pod) {
switch pod.Status.Phase {
case corev1.PodRunning:
taskRun.Status.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionUnknown,
Reason: ReasonBuilding,
Type: apis.ConditionSucceeded,
Status: corev1.ConditionUnknown,
Reason: ReasonBuilding,
Message: "Not all Steps in the Task have finished executing",
})
case corev1.PodPending:
Expand Down
7 changes: 7 additions & 0 deletions pkg/status/taskrunpod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func TestUpdateStatusFromPod(t *testing.T) {
ExitCode: 123,
}},
Name: "state-name",
Container: "step-state-name",
}},
},
}, {
Expand Down Expand Up @@ -107,6 +108,7 @@ func TestUpdateStatusFromPod(t *testing.T) {
ExitCode: 123,
}},
Name: "state-name",
Container: "step-state-name",
}},
},
}, {
Expand All @@ -132,6 +134,7 @@ func TestUpdateStatusFromPod(t *testing.T) {
ExitCode: 0,
}},
Name: "step-push",
Container: "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 @@ -156,6 +159,7 @@ func TestUpdateStatusFromPod(t *testing.T) {
Running: &corev1.ContainerStateRunning{},
},
Name: "running-step",
Container: "step-running-step",
}},
},
}, {
Expand Down Expand Up @@ -190,6 +194,7 @@ func TestUpdateStatusFromPod(t *testing.T) {
ExitCode: 123,
}},
Name: "failure",
Container: "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 @@ -261,6 +266,7 @@ func TestUpdateStatusFromPod(t *testing.T) {
},
},
Name: "status-name",
Container: "step-status-name",
}},
},
}, {
Expand Down Expand Up @@ -364,6 +370,7 @@ func TestUpdateStatusFromPod(t *testing.T) {
Running: &corev1.ContainerStateRunning{},
},
Name: "running-step",
Container: "step-running-step",
}},
},
}} {
Expand Down

0 comments on commit 38c2583

Please sign in to comment.