From 810ec2c2c25fc3e630f455c7cab05f045b7b7dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Barcarol=20Guimar=C3=A3es?= Date: Mon, 20 Jun 2022 11:31:37 +0000 Subject: [PATCH] pkg/steps: add error reason for pending pods Examples: `src` image: ``` INFO[2022-06-20T11:49:39Z] Reporting job state 'failed' with reason 'executing_graph:step_failed:cloning_source:pod_pending' ``` `images` build: ``` INFO[2022-06-20T11:54:26Z] Reporting job state 'failed' with reason 'executing_graph:step_failed:building_project_image:pod_pending' ``` `tests` container: ``` INFO[2022-06-20T11:56:09Z] Reporting job state 'failed' with reason 'executing_graph:step_failed:running_pod:pod_pending' ``` --- pkg/api/constant.go | 4 ++++ pkg/util/builds.go | 3 +++ pkg/util/pods.go | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/api/constant.go b/pkg/api/constant.go index 5bdebc3b68e..fde1ad8c4fb 100644 --- a/pkg/api/constant.go +++ b/pkg/api/constant.go @@ -51,6 +51,10 @@ const ( APPCIKubeAPIURL = "https://api.ci.l2s4.p1.openshiftapps.com:6443" + // ReasonPending is the error reason for pods not scheduled in time. + // It is generated when pods are for whatever reason not scheduled before + // `podStartTimeout`. + ReasonPending = "pod_pending" // CliEnv if the env we use to expose the path to the cli CliEnv = "CLI_DIR" DefaultLeaseEnv = "LEASED_RESOURCE" diff --git a/pkg/util/builds.go b/pkg/util/builds.go index 8bddb13967f..33a44c3455a 100644 --- a/pkg/util/builds.go +++ b/pkg/util/builds.go @@ -12,7 +12,9 @@ import ( buildapi "github.com/openshift/api/build/v1" + "github.com/openshift/ci-tools/pkg/api" "github.com/openshift/ci-tools/pkg/kubernetes" + "github.com/openshift/ci-tools/pkg/results" ) // PendingBuildError fetches scheduling errors from the build pod's events @@ -28,5 +30,6 @@ func PendingBuildError(ctx context.Context, client kubernetes.PodClient, build * } else { ret = fmt.Errorf("%s:%s\n%s", msg, getReasonsForUnreadyContainers(&pod), getEventsForPod(ctx, &pod, client)) } + ret = results.ForReason(api.ReasonPending).ForError(ret) return } diff --git a/pkg/util/pods.go b/pkg/util/pods.go index ea997018ac7..24267bb61c3 100644 --- a/pkg/util/pods.go +++ b/pkg/util/pods.go @@ -23,7 +23,9 @@ import ( "k8s.io/apimachinery/pkg/util/wait" ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/openshift/ci-tools/pkg/api" "github.com/openshift/ci-tools/pkg/kubernetes" + "github.com/openshift/ci-tools/pkg/results" ) // WaitForPodFlag changes the behavior of the functions which monitor pods @@ -431,7 +433,7 @@ func checkPending(pod corev1.Pod, timeout time.Duration, now time.Time) (time.Ti if t := t0.Add(timeout); now.Before(t) { return t, nil } - return time.Time{}, fmt.Errorf("container %q has not started in %s", name, now.Sub(t0)) + return time.Time{}, results.ForReason(api.ReasonPending).ForError(fmt.Errorf("container %q has not started in %s", name, now.Sub(t0))) } prev := pod.CreationTimestamp.Time for _, s := range pod.Status.InitContainerStatuses {