Skip to content

Commit

Permalink
Avoid stuck on pending when hit "CreateContainerConfigError"
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pli authored and tekton-robot committed Jan 21, 2020
1 parent 77f4de0 commit e5b2530
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pkg/pod/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const (
// to resource constraints on the node
ReasonExceededNodeResources = "ExceededNodeResources"

// ReasonCreateContainerConfigError indicates that the TaskRun failed to create a pod due to
// config error of container
ReasonCreateContainerConfigError = "CreateContainerConfigError"

// ReasonSucceeded indicates that the reason for the finished status is that all of the steps
// completed successfully
ReasonSucceeded = "Succeeded"
Expand Down Expand Up @@ -207,10 +211,14 @@ func updateIncompleteTaskRun(trs *v1alpha1.TaskRunStatus, pod *corev1.Pod) {
})
case corev1.PodPending:
var reason, msg string
if IsPodExceedingNodeResources(pod) {
switch {
case IsPodExceedingNodeResources(pod):
reason = ReasonExceededNodeResources
msg = "TaskRun Pod exceeded available resources"
} else {
case IsPodHitConfigError(pod):
reason = ReasonCreateContainerConfigError
msg = getWaitingMessage(pod)
default:
reason = "Pending"
msg = getWaitingMessage(pod)
}
Expand Down Expand Up @@ -287,6 +295,16 @@ func IsPodExceedingNodeResources(pod *corev1.Pod) bool {
return false
}

// IsPodHitConfigError returns true if the Pod's status undicates there are config error raised
func IsPodHitConfigError(pod *corev1.Pod) bool {
for _, containerStatus := range pod.Status.ContainerStatuses {
if containerStatus.State.Waiting != nil && containerStatus.State.Waiting.Reason == "CreateContainerConfigError" {
return true
}
}
return false
}

func getWaitingMessage(pod *corev1.Pod) string {
// First, try to surface reason for pending/unknown about the actual build step.
for _, status := range pod.Status.ContainerStatuses {
Expand Down
26 changes: 26 additions & 0 deletions pkg/pod/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,32 @@ func TestMakeTaskRunStatus(t *testing.T) {
Sidecars: []v1alpha1.SidecarState{},
},
},
}, {
desc: "pending-CreateContainerConfigError",
podStatus: corev1.PodStatus{
Phase: corev1.PodPending,
ContainerStatuses: []corev1.ContainerStatus{{
State: corev1.ContainerState{
Waiting: &corev1.ContainerStateWaiting{
Reason: "CreateContainerConfigError",
},
},
}},
},
want: v1alpha1.TaskRunStatus{
Status: duckv1beta1.Status{
Conditions: []apis.Condition{{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionUnknown,
Reason: ReasonCreateContainerConfigError,
Message: "Pending",
}},
},
TaskRunStatusFields: v1alpha1.TaskRunStatusFields{
Steps: []v1alpha1.StepState{},
Sidecars: []v1alpha1.SidecarState{},
},
},
}, {
desc: "with-sidecar-running",
podStatus: corev1.PodStatus{
Expand Down

0 comments on commit e5b2530

Please sign in to comment.