From 3217795a00614ad3b792d62b88a66da7fb4ac1f6 Mon Sep 17 00:00:00 2001 From: Benjamin Isinger Date: Thu, 28 Sep 2023 17:46:04 +0200 Subject: [PATCH] Reliably detect evicted pods for failing BuildRuns When a BuildRun pod is failing it is not necessary to check for failedContainer first. We can directly check if the pod is evicted and reflect that in the BuildRun condition Depending on how the system is evicting the pod, `extractFailedPodAndContainer` might return a non-nil value for `failedContainer`. In such scenarios we were not detecting if the pod was evicted. This is now fixed as we first check the Reason --- pkg/reconciler/buildrun/resources/conditions.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/reconciler/buildrun/resources/conditions.go b/pkg/reconciler/buildrun/resources/conditions.go index a03a5a29e..8ca0bf5a6 100644 --- a/pkg/reconciler/buildrun/resources/conditions.go +++ b/pkg/reconciler/buildrun/resources/conditions.go @@ -97,7 +97,14 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie //nolint:staticcheck // SA1019 we want to give users some time to adopt to failureDetails buildRun.Status.FailedAt = &buildv1alpha1.FailedAt{Pod: pod.Name} - if failedContainer != nil { + if pod.Status.Reason == "Evicted" { + message = pod.Status.Message + reason = buildv1alpha1.BuildRunStatePodEvicted + if failedContainer != nil { + //nolint:staticcheck // SA1019 we want to give users some time to adopt to failureDetails + buildRun.Status.FailedAt.Container = failedContainer.Name + } + } else if failedContainer != nil { //nolint:staticcheck // SA1019 we want to give users some time to adopt to failureDetails buildRun.Status.FailedAt.Container = failedContainer.Name message = fmt.Sprintf("buildrun step %s failed in pod %s, for detailed information: kubectl --namespace %s logs %s --container=%s", @@ -107,9 +114,6 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie pod.Name, failedContainer.Name, ) - } else if pod.Status.Reason == "Evicted" { - message = pod.Status.Message - reason = buildv1alpha1.BuildRunStatePodEvicted } else { message = fmt.Sprintf("buildrun failed due to an unexpected error in pod %s: for detailed information: kubectl --namespace %s logs %s --all-containers", pod.Name,