diff --git a/pkg/pod/status.go b/pkg/pod/status.go index ed4f5e480a9..92c57d0e251 100644 --- a/pkg/pod/status.go +++ b/pkg/pod/status.go @@ -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" @@ -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) } @@ -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 { diff --git a/pkg/pod/status_test.go b/pkg/pod/status_test.go index 3b462983f82..88d7c43e90e 100644 --- a/pkg/pod/status_test.go +++ b/pkg/pod/status_test.go @@ -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{