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 committed Jan 21, 2020
1 parent ab43a6a commit 6023fee
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
17 changes: 17 additions & 0 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 @@ -210,6 +214,9 @@ func updateIncompleteTaskRun(trs *v1alpha1.TaskRunStatus, pod *corev1.Pod) {
if IsPodExceedingNodeResources(pod) {
reason = ReasonExceededNodeResources
msg = "TaskRun Pod exceeded available resources"
} else if IsPodHitConfigError(pod) {
reason = ReasonCreateContainerConfigError
msg = getWaitingMessage(pod)
} else {
reason = "Pending"
msg = getWaitingMessage(pod)
Expand Down Expand Up @@ -287,6 +294,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 6023fee

Please sign in to comment.